diff --git a/ddtrace/_monkey.py b/ddtrace/_monkey.py index 40f4d20bb28..de347ea859a 100644 --- a/ddtrace/_monkey.py +++ b/ddtrace/_monkey.py @@ -79,10 +79,10 @@ "falcon": True, "pyramid": True, # Auto-enable logging if the environment variable DD_LOGS_INJECTION is true - "logbook": config.logs_injection, # type: ignore - "logging": config.logs_injection, # type: ignore - "loguru": config.logs_injection, # type: ignore - "structlog": config.logs_injection, # type: ignore + "logbook": config._logs_injection, # type: ignore + "logging": config._logs_injection, # type: ignore + "loguru": config._logs_injection, # type: ignore + "structlog": config._logs_injection, # type: ignore "pynamodb": True, "pyodbc": True, "fastapi": True, diff --git a/ddtrace/_trace/tracer.py b/ddtrace/_trace/tracer.py index 27c2d2ab8f9..9d26cb50498 100644 --- a/ddtrace/_trace/tracer.py +++ b/ddtrace/_trace/tracer.py @@ -300,7 +300,7 @@ def __init__( self._new_process = False config._subscribe(["_trace_sample_rate", "_trace_sampling_rules"], self._on_global_config_update) - config._subscribe(["logs_injection"], self._on_global_config_update) + config._subscribe(["_logs_injection"], self._on_global_config_update) config._subscribe(["tags"], self._on_global_config_update) config._subscribe(["_tracing_enabled"], self._on_global_config_update) @@ -826,7 +826,7 @@ def _start_span( span_api=span_api, on_finish=[self._on_span_finish], ) - if config.report_hostname: + if config._report_hostname: span.set_tag_str(HOSTNAME_KEY, hostname.get_hostname()) if not span._parent: @@ -1181,8 +1181,8 @@ def _on_global_config_update(self, cfg: Config, items: List[str]) -> None: if cfg._tracing_enabled is True and cfg._get_source("_tracing_enabled") != "remote_config": self.enabled = True - if "logs_injection" in items: - if config.logs_injection: + if "_logs_injection" in items: + if config._logs_injection: from ddtrace.contrib.logging import patch patch() diff --git a/ddtrace/bootstrap/preload.py b/ddtrace/bootstrap/preload.py index 93eba3cc6e6..c78aef7a5ee 100644 --- a/ddtrace/bootstrap/preload.py +++ b/ddtrace/bootstrap/preload.py @@ -139,8 +139,8 @@ def _(): modules_to_bool = {k: asbool(v) for k, v in modules_to_str.items()} patch_all(**modules_to_bool) - if config.trace_methods: - _install_trace_methods(config.trace_methods) + if config._trace_methods: + _install_trace_methods(config._trace_methods) if "DD_TRACE_GLOBAL_TAGS" in os.environ: env_tags = os.getenv("DD_TRACE_GLOBAL_TAGS") diff --git a/ddtrace/bootstrap/sitecustomize.py b/ddtrace/bootstrap/sitecustomize.py index 9a27dbd8bb1..b8c37ec4129 100644 --- a/ddtrace/bootstrap/sitecustomize.py +++ b/ddtrace/bootstrap/sitecustomize.py @@ -29,7 +29,7 @@ from ddtrace.internal.utils.formats import asbool # noqa:F401 # Debug mode from the tracer will do the same here, so only need to do this otherwise. -if config.logs_injection: +if config._logs_injection: _configure_log_injection() diff --git a/ddtrace/contrib/internal/aiohttp/middlewares.py b/ddtrace/contrib/internal/aiohttp/middlewares.py index bf921ecabec..07c8afbb07d 100644 --- a/ddtrace/contrib/internal/aiohttp/middlewares.py +++ b/ddtrace/contrib/internal/aiohttp/middlewares.py @@ -60,7 +60,7 @@ async def attach_context(request): # Configure trace search sample rate # DEV: aiohttp is special case maintains separate configuration from config api analytics_enabled = app[CONFIG_KEY]["analytics_enabled"] - if (config.analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: + if (config._analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: request_span.set_tag(_ANALYTICS_SAMPLE_RATE_KEY, app[CONFIG_KEY].get("analytics_sample_rate", True)) # attach the context and the root span to the request; the Context diff --git a/ddtrace/contrib/internal/pyramid/trace.py b/ddtrace/contrib/internal/pyramid/trace.py index 5546bd19b70..cd0569f62df 100644 --- a/ddtrace/contrib/internal/pyramid/trace.py +++ b/ddtrace/contrib/internal/pyramid/trace.py @@ -88,7 +88,7 @@ def trace_tween(request): # DEV: pyramid is special case maintains separate configuration from config api analytics_enabled = settings.get(SETTINGS_ANALYTICS_ENABLED) - if (config.analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: + if (config._analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: span.set_tag(_ANALYTICS_SAMPLE_RATE_KEY, settings.get(SETTINGS_ANALYTICS_SAMPLE_RATE, True)) setattr(request, DD_TRACER, tracer) # used to find the tracer in templates diff --git a/ddtrace/contrib/internal/tornado/handlers.py b/ddtrace/contrib/internal/tornado/handlers.py index c8c88b6318a..f5d6955cdee 100644 --- a/ddtrace/contrib/internal/tornado/handlers.py +++ b/ddtrace/contrib/internal/tornado/handlers.py @@ -54,7 +54,7 @@ def execute(func, handler, args, kwargs): # set analytics sample rate # DEV: tornado is special case maintains separate configuration from config api analytics_enabled = settings["analytics_enabled"] - if (config.analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: + if (config._analytics_enabled and analytics_enabled is not False) or analytics_enabled is True: request_span.set_tag(_ANALYTICS_SAMPLE_RATE_KEY, settings.get("analytics_sample_rate", True)) http_route = _find_route(handler.application.default_router.rules, handler.request) diff --git a/ddtrace/contrib/trace_utils.py b/ddtrace/contrib/trace_utils.py index 9fba9c0a7b5..f0ff816ed43 100644 --- a/ddtrace/contrib/trace_utils.py +++ b/ddtrace/contrib/trace_utils.py @@ -145,8 +145,8 @@ def _store_headers(headers, span, integration_config, request_or_response): return for header_name, header_value in headers.items(): - """config._header_tag_name gets an element of the dictionary in config.trace_http_header_tags - which gets the value from DD_TRACE_HEADER_TAGS environment variable.""" + # config._header_tag_name gets an element of the dictionary in config._trace_http_header_tags + # which gets the value from DD_TRACE_HEADER_TAGS environment variable.""" tag_name = integration_config._header_tag_name(header_name) if tag_name is None: continue @@ -188,7 +188,7 @@ def get_header_value(key): # type: (str) -> Optional[str] return peer_ip ip_header_value = "" - user_configured_ip_header = config.client_ip_header + user_configured_ip_header = config._client_ip_header if user_configured_ip_header: # Used selected the header to use to get the IP ip_header_value = get_header_value( @@ -406,7 +406,7 @@ def _set_url_tag(integration_config, span, url, query): # type: (IntegrationConfig, Span, str, str) -> None if not integration_config.http_tag_query_string: span.set_tag_str(http.URL, strip_query_string(url)) - elif config.global_query_string_obfuscation_disabled: + elif config._global_query_string_obfuscation_disabled: # TODO(munir): This case exists for backwards compatibility. To remove query strings from URLs, # users should set ``DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING=False``. This case should be # removed when config.global_query_string_obfuscation_disabled is removed (v3.0). @@ -491,7 +491,7 @@ def set_http_meta( # We always collect the IP if appsec is enabled to report it on potential vulnerabilities. # https://datadoghq.atlassian.net/wiki/spaces/APS/pages/2118779066/Client+IP+addresses+resolution - if asm_config._asm_enabled or config.retrieve_client_ip: + if asm_config._asm_enabled or config._retrieve_client_ip: # Retrieve the IP if it was calculated on AppSecProcessor.on_span_start request_ip = core.get_item("http.request.remote_ip", span=span) diff --git a/ddtrace/internal/ci_visibility/recorder.py b/ddtrace/internal/ci_visibility/recorder.py index ac2b5ee8f4f..33dcd4635a6 100644 --- a/ddtrace/internal/ci_visibility/recorder.py +++ b/ddtrace/internal/ci_visibility/recorder.py @@ -783,8 +783,8 @@ def set_test_session_name(cls, test_command: str) -> None: log.debug("Not setting test session name because no CIVisibilityEventClient is active") return - if ddconfig.test_session_name: - test_session_name = ddconfig.test_session_name + if ddconfig._test_session_name: + test_session_name = ddconfig._test_session_name else: job_name = instance._tags.get(ci.JOB_NAME) test_session_name = f"{job_name}-{test_command}" if job_name else test_command diff --git a/ddtrace/internal/ci_visibility/utils.py b/ddtrace/internal/ci_visibility/utils.py index e2af9a62b14..248b90a6984 100644 --- a/ddtrace/internal/ci_visibility/utils.py +++ b/ddtrace/internal/ci_visibility/utils.py @@ -105,7 +105,7 @@ def take_over_logger_stream_handler(remove_ddtrace_stream_handlers=True): log.debug("CIVisibility not taking over ddtrace logger handler because debug mode is enabled") return - level = ddconfig.ci_visibility_log_level + level = ddconfig._ci_visibility_log_level if level.upper() == "NONE": log.debug("CIVisibility not taking over ddtrace logger because level is set to: %s", level) diff --git a/ddtrace/internal/debug.py b/ddtrace/internal/debug.py index 89f13de0776..4d533b604b6 100644 --- a/ddtrace/internal/debug.py +++ b/ddtrace/internal/debug.py @@ -144,9 +144,9 @@ def collect(tracer): service=ddtrace.config.service or "", debug=log.isEnabledFor(logging.DEBUG), enabled_cli="ddtrace" in os.getenv("PYTHONPATH", ""), - analytics_enabled=ddtrace.config.analytics_enabled, - log_injection_enabled=ddtrace.config.logs_injection, - health_metrics_enabled=ddtrace.config.health_metrics_enabled, + analytics_enabled=ddtrace.config._analytics_enabled, + log_injection_enabled=ddtrace.config._logs_injection, + health_metrics_enabled=ddtrace.config._health_metrics_enabled, runtime_metrics_enabled=RuntimeWorker.enabled, dd_version=ddtrace.config.version or "", global_tags=os.getenv("DD_TAGS", ""), diff --git a/ddtrace/internal/processor/stats.py b/ddtrace/internal/processor/stats.py index 16c646faa43..d24f0eae585 100644 --- a/ddtrace/internal/processor/stats.py +++ b/ddtrace/internal/processor/stats.py @@ -110,7 +110,7 @@ def __init__(self, agent_url, interval=None, timeout=1.0, retry_attempts=3): } # type: Dict[str, str] container.update_headers_with_container_info(self._headers, container.get_container_info()) self._hostname = "" - if config.report_hostname: + if config._report_hostname: self._hostname = get_hostname() self._lock = Lock() self._enabled = True diff --git a/ddtrace/internal/writer/writer.py b/ddtrace/internal/writer/writer.py index e8a2b6ba8b7..f628daf8f8e 100644 --- a/ddtrace/internal/writer/writer.py +++ b/ddtrace/internal/writer/writer.py @@ -204,7 +204,7 @@ def _intake_url(self, client=None): def _metrics_dist(self, name: str, count: int = 1, tags: Optional[List] = None) -> None: if not self._report_metrics: return - if config.health_metrics_enabled and self.dogstatsd: + if config._health_metrics_enabled and self.dogstatsd: self.dogstatsd.distribution("datadog.%s.%s" % (self.STATSD_NAMESPACE, name), count, tags=tags) def _set_drop_rate(self) -> None: diff --git a/ddtrace/propagation/http.py b/ddtrace/propagation/http.py index 9448311a8ab..abbb8e46c1a 100644 --- a/ddtrace/propagation/http.py +++ b/ddtrace/propagation/http.py @@ -1004,7 +1004,7 @@ def parent_call(): log.debug("tried to inject invalid context %r", span_context) return - if config.propagation_http_baggage_enabled is True and span_context._baggage is not None: + if config._propagation_http_baggage_enabled is True and span_context._baggage is not None: for key in span_context._baggage: headers[_HTTP_BAGGAGE_PREFIX + key] = span_context._baggage[key] @@ -1057,7 +1057,7 @@ def my_controller(url, headers): for prop_style in config._propagation_style_extract: propagator = _PROP_STYLES[prop_style] context = propagator._extract(normalized_headers) # type: ignore - if config.propagation_http_baggage_enabled is True: + if config._propagation_http_baggage_enabled is True: _attach_baggage_to_context(normalized_headers, context) return context # loop through all extract propagation styles @@ -1066,7 +1066,7 @@ def my_controller(url, headers): if contexts: context = HTTPPropagator._resolve_contexts(contexts, styles_w_ctx, normalized_headers) - if config.propagation_http_baggage_enabled is True: + if config._propagation_http_baggage_enabled is True: _attach_baggage_to_context(normalized_headers, context) return context diff --git a/ddtrace/settings/config.py b/ddtrace/settings/config.py index 94e1163ce1d..06e5471c05e 100644 --- a/ddtrace/settings/config.py +++ b/ddtrace/settings/config.py @@ -286,12 +286,12 @@ def _default_config() -> Dict[str, _ConfigItem]: default=lambda: "", envs=[("DD_TRACE_SAMPLING_RULES", str)], ), - "logs_injection": _ConfigItem( + "_logs_injection": _ConfigItem( name="logs_injection_enabled", default=False, envs=[("DD_LOGS_INJECTION", asbool)], ), - "trace_http_header_tags": _ConfigItem( + "_trace_http_header_tags": _ConfigItem( name="trace_header_tags", default=lambda: {}, envs=[("DD_TRACE_HEADER_TAGS", parse_tags_str)], @@ -336,6 +336,30 @@ class Config(object): available and can be updated by users. """ + # Maps deprecated configuration attributes to their corresponding environment variable and + # internalized attribute name + _DEPRECATED_ATTRS = { + "http_tag_query_string": ("_http_tag_query_string", "DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING"), + "trace_http_header_tags": ("_trace_http_header_tags", "DD_TRACE_HEADER_TAGS"), + "report_hostname": ("_report_hostname", "DD_TRACE_REPORT_HOSTNAME"), + "health_metrics_enabled": ("_health_metrics_enabled", "DD_TRACE_HEALTH_METRICS_ENABLED"), + "analytics_enabled": ("_analytics_enabled", "DD_TRACE_ANALYTICS_ENABLED"), + "client_ip_header": ("_client_ip_header", "DD_TRACE_CLIENT_IP_HEADER"), + "retrieve_client_ip": ("_retrieve_client_ip", "DD_TRACE_CLIENT_IP_ENABLED"), + "propagation_http_baggage_enabled": ( + "_propagation_http_baggage_enabled", + "DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED", + ), + "global_query_string_obfuscation_disabled": ( + "_global_query_string_obfuscation_disabled", + 'DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP=""', + ), + "trace_methods": ("_trace_methods", "DD_TRACE_METHODS"), + "ci_visibility_log_level": ("_ci_visibility_log_level", "DD_CIVISIBILITY_LOG_LEVEL"), + "test_session_name": ("_test_session_name", "DD_TEST_SESSION_NAME"), + "logs_injection": ("_logs_injection", "DD_LOGS_INJECTION"), + } + class _HTTPServerConfig(object): _error_statuses = _get_config("DD_TRACE_HTTP_SERVER_ERROR_STATUSES", "500-599") # type: str _error_ranges = get_error_ranges(_error_statuses) # type: List[Tuple[int, int]] @@ -416,7 +440,7 @@ def __init__(self): self._partial_flush_enabled = _get_config("DD_TRACE_PARTIAL_FLUSH_ENABLED", True, asbool) self._partial_flush_min_spans = _get_config("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS", 300, int) - self.http = HttpConfig(header_tags=self.trace_http_header_tags) + self.http = HttpConfig(header_tags=self._trace_http_header_tags) self._remote_config_enabled = _get_config("DD_REMOTE_CONFIGURATION_ENABLED", True, asbool) self._remote_config_poll_interval = _get_config( ["DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS", "DD_REMOTECONFIG_POLL_SECONDS"], 5.0, float @@ -456,8 +480,8 @@ def __init__(self): # Master switch for turning on and off trace search by default # this weird invocation of getenv is meant to read the DD_ANALYTICS_ENABLED # legacy environment variable. It should be removed in the future - self.analytics_enabled = _get_config(["DD_TRACE_ANALYTICS_ENABLED", "DD_ANALYTICS_ENABLED"], False, asbool) - if self.analytics_enabled: + self._analytics_enabled = _get_config(["DD_TRACE_ANALYTICS_ENABLED", "DD_ANALYTICS_ENABLED"], False, asbool) + if self._analytics_enabled: deprecate( "Datadog App Analytics is deprecated and will be removed in a future version. " "App Analytics can be enabled via DD_TRACE_ANALYTICS_ENABLED and DD_ANALYTICS_ENABLED " @@ -465,11 +489,10 @@ def __init__(self): "These configurations will also be removed.", category=DDTraceDeprecationWarning, ) + self._client_ip_header = _get_config("DD_TRACE_CLIENT_IP_HEADER") + self._retrieve_client_ip = _get_config("DD_TRACE_CLIENT_IP_ENABLED", False, asbool) - self.client_ip_header = _get_config("DD_TRACE_CLIENT_IP_HEADER") - self.retrieve_client_ip = _get_config("DD_TRACE_CLIENT_IP_ENABLED", False, asbool) - - self.propagation_http_baggage_enabled = _get_config("DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED", False, asbool) + self._propagation_http_baggage_enabled = _get_config("DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED", False, asbool) self.env = _get_config("DD_ENV", self.tags.get("env")) self.service = _get_config("DD_SERVICE", self.tags.get("service", DEFAULT_SPAN_SERVICE_NAME)) @@ -496,9 +519,9 @@ def __init__(self): if self.version and "version" in self.tags: del self.tags["version"] - self.report_hostname = _get_config("DD_TRACE_REPORT_HOSTNAME", False, asbool) + self._report_hostname = _get_config("DD_TRACE_REPORT_HOSTNAME", False, asbool) - self.health_metrics_enabled = _get_config("DD_TRACE_HEALTH_METRICS_ENABLED", False, asbool) + self._health_metrics_enabled = _get_config("DD_TRACE_HEALTH_METRICS_ENABLED", False, asbool) self._telemetry_enabled = _get_config("DD_INSTRUMENTATION_TELEMETRY_ENABLED", True, asbool) self._telemetry_heartbeat_interval = _get_config("DD_TELEMETRY_HEARTBEAT_INTERVAL", 60, float) @@ -572,22 +595,22 @@ def __init__(self): dd_trace_obfuscation_query_string_regexp = _get_config( "DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP", DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP_DEFAULT ) - self.global_query_string_obfuscation_disabled = dd_trace_obfuscation_query_string_regexp == "" + self._global_query_string_obfuscation_disabled = dd_trace_obfuscation_query_string_regexp == "" self._obfuscation_query_string_pattern = None - self.http_tag_query_string = True # Default behaviour of query string tagging in http.url + self._http_tag_query_string = True # Default behaviour of query string tagging in http.url try: self._obfuscation_query_string_pattern = re.compile( dd_trace_obfuscation_query_string_regexp.encode("ascii") ) except Exception: log.warning("Invalid obfuscation pattern, disabling query string tracing", exc_info=True) - self.http_tag_query_string = False # Disable query string tagging if malformed obfuscation pattern + self._http_tag_query_string = False # Disable query string tagging if malformed obfuscation pattern self._ci_visibility_agentless_enabled = _get_config("DD_CIVISIBILITY_AGENTLESS_ENABLED", False, asbool) self._ci_visibility_agentless_url = _get_config("DD_CIVISIBILITY_AGENTLESS_URL", "") self._ci_visibility_intelligent_testrunner_enabled = _get_config("DD_CIVISIBILITY_ITR_ENABLED", True, asbool) - self.ci_visibility_log_level = _get_config("DD_CIVISIBILITY_LOG_LEVEL", "info") - self.test_session_name = _get_config("DD_TEST_SESSION_NAME") + self._ci_visibility_log_level = _get_config("DD_CIVISIBILITY_LOG_LEVEL", "info") + self._test_session_name = _get_config("DD_TEST_SESSION_NAME") self._test_visibility_early_flake_detection_enabled = _get_config( "DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED", True, asbool ) @@ -607,7 +630,7 @@ def __init__(self): removal_version="3.0.0", ) - self.trace_methods = _get_config("DD_TRACE_METHODS") + self._trace_methods = _get_config("DD_TRACE_METHODS") self._telemetry_install_id = _get_config("DD_INSTRUMENTATION_INSTALL_ID") self._telemetry_install_type = _get_config("DD_INSTRUMENTATION_INSTALL_TYPE") @@ -626,8 +649,25 @@ def __init__(self): self._inject_was_attempted = _get_config("_DD_INJECT_WAS_ATTEMPTED", False, asbool) def __getattr__(self, name) -> Any: + if name in self._DEPRECATED_ATTRS: + new_name, env_var = self._DEPRECATED_ATTRS[name] + deprecate( + f"ddtrace.config.{name} is deprecated", + message=f"Use {env_var} configuration instead. " + "This configuration must be set before importing ddtrace.", + removal_version="3.0.0", + category=DDTraceDeprecationWarning, + ) + if name == new_name: + raise RuntimeError( + f"Circular mapping detected: deprecated attribute {name} " + f"in {self._DEPRECATED_ATTRS} maps to a deprecated attribute {new_name}" + ) + return getattr(self, new_name) + if name in self._config: return self._config[name].value() + if name not in self._integration_configs: self._integration_configs[name] = IntegrationConfig(self, name) @@ -754,6 +794,17 @@ def __setattr__(self, key, value): self._set_config_items([(key, value, "code")]) return None else: + if key in self._DEPRECATED_ATTRS: + # replace deprecated attribute name with the new name + new_key, env_var = self._DEPRECATED_ATTRS[key] + deprecate( + f"ddtrace.config.{key} is deprecated", + message=f"Use {env_var} configuration instead. " + "This configuration must be set before importing ddtrace.", + removal_version="3.0.0", + category=DDTraceDeprecationWarning, + ) + key = new_key return super(self.__class__, self).__setattr__(key, value) def _set_config_items(self, items): @@ -826,7 +877,7 @@ def _handle_remoteconfig(self, data, test_tracer=None): base_rc_config["_trace_sampling_rules"] = trace_sampling_rules if "log_injection_enabled" in lib_config: - base_rc_config["logs_injection"] = lib_config["log_injection_enabled"] + base_rc_config["_logs_injection"] = lib_config["log_injection_enabled"] if "tracing_tags" in lib_config: tags = lib_config["tracing_tags"] @@ -841,18 +892,18 @@ def _handle_remoteconfig(self, data, test_tracer=None): tags = lib_config["tracing_header_tags"] if tags: tags = self._format_tags(lib_config["tracing_header_tags"]) - base_rc_config["trace_http_header_tags"] = tags + base_rc_config["_trace_http_header_tags"] = tags self._set_config_items([(k, v, "remote_config") for k, v in base_rc_config.items()]) # called unconditionally to handle the case where header tags have been unset self._handle_remoteconfig_header_tags(base_rc_config) def _handle_remoteconfig_header_tags(self, base_rc_config): """Implements precedence order between remoteconfig header tags from code, env, and RC""" - header_tags_conf = self._config["trace_http_header_tags"] + header_tags_conf = self._config["_trace_http_header_tags"] env_headers = header_tags_conf._env_value or {} code_headers = header_tags_conf._code_value or {} non_rc_header_tags = {**code_headers, **env_headers} - selected_header_tags = base_rc_config.get("trace_http_header_tags") or non_rc_header_tags + selected_header_tags = base_rc_config.get("_trace_http_header_tags") or non_rc_header_tags self.http = HttpConfig(header_tags=selected_header_tags) def _format_tags(self, tags: List[Union[str, Dict]]) -> Dict[str, str]: diff --git a/ddtrace/settings/integration.py b/ddtrace/settings/integration.py index 41a10eab1e2..ad901baf219 100644 --- a/ddtrace/settings/integration.py +++ b/ddtrace/settings/integration.py @@ -76,10 +76,10 @@ def _get_analytics_settings(self): if analytics_enabled: deprecate( - "Datadog App Analytics is deprecated" + "Datadog App Analytics is deprecated. " f"App Analytics can be enabled via {env} and {legacy_env} " f"environment variables and the ddtrace.config.{self.integration_name}.analytics_enabled configuration." - " This feature and its associated configuration will be removed in a future release.", + " This feature and its associated configurations will be removed in a future release.", category=DDTraceDeprecationWarning, ) @@ -93,7 +93,7 @@ def _get_analytics_settings(self): return analytics_enabled, analytics_sample_rate def get_http_tag_query_string(self, value): - if self.global_config.http_tag_query_string: + if self.global_config._http_tag_query_string: dd_http_server_tag_query_string = value if value else os.getenv("DD_HTTP_SERVER_TAG_QUERY_STRING", "true") # If invalid value, will default to True return dd_http_server_tag_query_string.lower() not in ("false", "0") @@ -135,7 +135,7 @@ def _header_tag_name(self, header_name): def _is_analytics_enabled(self, use_global_config): # DEV: analytics flag can be None which should not be taken as # enabled when global flag is disabled - if use_global_config and self.global_config.analytics_enabled: + if use_global_config and self.global_config._analytics_enabled: return self.analytics_enabled is not False else: return self.analytics_enabled is True diff --git a/releasenotes/notes/deprecate-public-config-attrs-744b806a66d96da4.yaml b/releasenotes/notes/deprecate-public-config-attrs-744b806a66d96da4.yaml new file mode 100644 index 00000000000..422b8f0ba0d --- /dev/null +++ b/releasenotes/notes/deprecate-public-config-attrs-744b806a66d96da4.yaml @@ -0,0 +1,11 @@ +--- +deprecations: + - | + tracing: Deprecates the following ``ddtrace.config`` attributes: + http_tag_query_string, trace_http_header_tags, report_hostname, health_metrics_enabled, analytics_enabled, + client_ip_header, retrieve_client_ip, propagation_http_baggage_enabled, global_query_string_obfuscation_disabled, + trace_methods, ci_visibility_log_level, and service_mapping. These attributes are now private and should not be accessed directly. + The following environment variables should be used instead: DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING, DD_TRACE_HEADER_TAGS, + DD_TRACE_REPORT_HOSTNAME, DD_TRACE_HEALTH_METRICS_ENABLED, DD_TRACE_ANALYTICS_ENABLED, DD_TRACE_CLIENT_IP_HEADER, + DD_TRACE_CLIENT_IP_ENABLED, DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED, DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP, + DD_TRACE_METHODS, DD_CIVISIBILITY_LOG_LEVEL, and DD_SERVICE_MAPPING. \ No newline at end of file diff --git a/tests/appsec/contrib_appsec/utils.py b/tests/appsec/contrib_appsec/utils.py index 7d03ace98b1..6cd915c99af 100644 --- a/tests/appsec/contrib_appsec/utils.py +++ b/tests/appsec/contrib_appsec/utils.py @@ -296,7 +296,7 @@ def test_client_ip_header_set_by_env_var( ): from ddtrace.ext import http - with override_global_config(dict(_asm_enabled=asm_enabled, client_ip_header=env_var)): + with override_global_config(dict(_asm_enabled=asm_enabled, _client_ip_header=env_var)): self.update_tracer(interface) response = interface.client.get("/", headers=headers) assert self.status(response) == 200 diff --git a/tests/contrib/pyramid/utils.py b/tests/contrib/pyramid/utils.py index 23eec4d2bd2..1d0ec084075 100644 --- a/tests/contrib/pyramid/utils.py +++ b/tests/contrib/pyramid/utils.py @@ -75,7 +75,7 @@ def test_200(self, query_string=""): else: assert http.QUERY_STRING not in s.get_tags() - if config.http_tag_query_string: + if config._http_tag_query_string: assert s.get_tag(http.URL) == "http://localhost/" + fqs else: assert s.get_tag(http.URL) == "http://localhost/" diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 73dc7a887f8..5a7ab1537e6 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -246,7 +246,7 @@ def test_metrics(): assert t._partial_flush_min_spans == 300 - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): statsd_mock = mock.Mock() t._writer.dogstatsd = statsd_mock with mock.patch("ddtrace.internal.writer.writer.log") as log: @@ -296,7 +296,7 @@ def test_metrics_partial_flush_disabled(): partial_flush_enabled=False, ) - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): statsd_mock = mock.Mock() t._writer.dogstatsd = statsd_mock with mock.patch("ddtrace.internal.writer.writer.log") as log: diff --git a/tests/integration/test_settings.py b/tests/integration/test_settings.py index 08e9aadb530..e71b14a3854 100644 --- a/tests/integration/test_settings.py +++ b/tests/integration/test_settings.py @@ -82,8 +82,8 @@ def test_setting_origin_code(test_agent_session, run_python_code_in_subprocess): from ddtrace import config, tracer config._trace_sample_rate = 0.2 -config.logs_injection = False -config.trace_http_header_tags = {"header": "value"} +config._logs_injection = False +config._trace_http_header_tags = {"header": "value"} config.tags = {"header": "value"} config._tracing_enabled = False diff --git a/tests/integration/test_trace_stats.py b/tests/integration/test_trace_stats.py index e77eecf9a19..0fd7695fc23 100644 --- a/tests/integration/test_trace_stats.py +++ b/tests/integration/test_trace_stats.py @@ -143,12 +143,12 @@ def test_stats_report_hostname(get_hostname): get_hostname.return_value = "test-hostname" # Enable report_hostname - with override_global_config(dict(report_hostname=True)): + with override_global_config(dict(_report_hostname=True)): p = SpanStatsProcessorV06("http://localhost:8126") assert p._hostname == "test-hostname" # Disable report_hostname - with override_global_config(dict(report_hostname=False)): + with override_global_config(dict(_report_hostname=False)): p = SpanStatsProcessorV06("http://localhost:8126") assert p._hostname == "" diff --git a/tests/internal/test_settings.py b/tests/internal/test_settings.py index 00ebdfc7ccd..cfe322beddb 100644 --- a/tests/internal/test_settings.py +++ b/tests/internal/test_settings.py @@ -52,13 +52,13 @@ def _deleted_rc_config(): { "expected": { "_trace_sample_rate": 1.0, - "logs_injection": False, - "trace_http_header_tags": {}, + "_logs_injection": False, + "_trace_http_header_tags": {}, }, "expected_source": { "_trace_sample_rate": "default", - "logs_injection": "default", - "trace_http_header_tags": "default", + "_logs_injection": "default", + "_trace_http_header_tags": "default", }, }, { @@ -81,38 +81,38 @@ def _deleted_rc_config(): }, { "env": {"DD_LOGS_INJECTION": "true"}, - "expected": {"logs_injection": True}, - "expected_source": {"logs_injection": "env_var"}, + "expected": {"_logs_injection": True}, + "expected_source": {"_logs_injection": "env_var"}, }, { "env": {"DD_LOGS_INJECTION": "true"}, - "code": {"logs_injection": False}, - "expected": {"logs_injection": False}, - "expected_source": {"logs_injection": "code"}, + "code": {"_logs_injection": False}, + "expected": {"_logs_injection": False}, + "expected_source": {"_logs_injection": "code"}, }, { "env": {"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1:header_tag_1,X-Header-Tag-2:header_tag_2"}, "expected": { - "trace_http_header_tags": {"X-Header-Tag-1": "header_tag_1", "X-Header-Tag-2": "header_tag_2"} + "_trace_http_header_tags": {"X-Header-Tag-1": "header_tag_1", "X-Header-Tag-2": "header_tag_2"} }, - "expected_source": {"trace_http_header_tags": "env_var"}, + "expected_source": {"_trace_http_header_tags": "env_var"}, }, { "env": {"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1:header_tag_1,X-Header-Tag-2:header_tag_2"}, - "code": {"trace_http_header_tags": {"header": "value"}}, - "expected": {"trace_http_header_tags": {"header": "value"}}, - "expected_source": {"trace_http_header_tags": "code"}, + "code": {"_trace_http_header_tags": {"header": "value"}}, + "expected": {"_trace_http_header_tags": {"header": "value"}}, + "expected_source": {"_trace_http_header_tags": "code"}, }, { "env": {"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1,X-Header-Tag-2,X-Header-Tag-3:specific_tag3"}, "expected": { - "trace_http_header_tags": { + "_trace_http_header_tags": { "X-Header-Tag-1": "", "X-Header-Tag-2": "", "X-Header-Tag-3": "specific_tag3", } }, - "expected_source": {"trace_http_header_tags": "env_var"}, + "expected_source": {"_trace_http_header_tags": "env_var"}, }, { "env": {"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1:header_tag_1,X-Header-Tag-2:header_tag_2"}, @@ -122,14 +122,14 @@ def _deleted_rc_config(): {"header": "X-Header-Tag-70", "tag_name": ""}, ] }, - "code": {"trace_http_header_tags": {"header": "value"}}, + "code": {"_trace_http_header_tags": {"header": "value"}}, "expected": { - "trace_http_header_tags": { + "_trace_http_header_tags": { "X-Header-Tag-69": "header_tag_69", "X-Header-Tag-70": "", } }, - "expected_source": {"trace_http_header_tags": "remote_config"}, + "expected_source": {"_trace_http_header_tags": "remote_config"}, }, { "env": {"DD_TAGS": "key:value,key2:value2"}, @@ -220,7 +220,7 @@ def test_settings_missing_lib_config(config, monkeypatch): def test_config_subscription(config): - for s in ("_trace_sample_rate", "logs_injection", "trace_http_header_tags"): + for s in ("_trace_sample_rate", "_logs_injection", "_trace_http_header_tags"): _handler = mock.MagicMock() config._subscribe([s], _handler) setattr(config, s, "1") @@ -615,3 +615,34 @@ def test_remoteconfig_header_tags(run_python_code_in_subprocess): env=env, ) assert status == 0, f"err={err.decode('utf-8')} out={out.decode('utf-8')}" + + +def test_config_public_properties_and_methods(): + # Regression test to prevent unexpected changes to public attributes in Config + # By default most attributes should be private and set via Environment Variables + from ddtrace.settings import Config + + public_attrs = set() + c = Config() + # Check for public attributes in Config + for attr in dir(c): + if not attr.startswith("_") and not attr.startswith("__"): + public_attrs.add(attr) + # Check for public keys in Config._config + for key in c._config: + if not key.startswith("_"): + public_attrs.add(key) + + assert public_attrs == { + "trace_headers", + "service", + "env", + "tags", + "version", + "http", + "http_server", + "header_is_traced", + "convert_rc_trace_sampling_rules", + "enable_remote_configuration", + "get_from", + }, public_attrs diff --git a/tests/tracer/test_env_vars.py b/tests/tracer/test_env_vars.py index 272dd751196..fb5f5ada055 100644 --- a/tests/tracer/test_env_vars.py +++ b/tests/tracer/test_env_vars.py @@ -52,8 +52,8 @@ def test_obfuscation_querystring_pattern_env_var( """import re;from ddtrace import config; from ddtrace.settings.config import DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP_DEFAULT; assert config._obfuscation_query_string_pattern == %s; -assert config.global_query_string_obfuscation_disabled == %s; -assert config.http_tag_query_string == %s +assert config._global_query_string_obfuscation_disabled == %s; +assert config._http_tag_query_string == %s """ % ( expected_obfuscation_config, diff --git a/tests/tracer/test_propagation.py b/tests/tracer/test_propagation.py index ca3341d6a88..62f93ff2d04 100644 --- a/tests/tracer/test_propagation.py +++ b/tests/tracer/test_propagation.py @@ -66,7 +66,7 @@ def test_inject(tracer): # noqa: F811 def test_inject_with_baggage_http_propagation(tracer): # noqa: F811 - with override_global_config(dict(propagation_http_baggage_enabled=True)): + with override_global_config(dict(_propagation_http_baggage_enabled=True)): ctx = Context(trace_id=1234, sampling_priority=2, dd_origin="synthetics") ctx._set_baggage_item("key1", "val1") tracer.context_provider.activate(ctx) @@ -637,7 +637,7 @@ def test_asm_standalone_present_appsec_tag_appsec_event_present_propagation_forc def test_extract_with_baggage_http_propagation(tracer): # noqa: F811 - with override_global_config(dict(propagation_http_baggage_enabled=True)): + with override_global_config(dict(_propagation_http_baggage_enabled=True)): headers = { "x-datadog-trace-id": "1234", "x-datadog-parent-id": "5678", diff --git a/tests/tracer/test_settings.py b/tests/tracer/test_settings.py index 5796825b98d..b947f416e75 100644 --- a/tests/tracer/test_settings.py +++ b/tests/tracer/test_settings.py @@ -1,3 +1,5 @@ +import warnings + import pytest from ddtrace.settings import Config @@ -11,11 +13,11 @@ class TestConfig(BaseTestCase): def test_logs_injection(self): with self.override_env(dict(DD_LOGS_INJECTION="True")): config = Config() - self.assertTrue(config.logs_injection) + self.assertTrue(config._logs_injection) with self.override_env(dict(DD_LOGS_INJECTION="false")): config = Config() - self.assertFalse(config.logs_injection) + self.assertFalse(config._logs_injection) def test_service(self): # If none is provided the default should be ``None`` @@ -211,3 +213,58 @@ def test_x_datadog_tags(env, expected): with override_env(env): _ = Config() assert expected == (_._x_datadog_tags_max_length, _._x_datadog_tags_enabled) + + +@pytest.mark.parametrize( + "deprecated_name,name,test_value,env", + ( + ("http_tag_query_string", "_http_tag_query_string", True, "DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING"), + ("trace_http_header_tags", "_trace_http_header_tags", {"x-dd": "x_dd"}, "DD_TRACE_HEADER_TAGS"), + ("report_hostname", "_report_hostname", True, "DD_TRACE_REPORT_HOSTNAME"), + ("health_metrics_enabled", "_health_metrics_enabled", True, "DD_TRACE_HEALTH_METRICS_ENABLED"), + ("analytics_enabled", "_analytics_enabled", True, "DD_TRACE_ANALYTICS_ENABLED"), + ("client_ip_header", "_client_ip_header", True, "DD_TRACE_CLIENT_IP_HEADER"), + ("retrieve_client_ip", "_retrieve_client_ip", True, "DD_TRACE_CLIENT_IP_ENABLED"), + ( + "propagation_http_baggage_enabled", + "_propagation_http_baggage_enabled", + True, + "DD_TRACE_PROPAGATION_HTTP_BAGGAGE_ENABLED", + ), + ( + "global_query_string_obfuscation_disabled", + "_global_query_string_obfuscation_disabled", + True, + 'DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP=""', + ), + ("trace_methods", "_trace_methods", ["monkey.banana_melon"], "DD_TRACE_METHODS"), + ("ci_visibility_log_level", "_ci_visibility_log_level", True, "DD_CIVISIBILITY_LOG_LEVEL"), + ("test_session_name", "_test_session_name", "yessirapp", "DD_TEST_SESSION_NAME"), + ("logs_injection", "_logs_injection", False, "DD_LOGS_INJECTION"), + ), +) +def test_deprecated_config_attributes(deprecated_name, name, test_value, env): + """Ensures setting and getting deprecated attributes log a warning and still + set/return the expected values. + """ + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter("always") + config = Config() + # Test getting/setting a configuration by the expected name + setattr(config, name, test_value) + assert getattr(config, name) == test_value + assert len(warns) == 0 + expected_warning = ( + f"ddtrace.config.{deprecated_name} is deprecated and will be " + f"removed in version '3.0.0': Use {env} configuration instead. " + "This configuration must be set before importing ddtrace." + ) + # Test getting the configuration by the deprecated name + getattr(config, deprecated_name) == test_value + assert len(warns) == 1 + assert str(warns[0].message) == expected_warning + # Test setting the configuration by the deprecated name + setattr(config, deprecated_name, None) + assert getattr(config, name) is None + assert len(warns) == 2 + assert str(warns[1].message) == expected_warning diff --git a/tests/tracer/test_trace_utils.py b/tests/tracer/test_trace_utils.py index d9c5508df93..fdf45548ad8 100644 --- a/tests/tracer/test_trace_utils.py +++ b/tests/tracer/test_trace_utils.py @@ -315,11 +315,11 @@ def test_set_http_meta_with_http_header_tags_config(): from ddtrace._trace.span import Span from ddtrace.contrib.trace_utils import set_http_meta - assert config.trace_http_header_tags == { + assert config._trace_http_header_tags == { "header1": "", "header2": "", "header3": "third-header", - }, config.trace_http_header_tags + }, config._trace_http_header_tags integration_config = config.new_integration assert integration_config.is_header_tracing_configured @@ -647,7 +647,7 @@ def test_set_http_meta_case_sensitive_headers_notfound(mock_store_headers, span, ], ) def test_get_request_header_ip(header_env_var, headers_dict, expected, span): - with override_global_config(dict(_asm_enabled=True, client_ip_header=header_env_var)): + with override_global_config(dict(_asm_enabled=True, _client_ip_header=header_env_var)): ip = trace_utils._get_request_header_client_ip(headers_dict, None, False) assert ip == expected @@ -755,7 +755,7 @@ def test_set_http_meta_headers_ip_asm_disabled_env_default_false(span, int_confi def test_set_http_meta_headers_ip_asm_disabled_env_false(span, int_config): - with override_global_config(dict(_asm_enabled=False, retrieve_client_ip=False)): + with override_global_config(dict(_asm_enabled=False, _retrieve_client_ip=False)): int_config.myint.http._header_tags = {"enabled": True} assert int_config.myint.is_header_tracing_configured is True trace_utils.set_http_meta( @@ -769,7 +769,7 @@ def test_set_http_meta_headers_ip_asm_disabled_env_false(span, int_config): def test_set_http_meta_headers_ip_asm_disabled_env_true(span, int_config): - with override_global_config(dict(_asm_enabled=False, retrieve_client_ip=True)): + with override_global_config(dict(_asm_enabled=False, _retrieve_client_ip=True)): int_config.myint.http._header_tags = {"enabled": True} assert int_config.myint.is_header_tracing_configured is True trace_utils.set_http_meta( @@ -1078,7 +1078,7 @@ def test_url_in_http_meta(span, int_config): STRIPPED_URL = "http://example.com/search#frag?ment" int_config.http_tag_query_string = True - with override_global_config({"global_query_string_obfuscation_disabled": False}): + with override_global_config({"_global_query_string_obfuscation_disabled": False}): trace_utils.set_http_meta( span, int_config, @@ -1087,7 +1087,7 @@ def test_url_in_http_meta(span, int_config): status_code=200, ) assert span.get_tag(http.URL) == REDACTED_URL - with override_global_config({"global_query_string_obfuscation_disabled": True}): + with override_global_config({"_global_query_string_obfuscation_disabled": True}): trace_utils.set_http_meta( span, int_config, @@ -1098,7 +1098,7 @@ def test_url_in_http_meta(span, int_config): assert span.get_tag(http.URL) == SENSITIVE_QS_URL int_config.http_tag_query_string = False - with override_global_config({"global_query_string_obfuscation_disabled": False}): + with override_global_config({"_global_query_string_obfuscation_disabled": False}): trace_utils.set_http_meta( span, int_config, @@ -1107,7 +1107,7 @@ def test_url_in_http_meta(span, int_config): status_code=200, ) assert span.get_tag(http.URL) == STRIPPED_URL - with override_global_config({"global_query_string_obfuscation_disabled": True}): + with override_global_config({"_global_query_string_obfuscation_disabled": True}): trace_utils.set_http_meta( span, int_config, diff --git a/tests/tracer/test_tracer.py b/tests/tracer/test_tracer.py index 59bcbf345cb..04f1af3840a 100644 --- a/tests/tracer/test_tracer.py +++ b/tests/tracer/test_tracer.py @@ -1601,7 +1601,7 @@ def test_manual_drop(tracer, test_spans): @mock.patch("ddtrace.internal.hostname.get_hostname") def test_get_report_hostname_enabled(get_hostname, tracer, test_spans): get_hostname.return_value = "test-hostname" - with override_global_config(dict(report_hostname=True)): + with override_global_config(dict(_report_hostname=True)): with tracer.trace("span"): with tracer.trace("child"): pass @@ -1616,7 +1616,7 @@ def test_get_report_hostname_enabled(get_hostname, tracer, test_spans): @mock.patch("ddtrace.internal.hostname.get_hostname") def test_get_report_hostname_disabled(get_hostname, tracer, test_spans): get_hostname.return_value = "test-hostname" - with override_global_config(dict(report_hostname=False)): + with override_global_config(dict(_report_hostname=False)): with tracer.trace("span"): with tracer.trace("child"): pass @@ -1631,7 +1631,7 @@ def test_get_report_hostname_disabled(get_hostname, tracer, test_spans): @mock.patch("ddtrace.internal.hostname.get_hostname") def test_get_report_hostname_default(get_hostname, tracer, test_spans): get_hostname.return_value = "test-hostname" - with override_global_config(dict(report_hostname=False)): + with override_global_config(dict(_report_hostname=False)): with tracer.trace("span"): with tracer.trace("child"): pass diff --git a/tests/tracer/test_writer.py b/tests/tracer/test_writer.py index 13bd58c9f16..2089971c554 100644 --- a/tests/tracer/test_writer.py +++ b/tests/tracer/test_writer.py @@ -59,7 +59,7 @@ class AgentWriterTests(BaseTestCase): def test_metrics_disabled(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=False)): + with override_global_config(dict(_health_metrics_enabled=False)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -71,7 +71,7 @@ def test_metrics_disabled(self): def test_metrics_bad_endpoint(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -89,7 +89,7 @@ def test_metrics_bad_endpoint(self): def test_metrics_trace_too_big(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True, _trace_writer_buffer_size=15000)): + with override_global_config(dict(_health_metrics_enabled=True, _trace_writer_buffer_size=15000)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -124,7 +124,7 @@ def test_metrics_trace_too_big(self): def test_metrics_multi(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j) for j in range(5)]) @@ -158,7 +158,7 @@ def test_metrics_multi(self): def test_generate_health_metrics_with_different_tags(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False) # Queue 3 health metrics where each metric has the same name but different tags @@ -189,7 +189,7 @@ def test_generate_health_metrics_with_different_tags(self): def test_report_metrics_disabled(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False, report_metrics=False) # Queue 3 health metrics where each metric has the same name but different tags @@ -224,7 +224,7 @@ def test_report_metrics_disabled(self): def test_write_sync(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=True) writer.write([Span(name="name", trace_id=1, span_id=j + 1, parent_id=j or None) for j in range(5)]) statsd.distribution.assert_has_calls( @@ -241,7 +241,7 @@ def test_write_sync(self): def test_drop_reason_bad_endpoint(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -260,7 +260,7 @@ def test_drop_reason_bad_endpoint(self): def test_drop_reason_trace_too_big(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, buffer_size=1000) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -284,7 +284,7 @@ def test_drop_reason_trace_too_big(self): def test_drop_reason_buffer_full(self): statsd = mock.Mock() - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", buffer_size=1000, dogstatsd=statsd) for i in range(10): writer.write([Span(name="name", trace_id=i, span_id=j + 1, parent_id=j or None) for j in range(5)]) @@ -311,7 +311,7 @@ def test_drop_reason_encoding_error(self): writer_encoder = mock.Mock() writer_encoder.__len__ = (lambda *args: n_traces).__get__(writer_encoder) writer_encoder.encode.side_effect = Exception - with override_global_config(dict(health_metrics_enabled=True)): + with override_global_config(dict(_health_metrics_enabled=True)): writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, sync_mode=False) for client in writer._clients: client.encoder = writer_encoder @@ -338,7 +338,7 @@ def test_keep_rate(self): writer_run_periodic = mock.Mock() writer_put = mock.Mock() writer_put.return_value = Response(status=200) - with override_global_config(dict(health_metrics_enabled=False, _trace_writer_buffer_size=8 << 20)): + with override_global_config(dict(_health_metrics_enabled=False, _trace_writer_buffer_size=8 << 20)): # this test decodes the msgpack payload to verify the keep rate. v04 is easier to decode so we use that here writer = self.WRITER_CLASS("http://asdf:1234", dogstatsd=statsd, api_version="v0.4") writer.run_periodic = writer_run_periodic diff --git a/tests/utils.py b/tests/utils.py index 62389e0fbba..1fb8d8fa96a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -113,10 +113,10 @@ def override_global_config(values): # DEV: We do not do `ddtrace.config.keys()` because we have all of our integrations global_config_keys = [ "_tracing_enabled", - "client_ip_header", - "retrieve_client_ip", - "report_hostname", - "health_metrics_enabled", + "_client_ip_header", + "_retrieve_client_ip", + "_report_hostname", + "_health_metrics_enabled", "_propagation_style_extract", "_propagation_style_inject", "_x_datadog_tags_max_length", @@ -129,7 +129,7 @@ def override_global_config(values): "_raise", "_trace_compute_stats", "_obfuscation_query_string_pattern", - "global_query_string_obfuscation_disabled", + "_global_query_string_obfuscation_disabled", "_ci_visibility_agentless_url", "_ci_visibility_agentless_enabled", "_subexec_sensitive_user_wildcards", @@ -147,7 +147,7 @@ def override_global_config(values): "_trace_writer_connection_reuse", "_trace_writer_log_err_payload", "_span_traceback_max_size", - "propagation_http_baggage_enabled", + "_propagation_http_baggage_enabled", "_telemetry_enabled", "_telemetry_dependency_collection", "_dd_site",