Skip to content

Commit

Permalink
get ready to remove shit from ddtrace.config
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Oct 9, 2024
1 parent 48c2a2c commit bf6be2b
Show file tree
Hide file tree
Showing 30 changed files with 269 additions and 119 deletions.
8 changes: 4 additions & 4 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/bootstrap/preload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/bootstrap/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/aiohttp/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/pyramid/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/tornado/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions ddtrace/contrib/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions ddtrace/internal/ci_visibility/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/ci_visibility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/internal/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/processor/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/writer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/propagation/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
Loading

0 comments on commit bf6be2b

Please sign in to comment.