From d60ed8daed863654b2c870878c3263de7d5a8a18 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Tue, 22 Oct 2024 12:58:18 -0400 Subject: [PATCH] fix broken peer service telemetry logic ensure recursivzely defined envier items are captured in telemetry --- ddtrace/settings/_core.py | 2 +- ddtrace/settings/peer_service.py | 9 +++------ tests/telemetry/test_writer.py | 13 ++++++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ddtrace/settings/_core.py b/ddtrace/settings/_core.py index 84f5d13b16d..2ab52e38db6 100644 --- a/ddtrace/settings/_core.py +++ b/ddtrace/settings/_core.py @@ -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 @@ -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 diff --git a/ddtrace/settings/peer_service.py b/ddtrace/settings/peer_service.py index 7bc56849a95..2e0af732c3d 100644 --- a/ddtrace/settings/peer_service.py +++ b/ddtrace/settings/peer_service.py @@ -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): @@ -23,7 +21,7 @@ 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 @@ -31,11 +29,10 @@ def set_defaults_enabled(self): @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) diff --git a/tests/telemetry/test_writer.py b/tests/telemetry/test_writer.py index d90a7351eba..6adfa019cc1 100644 --- a/tests/telemetry/test_writer.py +++ b/tests/telemetry/test_writer.py @@ -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}, @@ -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}, @@ -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"},