Skip to content

Commit

Permalink
chore(configurations): remove deprecated tracing env vars (#12176)
Browse files Browse the repository at this point in the history
## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
mabdinur authored Feb 5, 2025
1 parent 3081919 commit a2b1d7b
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 286 deletions.
71 changes: 10 additions & 61 deletions ddtrace/settings/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from ddtrace.internal.serverless import in_gcp_function
from ddtrace.internal.telemetry import telemetry_writer
from ddtrace.internal.utils.cache import cachedmethod
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate

from .._trace.pin import Pin
from ..internal import gitmetadata
Expand Down Expand Up @@ -264,9 +262,11 @@ def _parse_global_tags(s):

def _default_config() -> Dict[str, _ConfigItem]:
return {
# Remove the _trace_sample_rate property, _trace_sampling_rules should be the source of truth
"_trace_sample_rate": _ConfigItem(
default=1.0,
envs=[("DD_TRACE_SAMPLE_RATE", float)],
# trace_sample_rate is placeholder, this code will be removed up after v3.0
envs=[("trace_sample_rate", float)],
),
"_trace_sampling_rules": _ConfigItem(
default=lambda: "",
Expand Down Expand Up @@ -352,14 +352,6 @@ def __init__(self):
self._from_endpoint = ENDPOINT_FETCHED_CONFIG
self._config = _default_config()

sample_rate = os.getenv("DD_TRACE_SAMPLE_RATE")
if sample_rate is not None:
deprecate(
"DD_TRACE_SAMPLE_RATE is deprecated",
message="Please use DD_TRACE_SAMPLING_RULES instead.",
removal_version="3.0.0",
)

# Use a dict as underlying storing mechanism for integration configs
self._integration_configs = {}

Expand All @@ -368,9 +360,6 @@ def __init__(self):

rate_limit = os.getenv("DD_TRACE_RATE_LIMIT")
if rate_limit is not None and self._trace_sampling_rules in ("", "[]"):
# This warning will be logged when DD_TRACE_SAMPLE_RATE is set. This is intentional.
# Even though DD_TRACE_SAMPLE_RATE is treated as a global trace sampling rule, this configuration
# is deprecated. We should always encourage users to set DD_TRACE_SAMPLING_RULES instead.
log.warning(
"DD_TRACE_RATE_LIMIT is set to %s and DD_TRACE_SAMPLING_RULES is not set. "
"Tracer rate limiting is only applied to spans that match tracer sampling rules. "
Expand All @@ -388,13 +377,9 @@ def __init__(self):
)
self._trace_api = _get_config("DD_TRACE_API_VERSION")
if self._trace_api == "v0.3":
deprecate(
"DD_TRACE_API_VERSION=v0.3 is deprecated",
message="Traces will be submitted to the v0.4/traces agent endpoint instead.",
removal_version="3.0.0",
category=DDTraceDeprecationWarning,
log.error(
"Setting DD_TRACE_API_VERSION to ``v0.3`` is not supported. The default ``v0.5`` format will be used.",
)
self._trace_api = "v0.4"
self._trace_writer_buffer_size = _get_config("DD_TRACE_WRITER_BUFFER_SIZE_BYTES", DEFAULT_BUFFER_SIZE, int)
self._trace_writer_payload_size = _get_config(
"DD_TRACE_WRITER_MAX_PAYLOAD_SIZE_BYTES", DEFAULT_MAX_PAYLOAD_SIZE, int
Expand All @@ -418,18 +403,8 @@ def __init__(self):

self._span_traceback_max_size = _get_config("DD_TRACE_SPAN_TRACEBACK_MAX_SIZE", 30, int)

# 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:
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 "
"environment variables and ddtrace.config.analytics_enabled configuration. "
"These configurations will also be removed.",
category=DDTraceDeprecationWarning,
)
# DD_ANALYTICS_ENABLED is not longer supported, remove this functionatiy from all integrations in the future
self._analytics_enabled = False
self._client_ip_header = _get_config("DD_TRACE_CLIENT_IP_HEADER")
self._retrieve_client_ip = _get_config("DD_TRACE_CLIENT_IP_ENABLED", False, asbool)

Expand Down Expand Up @@ -477,14 +452,6 @@ def __init__(self):
self._128_bit_trace_id_enabled = _get_config("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", True, asbool)

self._128_bit_trace_id_logging_enabled = _get_config("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", False, asbool)
if self._128_bit_trace_id_logging_enabled:
deprecate(
"Using DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is deprecated.",
message="Log injection format is now configured automatically.",
removal_version="3.0.0",
category=DDTraceDeprecationWarning,
)

self._sampling_rules = _get_config("DD_SPAN_SAMPLING_RULES")
self._sampling_rules_file = _get_config("DD_SPAN_SAMPLING_RULES_FILE")

Expand Down Expand Up @@ -536,18 +503,7 @@ def __init__(self):
["DD_TRACE_COMPUTE_STATS", "DD_TRACE_STATS_COMPUTATION_ENABLED"], trace_compute_stats_default, asbool
)
self._data_streams_enabled = _get_config("DD_DATA_STREAMS_ENABLED", False, asbool)

legacy_client_tag_enabled = _get_config("DD_HTTP_CLIENT_TAG_QUERY_STRING")
if legacy_client_tag_enabled is None:
self._http_client_tag_query_string = _get_config("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", "true")
else:
deprecate(
"DD_HTTP_CLIENT_TAG_QUERY_STRING is deprecated",
message="Please use DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING instead.",
removal_version="3.0.0",
category=DDTraceDeprecationWarning,
)
self._http_client_tag_query_string = legacy_client_tag_enabled.lower()
self._http_client_tag_query_string = _get_config("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", "true")

dd_trace_obfuscation_query_string_regexp = _get_config(
"DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP", DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP_DEFAULT
Expand Down Expand Up @@ -577,15 +533,8 @@ def __init__(self):
# https://github.com/open-telemetry/opentelemetry-python/blob/v1.16.0/opentelemetry-api/src/opentelemetry/context/__init__.py#L53
os.environ["OTEL_PYTHON_CONTEXT"] = "ddcontextvars_context"
self._subscriptions = [] # type: List[Tuple[List[str], Callable[[Config, List[str]], None]]]
self._span_aggregator_rlock = _get_config("DD_TRACE_SPAN_AGGREGATOR_RLOCK", True, asbool)
if self._span_aggregator_rlock is False:
deprecate(
"DD_TRACE_SPAN_AGGREGATOR_RLOCK is deprecated",
message="Soon the ddtrace library will only support using threading.Rlock to "
"aggregate and encode span data. If you need to disable the re-entrant lock and "
"revert to using threading.Lock, please contact Datadog support.",
removal_version="3.0.0",
)
# Disabled Span Aggregator Rlock is not supported. Remove this configuration in the future
self._span_aggregator_rlock = True

self._trace_methods = _get_config("DD_TRACE_METHODS")

Expand Down
12 changes: 8 additions & 4 deletions ddtrace/settings/_otel_remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ def _remap_traces_sampler(otel_value: str) -> Optional[str]:
otel_value,
)
otel_value = f"parentbased_{otel_value}"
rate = None
if otel_value == "parentbased_always_on":
return "1.0"
rate = "1.0"
elif otel_value == "parentbased_always_off":
return "0.0"
rate = "0.0"
elif otel_value == "parentbased_traceidratio":
return os.environ.get("OTEL_TRACES_SAMPLER_ARG", "1")
rate = os.environ.get("OTEL_TRACES_SAMPLER_ARG", "1")

if rate is not None:
return f'[{{"sample_rate":{rate}}}]'
return None


Expand Down Expand Up @@ -130,7 +134,7 @@ def _remap_default(otel_value: str) -> Optional[str]:
"OTEL_SERVICE_NAME": ("DD_SERVICE", _remap_default),
"OTEL_LOG_LEVEL": ("DD_TRACE_DEBUG", _remap_otel_log_level),
"OTEL_PROPAGATORS": ("DD_TRACE_PROPAGATION_STYLE", _remap_otel_propagators),
"OTEL_TRACES_SAMPLER": ("DD_TRACE_SAMPLE_RATE", _remap_traces_sampler),
"OTEL_TRACES_SAMPLER": ("DD_TRACE_SAMPLING_RULES", _remap_traces_sampler),
"OTEL_TRACES_EXPORTER": ("DD_TRACE_ENABLED", _remap_traces_exporter),
"OTEL_METRICS_EXPORTER": ("DD_RUNTIME_METRICS_ENABLED", _remap_metrics_exporter),
"OTEL_LOGS_EXPORTER": ("", _validate_logs_exporter), # Does not set a DDTRACE environment variable.
Expand Down
11 changes: 0 additions & 11 deletions ddtrace/settings/config.py

This file was deleted.

39 changes: 4 additions & 35 deletions ddtrace/settings/integration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import os
from typing import Optional # noqa:F401
from typing import Tuple # noqa:F401

from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate

from .._hooks import Hooks
from ..internal.utils.attrdict import AttrDict
from ..internal.utils.formats import asbool
from .http import HttpConfig


Expand Down Expand Up @@ -43,9 +38,10 @@ def __init__(self, global_config, name, *args, **kwargs):
object.__setattr__(self, "hooks", Hooks())
object.__setattr__(self, "http", HttpConfig())

analytics_enabled, analytics_sample_rate = self._get_analytics_settings()
self.setdefault("analytics_enabled", analytics_enabled)
self.setdefault("analytics_sample_rate", float(analytics_sample_rate))
# Trace Analytics was removed in v3.0.0
# TODO(munir): Remove all references to analytics_enabled and analytics_sample_rate
self.setdefault("analytics_enabled", False)
self.setdefault("analytics_sample_rate", 1.0)
service = os.getenv(
"DD_%s_SERVICE" % name.upper(),
default=os.getenv(
Expand All @@ -65,33 +61,6 @@ def __init__(self, global_config, name, *args, **kwargs):
self.get_http_tag_query_string(getattr(self, "default_http_tag_query_string", None)),
)

def _get_analytics_settings(self):
# type: () -> Tuple[Optional[bool], float]
# Set default analytics configuration, default is disabled
# DEV: Default to `None` which means do not set this key
# Inject environment variables for integration
env = "DD_TRACE_%s_ANALYTICS_ENABLED" % self.integration_name.upper()
legacy_env = "DD_%s_ANALYTICS_ENABLED" % self.integration_name.upper()
analytics_enabled = asbool(os.getenv(env, os.getenv(legacy_env, default=None)))

if analytics_enabled:
deprecate(
"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 configurations will be removed in a future release.",
category=DDTraceDeprecationWarning,
)

analytics_sample_rate = float(
os.getenv(
"DD_TRACE_%s_ANALYTICS_SAMPLE_RATE" % self.integration_name.upper(),
os.getenv("DD_%s_ANALYTICS_SAMPLE_RATE" % self.integration_name.upper(), default=1.0),
)
)

return analytics_enabled, analytics_sample_rate

def get_http_tag_query_string(self, value):
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")
Expand Down
24 changes: 1 addition & 23 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
Advanced Usage
==============

.. _agentconfiguration:

Agent Configuration
-------------------

If the Datadog Agent is on a separate host from your application, you can modify
the default ``ddtrace.tracer`` object to utilize another hostname and port. Here
is a small example showcasing this::

from ddtrace.trace import tracer

tracer.configure(hostname=<YOUR_HOST>, port=<YOUR_PORT>, https=<True/False>)

By default, these will be set to ``localhost``, ``8126``, and ``False`` respectively.

You can also use a Unix Domain Socket to connect to the agent::

from ddtrace.trace import tracer

tracer.configure(uds_path="/path/to/socket")


.. _context:


Expand Down Expand Up @@ -223,7 +201,7 @@ provider can be used. It must implement the
:class:`ddtrace.trace.BaseContextProvider` interface and can be configured
with::

tracer.configure(context_provider=MyContextProvider)
tracer.configure(context_provider=MyContextProvider())


.. _disttracing:
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ Sampling
version_added:
v0.33.0:
v2.15.0: Only applied when DD_TRACE_SAMPLE_RATE, DD_TRACE_SAMPLING_RULES, or DD_SPAN_SAMPLING_RULE are set.
v3.0.0: Only applied when DD_TRACE_SAMPLING_RULES or DD_SPAN_SAMPLING_RULE are set.

DD_TRACE_SAMPLING_RULES:
type: JSON array
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
upgrade:
- |
configurations: Drops support for deprecated tracing configurations. The following configurations are no longer supported:
- DD_TRACE_SAMPLE_RATE, use DD_TRACE_SAMPLING_RULES instead.
- DD_TRACE_API_VERSION=v0.3, the default ``v0.5`` version is used instead.
- DD_ANALYTICS_ENABLED, Datadog Analytics is no longer supported.
- DD_TRACE_ANALYTICS_ENABLED, Datadog Analytics is no longer supported.
- DD_HTTP_CLIENT_TAG_QUERY_STRING, DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING should be used instead.
- DD_TRACE_SPAN_AGGREGATOR_RLOCK, disabling the span aggregator rlock is no longer supported.
3 changes: 1 addition & 2 deletions tests/appsec/iast/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ def test_appsec_iast_processor_ensure_span_is_manual_keep(iast_context_defaults,
test_appsec_iast_processor_ensure_span_is_manual_keep.
This test throws 'finished span not connected to a trace' log error
"""
with override_env(dict(DD_TRACE_SAMPLE_RATE=sampling_rate)):
with override_env({"DD_TRACE_SAMPLING_RULES": '[{"sample_rate":%s]"}]' % (sampling_rate,)}):
oce.reconfigure()
tracer = DummyTracer(iast_enabled=True)

span = traced_function(tracer)
tracer._on_span_finish(span)

result = span.get_tag(IAST.JSON)

assert len(json.loads(result)["vulnerabilities"]) == 1
assert span.get_metric(_SAMPLING_PRIORITY_KEY) is USER_KEEP

Expand Down
Loading

0 comments on commit a2b1d7b

Please sign in to comment.