Skip to content

Commit

Permalink
fix(weave): Make traces work again and still remove logging (#1222)
Browse files Browse the repository at this point in the history
* Make traces work again and still remove logging

* lint

* add helper

* lint
  • Loading branch information
jwlee64 authored Feb 20, 2024
1 parent 93a3097 commit a10f4ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions weave/engine_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import dataclasses

from . import environment
from . import logs
from . import stream_data_interfaces

Expand Down Expand Up @@ -155,23 +156,23 @@ def attributes(self):
def set_tag(self, key, unredacted_val, redacted_val=None):
if "tags" not in self.attributes:
self.attributes["tags"] = {}
if not os.getenv("DISABLE_WEAVE_PII"):
if not environment.disable_weave_pii():
self.attributes["tags"][key] = unredacted_val
elif redacted_val is not None:
self.attributes["tags"][key] = redacted_val

def set_meta(self, key, unredacted_val, redacted_val=None):
if "metadata" not in self.attributes:
self.attributes["metadata"] = {}
if not os.getenv("DISABLE_WEAVE_PII"):
if not environment.disable_weave_pii():
self.attributes["metadata"][key] = unredacted_val
elif redacted_val is not None:
self.attributes["metadata"][key] = redacted_val

def set_metric(self, key, unredacted_val, redacted_val=None):
if "metrics" not in self.attributes:
self.attributes["metrics"] = {}
if not os.getenv("DISABLE_WEAVE_PII"):
if not environment.disable_weave_pii():
self.attributes["metrics"][key] = unredacted_val
elif redacted_val is not None:
self.attributes["metrics"][key] = redacted_val
Expand Down Expand Up @@ -285,18 +286,18 @@ def patch_ddtrace_set_tag():

# Only logged redacted values if flag is on
def set_tag(self, key, unredacted_val=None, redacted_val=None):
if redacted_val is not None and os.getenv("DISABLE_WEAVE_PII"):
if redacted_val is not None and environment.disable_weave_pii():
old_set_tag(self, key, redacted_val)
elif (
unredacted_val is not None
and not os.getenv("DISABLE_WEAVE_PII")
and not environment.disable_weave_pii()
or "_dd." in key
):
old_set_tag(self, key, unredacted_val)

# Log metric if flag is off or if flag is on and redacted
def set_metric(self, key, val, is_pii_redacted=False):
if not os.getenv("DISABLE_WEAVE_PII") or is_pii_redacted or "_dd." in key:
if not environment.disable_weave_pii() or is_pii_redacted or "_dd." in key:
old_set_metric(self, key, val)

ddtrace_span.Span.set_metric = set_metric
Expand Down
4 changes: 4 additions & 0 deletions weave/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,7 @@ def dd_env() -> str:

def env_is_ci() -> bool:
return util.parse_boolean_env_var("WEAVE_CI")


def disable_weave_pii() -> bool:
return os.getenv("DISABLE_WEAVE_PII", "false").strip().lower() == "true"
9 changes: 7 additions & 2 deletions weave/weave_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ def execute(self, document, *args, **kwargs):
# crashes
import ddtrace

if not os.environ.get("DISABLE_WEAVE_PII"):
ddtrace.patch_all(logging=True)
# patch all libraries to datadog except logging
ddtrace.patch_all(logging=False)

if not environment.disable_weave_pii():
# patch logging to datadog, if not disabled
ddtrace.patch(logging=True)

custom_dd_patch()


Expand Down

0 comments on commit a10f4ca

Please sign in to comment.