Skip to content

Commit 63d13ab

Browse files
authored
chore(tracing): remove deprecated modules [3.0] (#12186)
- Removes all tracing modules and packages that are not defined in ddtrace._trace, ddtrace.internal, or ddtrace.trace. - Removes deprecated tracing attributes from ddtrace. ddtrace.trace should be the sole public interface for tracing. ## 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)
1 parent e294f47 commit 63d13ab

File tree

17 files changed

+57
-216
lines changed

17 files changed

+57
-216
lines changed

benchmarks/sampling_rule_matches/scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import bm
66

7+
from ddtrace._trace.sampling_rule import SamplingRule
78
from ddtrace._trace.span import Span
8-
from ddtrace.sampling_rule import SamplingRule
99

1010

1111
def rands(size=6, chars=string.ascii_uppercase + string.digits):

ddtrace/__init__.py

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
from ._monkey import patch_all # noqa: E402
2828
from .internal.compat import PYTHON_VERSION_INFO # noqa: E402
2929
from .internal.utils.deprecations import DDTraceDeprecationWarning # noqa: E402
30-
from ddtrace._trace.pin import Pin # noqa: E402
31-
from ddtrace._trace.span import Span # noqa: E402
32-
from ddtrace._trace.tracer import Tracer # noqa: E402
30+
31+
# TODO(munir): Remove the imports below in v3.0
32+
from ddtrace._trace import pin as _p # noqa: E402, F401
33+
from ddtrace._trace import span as _s # noqa: E402, F401
34+
from ddtrace._trace import tracer as _t # noqa: E402, F401
3335
from ddtrace.vendor import debtcollector
3436
from .version import get_version # noqa: E402
3537

@@ -39,15 +41,6 @@
3941

4042
_start_mini_agent()
4143

42-
# DEV: Import deprecated tracer module in order to retain side-effect of package
43-
# initialization, which added this module to sys.modules. We catch deprecation
44-
# warnings as this is only to retain a side effect of the package
45-
# initialization.
46-
# TODO: Remove this in v3.0 when the ddtrace/tracer.py module is removed
47-
with warnings.catch_warnings():
48-
warnings.simplefilter("ignore")
49-
from .tracer import Tracer as _
50-
5144
__version__ = get_version()
5245

5346
# TODO: Deprecate accessing tracer from ddtrace.__init__ module in v4.0
@@ -57,36 +50,11 @@
5750
__all__ = [
5851
"patch",
5952
"patch_all",
60-
"Pin",
61-
"Span",
62-
"Tracer",
6353
"config",
6454
"DDTraceDeprecationWarning",
6555
]
6656

6757

68-
_DEPRECATED_TRACE_ATTRIBUTES = [
69-
"Span",
70-
"Tracer",
71-
"Pin",
72-
]
73-
74-
75-
def __getattr__(name):
76-
if name in _DEPRECATED_TRACE_ATTRIBUTES:
77-
debtcollector.deprecate(
78-
("%s.%s is deprecated" % (__name__, name)),
79-
message="Import from ddtrace.trace instead.",
80-
category=DDTraceDeprecationWarning,
81-
removal_version="3.0.0",
82-
)
83-
84-
if name in globals():
85-
return globals()[name]
86-
87-
raise AttributeError("%s has no attribute %s", __name__, name)
88-
89-
9058
def check_supported_python_version():
9159
if PYTHON_VERSION_INFO < (3, 8):
9260
deprecation_message = (

ddtrace/constants.py

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning as _DDTraceDeprecationWarning
2-
from ddtrace.vendor import debtcollector as _debtcollector
3-
4-
5-
# TODO: Deprecate and remove the SAMPLE_RATE_METRIC_KEY constant.
6-
# This key enables legacy trace sampling support in the Datadog agent.
7-
_SAMPLE_RATE_METRIC_KEY = SAMPLE_RATE_METRIC_KEY = "_sample_rate"
8-
_SAMPLING_PRIORITY_KEY = SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
9-
_ANALYTICS_SAMPLE_RATE_KEY = ANALYTICS_SAMPLE_RATE_KEY = "_dd1.sr.eausr"
10-
_SAMPLING_AGENT_DECISION = SAMPLING_AGENT_DECISION = "_dd.agent_psr"
11-
_SAMPLING_RULE_DECISION = SAMPLING_RULE_DECISION = "_dd.rule_psr"
12-
_SAMPLING_LIMIT_DECISION = SAMPLING_LIMIT_DECISION = "_dd.limit_psr"
1+
"""
2+
This module contains constants used across ddtrace products.
3+
4+
Constants that should NOT be referenced by ddtrace users are marked with a leading underscore.
5+
"""
6+
_SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
7+
_ANALYTICS_SAMPLE_RATE_KEY = "_dd1.sr.eausr"
8+
_SAMPLING_AGENT_DECISION = "_dd.agent_psr"
9+
_SAMPLING_RULE_DECISION = "_dd.rule_psr"
10+
_SAMPLING_LIMIT_DECISION = "_dd.limit_psr"
1311
_SINGLE_SPAN_SAMPLING_MECHANISM = "_dd.span_sampling.mechanism"
1412
_SINGLE_SPAN_SAMPLING_RATE = "_dd.span_sampling.rule_rate"
1513
_SINGLE_SPAN_SAMPLING_MAX_PER_SEC = "_dd.span_sampling.max_per_second"
1614
_SINGLE_SPAN_SAMPLING_MAX_PER_SEC_NO_LIMIT = -1
1715
_APM_ENABLED_METRIC_KEY = "_dd.apm.enabled"
1816

19-
_ORIGIN_KEY = ORIGIN_KEY = "_dd.origin"
20-
_USER_ID_KEY = USER_ID_KEY = "_dd.p.usr.id"
21-
_HOSTNAME_KEY = HOSTNAME_KEY = "_dd.hostname"
22-
_RUNTIME_FAMILY = RUNTIME_FAMILY = "_dd.runtime_family"
17+
_ORIGIN_KEY = "_dd.origin"
18+
_USER_ID_KEY = "_dd.p.usr.id"
19+
_HOSTNAME_KEY = "_dd.hostname"
20+
_RUNTIME_FAMILY = "_dd.runtime_family"
2321
ENV_KEY = "env"
2422
VERSION_KEY = "version"
2523
SERVICE_KEY = "service.name"
26-
_BASE_SERVICE_KEY = BASE_SERVICE_KEY = "_dd.base_service"
24+
_BASE_SERVICE_KEY = "_dd.base_service"
2725
SERVICE_VERSION_KEY = "service.version"
2826
SPAN_KIND = "span.kind"
29-
_SPAN_MEASURED_KEY = SPAN_MEASURED_KEY = "_dd.measured"
30-
_KEEP_SPANS_RATE_KEY = KEEP_SPANS_RATE_KEY = "_dd.tracer_kr"
31-
_MULTIPLE_IP_HEADERS = MULTIPLE_IP_HEADERS = "_dd.multiple-ip-headers"
27+
_SPAN_MEASURED_KEY = "_dd.measured"
28+
_KEEP_SPANS_RATE_KEY = "_dd.tracer_kr"
29+
_MULTIPLE_IP_HEADERS = "_dd.multiple-ip-headers"
3230

3331
APPSEC_ENV = "DD_APPSEC_ENABLED"
34-
_CONFIG_ENDPOINT_ENV = CONFIG_ENDPOINT_ENV = "_DD_CONFIG_ENDPOINT"
35-
_CONFIG_ENDPOINT_RETRIES_ENV = CONFIG_ENDPOINT_RETRIES_ENV = "_DD_CONFIG_ENDPOINT_RETRIES"
36-
_CONFIG_ENDPOINT_TIMEOUT_ENV = CONFIG_ENDPOINT_TIMEOUT_ENV = "_DD_CONFIG_ENDPOINT_TIMEOUT"
32+
_CONFIG_ENDPOINT_ENV = "_DD_CONFIG_ENDPOINT"
33+
_CONFIG_ENDPOINT_RETRIES_ENV = "_DD_CONFIG_ENDPOINT_RETRIES"
34+
_CONFIG_ENDPOINT_TIMEOUT_ENV = "_DD_CONFIG_ENDPOINT_TIMEOUT"
3735
IAST_ENV = "DD_IAST_ENABLED"
3836

3937
MANUAL_DROP_KEY = "manual.drop"
@@ -53,38 +51,3 @@
5351
AUTO_KEEP = 1
5452
# Use this to explicitly inform the backend that a trace should be kept and stored.
5553
USER_KEEP = 2
56-
57-
58-
_DEPRECATED_MODULE_ATTRIBUTES = [
59-
"ANALYTICS_SAMPLE_RATE_KEY",
60-
"SAMPLE_RATE_METRIC_KEY",
61-
"SAMPLING_PRIORITY_KEY",
62-
"SAMPLING_AGENT_DECISION",
63-
"SAMPLING_RULE_DECISION",
64-
"SAMPLING_LIMIT_DECISION",
65-
"USER_ID_KEY",
66-
"ORIGIN_KEY",
67-
"HOSTNAME_KEY",
68-
"RUNTIME_FAMILY",
69-
"BASE_SERVICE_KEY",
70-
"SPAN_MEASURED_KEY",
71-
"KEEP_SPANS_RATE_KEY",
72-
"MULTIPLE_IP_HEADERS",
73-
"CONFIG_ENDPOINT_ENV",
74-
"CONFIG_ENDPOINT_RETRIES_ENV",
75-
"CONFIG_ENDPOINT_TIMEOUT_ENV",
76-
]
77-
78-
79-
def __getattr__(name):
80-
if name in _DEPRECATED_MODULE_ATTRIBUTES:
81-
_debtcollector.deprecate(
82-
("%s.%s is deprecated" % (__name__, name)),
83-
category=_DDTraceDeprecationWarning,
84-
removal_version="3.0.0",
85-
)
86-
87-
if name in globals():
88-
return globals()[name]
89-
90-
raise AttributeError("%s has no attribute %s", __name__, name)

ddtrace/context.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/filters.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/pin.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/provider.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

ddtrace/sampler.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/sampling_rule.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/span.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/tracer.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

ddtrace/tracing/__init__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
other:
3+
- |
4+
tracing: Removes the deprecated tracing modules and constants from the ``ddtrace`` package.

tests/internal/test_settings.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,28 @@ def test_remoteconfig_header_tags(run_python_code_in_subprocess):
615615
env=env,
616616
)
617617
assert status == 0, f"err={err.decode('utf-8')} out={out.decode('utf-8')}"
618+
619+
620+
def test_config_public_properties_and_methods():
621+
# Regression test to prevent unexpected changes to public attributes in Config
622+
# By default most attributes should be private and set via Environment Variables
623+
from ddtrace.settings import Config
624+
625+
public_attrs = set()
626+
c = Config()
627+
# Check for public attributes in Config
628+
for attr in dir(c):
629+
if not attr.startswith("_") and not attr.startswith("__"):
630+
public_attrs.add(attr)
631+
# Check for public keys in Config._config
632+
for key in c._config:
633+
if not key.startswith("_"):
634+
public_attrs.add(key)
635+
636+
assert public_attrs == {
637+
"service",
638+
"service_mapping",
639+
"env",
640+
"tags",
641+
"version",
642+
}, public_attrs

tests/llmobs/test_llmobs_ragas_evaluators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ddtrace.llmobs._evaluators.ragas.context_precision import RagasContextPrecisionEvaluator
88
from ddtrace.llmobs._evaluators.ragas.faithfulness import RagasFaithfulnessEvaluator
99
from ddtrace.llmobs._evaluators.runner import EvaluatorRunner
10-
from ddtrace.span import Span
10+
from ddtrace.trace import Span
1111
from tests.llmobs._utils import _expected_llmobs_llm_span_event
1212
from tests.llmobs._utils import _expected_ragas_answer_relevancy_spans
1313
from tests.llmobs._utils import _expected_ragas_context_precision_spans

tests/suitespec.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ components:
116116
- ddtrace/_trace/*
117117
- ddtrace/trace/*
118118
- ddtrace/constants.py
119-
- ddtrace/context.py
120-
- ddtrace/filters.py
121-
- ddtrace/pin.py
122-
- ddtrace/provider.py
123-
- ddtrace/sampler.py
124-
- ddtrace/sampling_rule.py
125-
- ddtrace/span.py
126-
- ddtrace/tracer.py
127-
- ddtrace/tracing/*
128119
- ddtrace/settings/__init__.py
129120
- ddtrace/settings/config.py
130121
- ddtrace/settings/http.py

tests/tracer/test_tracer.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,21 +2010,6 @@ def test_ctx_api():
20102010
assert core.get_items(["appsec.key"]) == [None]
20112011

20122012

2013-
@pytest.mark.subprocess(parametrize={"IMPORT_DDTRACE_TRACER": ["true", "false"]})
2014-
def test_import_ddtrace_tracer_not_module():
2015-
import os
2016-
2017-
import_ddtrace_tracer = os.environ["IMPORT_DDTRACE_TRACER"] == "true"
2018-
2019-
if import_ddtrace_tracer:
2020-
import ddtrace.tracer # noqa: F401
2021-
2022-
from ddtrace.trace import Tracer
2023-
from ddtrace.trace import tracer
2024-
2025-
assert isinstance(tracer, Tracer)
2026-
2027-
20282013
@pytest.mark.parametrize("sca_enabled", ["true", "false"])
20292014
@pytest.mark.parametrize("appsec_enabled", [True, False])
20302015
@pytest.mark.parametrize("iast_enabled", [True, False])

0 commit comments

Comments
 (0)