Skip to content

Commit

Permalink
chore(tracing): remove deprecated modules [3.0] (#12186)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
mabdinur authored Feb 4, 2025
1 parent e294f47 commit 63d13ab
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 216 deletions.
2 changes: 1 addition & 1 deletion benchmarks/sampling_rule_matches/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import bm

from ddtrace._trace.sampling_rule import SamplingRule
from ddtrace._trace.span import Span
from ddtrace.sampling_rule import SamplingRule


def rands(size=6, chars=string.ascii_uppercase + string.digits):
Expand Down
42 changes: 5 additions & 37 deletions ddtrace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
from ._monkey import patch_all # noqa: E402
from .internal.compat import PYTHON_VERSION_INFO # noqa: E402
from .internal.utils.deprecations import DDTraceDeprecationWarning # noqa: E402
from ddtrace._trace.pin import Pin # noqa: E402
from ddtrace._trace.span import Span # noqa: E402
from ddtrace._trace.tracer import Tracer # noqa: E402

# TODO(munir): Remove the imports below in v3.0
from ddtrace._trace import pin as _p # noqa: E402, F401
from ddtrace._trace import span as _s # noqa: E402, F401
from ddtrace._trace import tracer as _t # noqa: E402, F401
from ddtrace.vendor import debtcollector
from .version import get_version # noqa: E402

Expand All @@ -39,15 +41,6 @@

_start_mini_agent()

# DEV: Import deprecated tracer module in order to retain side-effect of package
# initialization, which added this module to sys.modules. We catch deprecation
# warnings as this is only to retain a side effect of the package
# initialization.
# TODO: Remove this in v3.0 when the ddtrace/tracer.py module is removed
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from .tracer import Tracer as _

__version__ = get_version()

# TODO: Deprecate accessing tracer from ddtrace.__init__ module in v4.0
Expand All @@ -57,36 +50,11 @@
__all__ = [
"patch",
"patch_all",
"Pin",
"Span",
"Tracer",
"config",
"DDTraceDeprecationWarning",
]


_DEPRECATED_TRACE_ATTRIBUTES = [
"Span",
"Tracer",
"Pin",
]


def __getattr__(name):
if name in _DEPRECATED_TRACE_ATTRIBUTES:
debtcollector.deprecate(
("%s.%s is deprecated" % (__name__, name)),
message="Import from ddtrace.trace instead.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)

if name in globals():
return globals()[name]

raise AttributeError("%s has no attribute %s", __name__, name)


def check_supported_python_version():
if PYTHON_VERSION_INFO < (3, 8):
deprecation_message = (
Expand Down
79 changes: 21 additions & 58 deletions ddtrace/constants.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning as _DDTraceDeprecationWarning
from ddtrace.vendor import debtcollector as _debtcollector


# TODO: Deprecate and remove the SAMPLE_RATE_METRIC_KEY constant.
# This key enables legacy trace sampling support in the Datadog agent.
_SAMPLE_RATE_METRIC_KEY = SAMPLE_RATE_METRIC_KEY = "_sample_rate"
_SAMPLING_PRIORITY_KEY = SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
_ANALYTICS_SAMPLE_RATE_KEY = ANALYTICS_SAMPLE_RATE_KEY = "_dd1.sr.eausr"
_SAMPLING_AGENT_DECISION = SAMPLING_AGENT_DECISION = "_dd.agent_psr"
_SAMPLING_RULE_DECISION = SAMPLING_RULE_DECISION = "_dd.rule_psr"
_SAMPLING_LIMIT_DECISION = SAMPLING_LIMIT_DECISION = "_dd.limit_psr"
"""
This module contains constants used across ddtrace products.
Constants that should NOT be referenced by ddtrace users are marked with a leading underscore.
"""
_SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
_ANALYTICS_SAMPLE_RATE_KEY = "_dd1.sr.eausr"
_SAMPLING_AGENT_DECISION = "_dd.agent_psr"
_SAMPLING_RULE_DECISION = "_dd.rule_psr"
_SAMPLING_LIMIT_DECISION = "_dd.limit_psr"
_SINGLE_SPAN_SAMPLING_MECHANISM = "_dd.span_sampling.mechanism"
_SINGLE_SPAN_SAMPLING_RATE = "_dd.span_sampling.rule_rate"
_SINGLE_SPAN_SAMPLING_MAX_PER_SEC = "_dd.span_sampling.max_per_second"
_SINGLE_SPAN_SAMPLING_MAX_PER_SEC_NO_LIMIT = -1
_APM_ENABLED_METRIC_KEY = "_dd.apm.enabled"

_ORIGIN_KEY = ORIGIN_KEY = "_dd.origin"
_USER_ID_KEY = USER_ID_KEY = "_dd.p.usr.id"
_HOSTNAME_KEY = HOSTNAME_KEY = "_dd.hostname"
_RUNTIME_FAMILY = RUNTIME_FAMILY = "_dd.runtime_family"
_ORIGIN_KEY = "_dd.origin"
_USER_ID_KEY = "_dd.p.usr.id"
_HOSTNAME_KEY = "_dd.hostname"
_RUNTIME_FAMILY = "_dd.runtime_family"
ENV_KEY = "env"
VERSION_KEY = "version"
SERVICE_KEY = "service.name"
_BASE_SERVICE_KEY = BASE_SERVICE_KEY = "_dd.base_service"
_BASE_SERVICE_KEY = "_dd.base_service"
SERVICE_VERSION_KEY = "service.version"
SPAN_KIND = "span.kind"
_SPAN_MEASURED_KEY = SPAN_MEASURED_KEY = "_dd.measured"
_KEEP_SPANS_RATE_KEY = KEEP_SPANS_RATE_KEY = "_dd.tracer_kr"
_MULTIPLE_IP_HEADERS = MULTIPLE_IP_HEADERS = "_dd.multiple-ip-headers"
_SPAN_MEASURED_KEY = "_dd.measured"
_KEEP_SPANS_RATE_KEY = "_dd.tracer_kr"
_MULTIPLE_IP_HEADERS = "_dd.multiple-ip-headers"

APPSEC_ENV = "DD_APPSEC_ENABLED"
_CONFIG_ENDPOINT_ENV = CONFIG_ENDPOINT_ENV = "_DD_CONFIG_ENDPOINT"
_CONFIG_ENDPOINT_RETRIES_ENV = CONFIG_ENDPOINT_RETRIES_ENV = "_DD_CONFIG_ENDPOINT_RETRIES"
_CONFIG_ENDPOINT_TIMEOUT_ENV = CONFIG_ENDPOINT_TIMEOUT_ENV = "_DD_CONFIG_ENDPOINT_TIMEOUT"
_CONFIG_ENDPOINT_ENV = "_DD_CONFIG_ENDPOINT"
_CONFIG_ENDPOINT_RETRIES_ENV = "_DD_CONFIG_ENDPOINT_RETRIES"
_CONFIG_ENDPOINT_TIMEOUT_ENV = "_DD_CONFIG_ENDPOINT_TIMEOUT"
IAST_ENV = "DD_IAST_ENABLED"

MANUAL_DROP_KEY = "manual.drop"
Expand All @@ -53,38 +51,3 @@
AUTO_KEEP = 1
# Use this to explicitly inform the backend that a trace should be kept and stored.
USER_KEEP = 2


_DEPRECATED_MODULE_ATTRIBUTES = [
"ANALYTICS_SAMPLE_RATE_KEY",
"SAMPLE_RATE_METRIC_KEY",
"SAMPLING_PRIORITY_KEY",
"SAMPLING_AGENT_DECISION",
"SAMPLING_RULE_DECISION",
"SAMPLING_LIMIT_DECISION",
"USER_ID_KEY",
"ORIGIN_KEY",
"HOSTNAME_KEY",
"RUNTIME_FAMILY",
"BASE_SERVICE_KEY",
"SPAN_MEASURED_KEY",
"KEEP_SPANS_RATE_KEY",
"MULTIPLE_IP_HEADERS",
"CONFIG_ENDPOINT_ENV",
"CONFIG_ENDPOINT_RETRIES_ENV",
"CONFIG_ENDPOINT_TIMEOUT_ENV",
]


def __getattr__(name):
if name in _DEPRECATED_MODULE_ATTRIBUTES:
_debtcollector.deprecate(
("%s.%s is deprecated" % (__name__, name)),
category=_DDTraceDeprecationWarning,
removal_version="3.0.0",
)

if name in globals():
return globals()[name]

raise AttributeError("%s has no attribute %s", __name__, name)
10 changes: 0 additions & 10 deletions ddtrace/context.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/filters.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/pin.py

This file was deleted.

14 changes: 0 additions & 14 deletions ddtrace/provider.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/sampler.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/sampling_rule.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/span.py

This file was deleted.

10 changes: 0 additions & 10 deletions ddtrace/tracer.py

This file was deleted.

11 changes: 0 additions & 11 deletions ddtrace/tracing/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
other:
- |
tracing: Removes the deprecated tracing modules and constants from the ``ddtrace`` package.
25 changes: 25 additions & 0 deletions tests/internal/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,28 @@ 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 == {
"service",
"service_mapping",
"env",
"tags",
"version",
}, public_attrs
2 changes: 1 addition & 1 deletion tests/llmobs/test_llmobs_ragas_evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ddtrace.llmobs._evaluators.ragas.context_precision import RagasContextPrecisionEvaluator
from ddtrace.llmobs._evaluators.ragas.faithfulness import RagasFaithfulnessEvaluator
from ddtrace.llmobs._evaluators.runner import EvaluatorRunner
from ddtrace.span import Span
from ddtrace.trace import Span
from tests.llmobs._utils import _expected_llmobs_llm_span_event
from tests.llmobs._utils import _expected_ragas_answer_relevancy_spans
from tests.llmobs._utils import _expected_ragas_context_precision_spans
Expand Down
9 changes: 0 additions & 9 deletions tests/suitespec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ components:
- ddtrace/_trace/*
- ddtrace/trace/*
- ddtrace/constants.py
- ddtrace/context.py
- ddtrace/filters.py
- ddtrace/pin.py
- ddtrace/provider.py
- ddtrace/sampler.py
- ddtrace/sampling_rule.py
- ddtrace/span.py
- ddtrace/tracer.py
- ddtrace/tracing/*
- ddtrace/settings/__init__.py
- ddtrace/settings/config.py
- ddtrace/settings/http.py
Expand Down
15 changes: 0 additions & 15 deletions tests/tracer/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,21 +2010,6 @@ def test_ctx_api():
assert core.get_items(["appsec.key"]) == [None]


@pytest.mark.subprocess(parametrize={"IMPORT_DDTRACE_TRACER": ["true", "false"]})
def test_import_ddtrace_tracer_not_module():
import os

import_ddtrace_tracer = os.environ["IMPORT_DDTRACE_TRACER"] == "true"

if import_ddtrace_tracer:
import ddtrace.tracer # noqa: F401

from ddtrace.trace import Tracer
from ddtrace.trace import tracer

assert isinstance(tracer, Tracer)


@pytest.mark.parametrize("sca_enabled", ["true", "false"])
@pytest.mark.parametrize("appsec_enabled", [True, False])
@pytest.mark.parametrize("iast_enabled", [True, False])
Expand Down

0 comments on commit 63d13ab

Please sign in to comment.