Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(configurations): remove deprecated tracing env vars #12176

Open
wants to merge 8 commits into
base: 3.x-staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 12 additions & 60 deletions ddtrace/settings/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,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 @@ -388,14 +390,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 @@ -404,9 +398,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 @@ -424,13 +415,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 @@ -454,18 +441,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the changes above, should we log that analytics_enabled is not supported?

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 @@ -512,15 +489,8 @@ 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,
)

# Disabling DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is not supported. Remove this configuration in the future.
self._128_bit_trace_id_logging_enabled = True
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @mtoffl01

Not sure if we should pull this out into it's own PR. DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED configuration is being removed so we need to enable this functionality by default.

Maybe this could use it's own release note.

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

Expand Down Expand Up @@ -572,18 +542,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 @@ -613,15 +572,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 @@ -70,12 +70,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 @@ -148,7 +152,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
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,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.
v2.15.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,11 @@
---
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_TRACE_128_BIT_TRACEID_LOGGING_ENABLED, this configuration can not be disabled.
- 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.
2 changes: 1 addition & 1 deletion tests/appsec/iast/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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": f'[{"sample_rate":{sampling_rate}}]'}):
oce.reconfigure()
tracer = DummyTracer(iast_enabled=True)

Expand Down
54 changes: 34 additions & 20 deletions tests/integration/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_setting_origin_environment(test_agent_session, run_python_code_in_subpr
env = os.environ.copy()
env.update(
{
"DD_TRACE_SAMPLE_RATE": "0.1",
"DD_TRACE_SAMPLING_RULES": '[{"sample_rate":0.1}]',
"DD_LOGS_INJECTION": "true",
"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1:header_tag_1,X-Header-Tag-2:header_tag_2",
"DD_TAGS": "team:apm,component:web",
Expand All @@ -39,11 +39,11 @@ def test_setting_origin_environment(test_agent_session, run_python_code_in_subpr
assert status == 0, err

events = test_agent_session.get_events(subprocess=True)
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLE_RATE")
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLING_RULES")

assert {
"name": "DD_TRACE_SAMPLE_RATE",
"value": 0.1,
"name": "DD_TRACE_SAMPLING_RULES",
"value": '[{"sample_rate":0.1}]',
"origin": "env_var",
} in events_trace_sample_rate

Expand All @@ -69,7 +69,6 @@ def test_setting_origin_code(test_agent_session, run_python_code_in_subprocess):
env = os.environ.copy()
env.update(
{
"DD_TRACE_SAMPLE_RATE": "0.1",
"DD_LOGS_INJECTION": "true",
"DD_TRACE_HEADER_TAGS": "X-Header-Tag-1:header_tag_1,X-Header-Tag-2:header_tag_2",
"DD_TAGS": "team:apm,component:web",
Expand All @@ -81,7 +80,6 @@ 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.tags = {"header": "value"}
Expand All @@ -96,12 +94,6 @@ def test_setting_origin_code(test_agent_session, run_python_code_in_subprocess):
assert status == 0, err

events = test_agent_session.get_events(subprocess=True)
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLE_RATE")
assert {
"name": "DD_TRACE_SAMPLE_RATE",
"value": 0.2,
"origin": "code",
} in events_trace_sample_rate

events_logs_injection_enabled = _get_telemetry_config_items(events, "DD_LOGS_INJECTION")
assert {
Expand Down Expand Up @@ -174,8 +166,8 @@ def test_remoteconfig_sampling_rate_default(test_agent_session, run_python_code_
assert status == 0, err

events = test_agent_session.get_events(subprocess=True)
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLE_RATE")
assert {"name": "DD_TRACE_SAMPLE_RATE", "value": 1.0, "origin": "default"} in events_trace_sample_rate
events_trace_sample_rate = _get_telemetry_config_items(events, "trace_sample_rate")
assert {"name": "trace_sample_rate", "value": 1.0, "origin": "default"} in events_trace_sample_rate


@pytest.mark.skipif(AGENT_VERSION != "testagent", reason="Tests only compatible with a testagent")
Expand All @@ -191,7 +183,22 @@ def test_remoteconfig_sampling_rate_telemetry(test_agent_session, run_python_cod
from ddtrace import config, tracer
from tests.internal.test_settings import _base_rc_config

config._handle_remoteconfig(_base_rc_config({"tracing_sampling_rate": 0.5}))
config._handle_remoteconfig(
_base_rc_config(
{
"tracing_sampling_rules": [
{
"sample_rate": "0.5",
"service": "*",
"name": "*",
"resource": "*",
"tags": {},
"provenance": "customer",
}
]
}
)
)
with tracer.trace("test") as span:
pass
assert span.get_metric("_dd.rule_psr") == 0.5
Expand All @@ -201,8 +208,13 @@ def test_remoteconfig_sampling_rate_telemetry(test_agent_session, run_python_cod
assert status == 0, err

events = test_agent_session.get_events(subprocess=True)
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLE_RATE")
assert {"name": "DD_TRACE_SAMPLE_RATE", "value": 0.5, "origin": "remote_config"} in events_trace_sample_rate
events_trace_sample_rate = _get_telemetry_config_items(events, "DD_TRACE_SAMPLING_RULES")
assert {
"name": "DD_TRACE_SAMPLING_RULES",
"origin": "remote_config",
"value": '[{"sample_rate": "0.5", "service": "*", "name": "*", "resource": "*", '
'"tags": {}, "provenance": "customer"}]',
} in events_trace_sample_rate


@pytest.mark.skipif(AGENT_VERSION != "testagent", reason="Tests only compatible with a testagent")
Expand All @@ -226,9 +238,11 @@ def test_remoteconfig_header_tags_telemetry(test_agent_session, run_python_code_
{"header": "used-with-default", "tag_name":""}]
}))
with tracer.trace("test") as span:
trace_utils.set_http_meta(span,
config.falcon, # randomly chosen http integration config
request_headers={"used": "foobarbanana", "used-with-default": "defaultname"})
trace_utils.set_http_meta(
span,
config.falcon, # randomly chosen http integration config
request_headers={"used": "foobarbanana", "used-with-default": "defaultname"},
)
assert span.get_tag("header_tag_69") == "foobarbanana"
assert span.get_tag("header_tag_70") is None
assert span.get_tag("http.request.headers.used-with-default") == "defaultname"
Expand Down
Loading
Loading