Skip to content

Commit

Permalink
fix broken peer service telemetry logic
Browse files Browse the repository at this point in the history
ensure recursivzely defined envier items are captured in telemetry
  • Loading branch information
mabdinur committed Oct 22, 2024
1 parent 5a610cc commit d60ed8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ddtrace/settings/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Union # noqa:F401

from envier import Env
from envier.env import EnvVariable

from ddtrace.internal.telemetry import telemetry_writer

Expand All @@ -21,7 +22,6 @@ def _report_telemetry(self) -> None:
for name, e in type(self).items(recursive=True):
if e.private:
continue

env_name = e.full_name

# Get the item value recursively
Expand Down
9 changes: 3 additions & 6 deletions ddtrace/settings/peer_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os

from ddtrace.ext import SpanKind
from ddtrace.internal.schema import SCHEMA_VERSION
from ddtrace.internal.utils.formats import asbool
from ddtrace.internal.utils.formats import parse_tags_str
from ddtrace.settings._core import report_telemetry as _report_telemetry
from ddtrace.settings._core import get_config as _get_config


class PeerServiceConfig(object):
Expand All @@ -23,19 +21,18 @@ def __init__(self, set_defaults_enabled=None, peer_service_mapping=None):
@property
def set_defaults_enabled(self):
if self._set_defaults_enabled is None:
env_enabled = asbool(os.getenv("DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED", default=False))
env_enabled = _get_config("DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED", False, asbool)
self._set_defaults_enabled = SCHEMA_VERSION == "v1" or (SCHEMA_VERSION == "v0" and env_enabled)

return self._set_defaults_enabled

@property
def peer_service_mapping(self):
if self._peer_service_mapping is None:
self._unparsed_peer_service_mapping = os.getenv("DD_TRACE_PEER_SERVICE_MAPPING", default="")
self._unparsed_peer_service_mapping = _get_config("DD_TRACE_PEER_SERVICE_MAPPING", "")
self._peer_service_mapping = parse_tags_str(self._unparsed_peer_service_mapping)

return self._peer_service_mapping


_ps_config = PeerServiceConfig()
_report_telemetry(_ps_config)
13 changes: 12 additions & 1 deletion tests/telemetry/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_app_started_event_configuration_override(test_agent_session, run_python
{"name": "DD_API_SECURITY_SAMPLE_DELAY", "origin": "default", "value": 30.0},
{"name": "DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING", "origin": "default", "value": ""},
{"name": "DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING_ENABLED", "origin": "default", "value": True},
{"name": "DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE", "origin": "default", "value": ""},
{"name": "DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE", "origin": "unknown", "value": "identification"},
{"name": "DD_APPSEC_ENABLED", "origin": "env_var", "value": True},
{"name": "DD_APPSEC_MAX_STACK_TRACES", "origin": "default", "value": 2},
{"name": "DD_APPSEC_MAX_STACK_TRACE_DEPTH", "origin": "default", "value": 32},
Expand Down Expand Up @@ -386,12 +386,21 @@ def test_app_started_event_configuration_override(test_agent_session, run_python
{"name": "DD_PROFILING_ENABLE_ASSERTS", "origin": "default", "value": False},
{"name": "DD_PROFILING_ENABLE_CODE_PROVENANCE", "origin": "default", "value": True},
{"name": "DD_PROFILING_ENDPOINT_COLLECTION_ENABLED", "origin": "default", "value": True},
{"name": "DD_PROFILING_EXPORT_LIBDD_ENABLED", "origin": "default", "value": False},
{"name": "DD_PROFILING_HEAP_ENABLED", "origin": "env_var", "value": False},
{"name": "DD_PROFILING_HEAP_SAMPLE_SIZE", "origin": "default", "value": None},
{"name": "DD_PROFILING_IGNORE_PROFILER", "origin": "default", "value": False},
{"name": "DD_PROFILING_LOCK_ENABLED", "origin": "env_var", "value": False},
{"name": "DD_PROFILING_LOCK_NAME_INSPECT_DIR", "origin": "default", "value": True},
{"name": "DD_PROFILING_MAX_EVENTS", "origin": "default", "value": 16384},
{"name": "DD_PROFILING_MAX_FRAMES", "origin": "env_var", "value": 512},
{"name": "DD_PROFILING_MAX_TIME_USAGE_PCT", "origin": "default", "value": 1.0},
{"name": "DD_PROFILING_MEMORY_ENABLED", "origin": "env_var", "value": False},
{"name": "DD_PROFILING_MEMORY_EVENTS_BUFFER", "origin": "default", "value": 16},
{"name": "DD_PROFILING_OUTPUT_PPROF", "origin": "default", "value": None},
{"name": "DD_PROFILING_SAMPLE_POOL_CAPACITY", "origin": "default", "value": 4},
{"name": "DD_PROFILING_STACK_ENABLED", "origin": "env_var", "value": False},
{"name": "DD_PROFILING_STACK_V2_ENABLED", "origin": "default", "value": False},
{"name": "DD_PROFILING_TAGS", "origin": "default", "value": ""},
{"name": "DD_PROFILING_TIMELINE_ENABLED", "origin": "default", "value": False},
{"name": "DD_PROFILING_UPLOAD_INTERVAL", "origin": "env_var", "value": 10.0},
Expand Down Expand Up @@ -435,6 +444,8 @@ def test_app_started_event_configuration_override(test_agent_session, run_python
{"name": "DD_TRACE_OTEL_ENABLED", "origin": "env_var", "value": True},
{"name": "DD_TRACE_PARTIAL_FLUSH_ENABLED", "origin": "env_var", "value": False},
{"name": "DD_TRACE_PARTIAL_FLUSH_MIN_SPANS", "origin": "env_var", "value": 3},
{"name": "DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED", "origin": "default", "value": False},
{"name": "DD_TRACE_PEER_SERVICE_MAPPING", "origin": "env_var", "value": "default_service:remapped_service"},
{"name": "DD_TRACE_PROPAGATION_EXTRACT_FIRST", "origin": "default", "value": False},
{"name": "DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED", "origin": "default", "value": False},
{"name": "DD_TRACE_PROPAGATION_STYLE_EXTRACT", "origin": "env_var", "value": "tracecontext"},
Expand Down

0 comments on commit d60ed8d

Please sign in to comment.