From 63d13ab421562046fec2c3cfc46dfd229de6ea97 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Tue, 4 Feb 2025 01:22:48 -0500 Subject: [PATCH] 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) --- benchmarks/sampling_rule_matches/scenario.py | 2 +- ddtrace/__init__.py | 42 ++-------- ddtrace/constants.py | 79 +++++-------------- ddtrace/context.py | 10 --- ddtrace/filters.py | 10 --- ddtrace/pin.py | 10 --- ddtrace/provider.py | 14 ---- ddtrace/sampler.py | 10 --- ddtrace/sampling_rule.py | 10 --- ddtrace/span.py | 10 --- ddtrace/tracer.py | 10 --- ddtrace/tracing/__init__.py | 11 --- ...ated-tracing-modules-a129231d42e1218d.yaml | 4 + tests/internal/test_settings.py | 25 ++++++ tests/llmobs/test_llmobs_ragas_evaluators.py | 2 +- tests/suitespec.yml | 9 --- tests/tracer/test_tracer.py | 15 ---- 17 files changed, 57 insertions(+), 216 deletions(-) delete mode 100644 ddtrace/context.py delete mode 100644 ddtrace/filters.py delete mode 100644 ddtrace/pin.py delete mode 100644 ddtrace/provider.py delete mode 100644 ddtrace/sampler.py delete mode 100644 ddtrace/sampling_rule.py delete mode 100644 ddtrace/span.py delete mode 100644 ddtrace/tracer.py delete mode 100644 ddtrace/tracing/__init__.py create mode 100644 releasenotes/notes/remove-deprecated-tracing-modules-a129231d42e1218d.yaml diff --git a/benchmarks/sampling_rule_matches/scenario.py b/benchmarks/sampling_rule_matches/scenario.py index 70ee5111bf8..d77926f5d65 100644 --- a/benchmarks/sampling_rule_matches/scenario.py +++ b/benchmarks/sampling_rule_matches/scenario.py @@ -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): diff --git a/ddtrace/__init__.py b/ddtrace/__init__.py index e480851926f..008e931a482 100644 --- a/ddtrace/__init__.py +++ b/ddtrace/__init__.py @@ -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 @@ -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 @@ -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 = ( diff --git a/ddtrace/constants.py b/ddtrace/constants.py index b4694e24345..829a57a45a7 100644 --- a/ddtrace/constants.py +++ b/ddtrace/constants.py @@ -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" @@ -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) diff --git a/ddtrace/context.py b/ddtrace/context.py deleted file mode 100644 index 843ef510c38..00000000000 --- a/ddtrace/context.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.trace import Context # noqa: F401 -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.context module is deprecated and will be removed from the public API.", - message="Context should be imported from the ddtrace.trace package", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/filters.py b/ddtrace/filters.py deleted file mode 100644 index bd6367d5635..00000000000 --- a/ddtrace/filters.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace._trace.filters import * # noqa: F403 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.filters module and the ``FilterRequestsOnUrl`` class is deprecated and will be removed.", - message="Import ``TraceFilter`` from the ddtrace.trace package.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/pin.py b/ddtrace/pin.py deleted file mode 100644 index 0e683b3b22e..00000000000 --- a/ddtrace/pin.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace._trace.pin import * # noqa: F403 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.trace.Pin module is deprecated and will be removed.", - message="Import ``Pin`` from the ddtrace.trace package.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/provider.py b/ddtrace/provider.py deleted file mode 100644 index 7b9867de01a..00000000000 --- a/ddtrace/provider.py +++ /dev/null @@ -1,14 +0,0 @@ -from ddtrace._trace.provider import BaseContextProvider # noqa: F401 -from ddtrace._trace.provider import DatadogContextMixin # noqa: F401 -from ddtrace._trace.provider import DefaultContextProvider # noqa: F401 -from ddtrace.internal.ci_visibility.context import CIContextProvider # noqa: F401 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The context provider interface is deprecated", - message="Import BaseContextProvider from `ddtrace.trace` instead.", - category=DDTraceDeprecationWarning, - removal_version="3.0.0", -) diff --git a/ddtrace/sampler.py b/ddtrace/sampler.py deleted file mode 100644 index c7f4b9d499a..00000000000 --- a/ddtrace/sampler.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace._trace.sampler import * # noqa: F403 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.sampler module is deprecated and will be removed.", - message="Use DD_TRACE_SAMPLING_RULES to configure sampling rates.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/sampling_rule.py b/ddtrace/sampling_rule.py deleted file mode 100644 index 244cebddd31..00000000000 --- a/ddtrace/sampling_rule.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace._trace.sampling_rule import * # noqa: F403 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.sample_rule module is deprecated and will be removed.", - message="Use DD_TRACE_SAMPLING_RULES to set sampling rules.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/span.py b/ddtrace/span.py deleted file mode 100644 index 48f1835262c..00000000000 --- a/ddtrace/span.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.trace import Span # noqa: F401 -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The span module is deprecated and will be moved.", - message="A new span interface will be provided by the trace sub-package.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/tracer.py b/ddtrace/tracer.py deleted file mode 100644 index afb4e05492d..00000000000 --- a/ddtrace/tracer.py +++ /dev/null @@ -1,10 +0,0 @@ -from ddtrace._trace.tracer import Tracer # noqa: F401 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The ddtrace.tracer module is deprecated and will be removed.", - message="A new interface will be provided by the trace sub-package.", - category=DDTraceDeprecationWarning, -) diff --git a/ddtrace/tracing/__init__.py b/ddtrace/tracing/__init__.py deleted file mode 100644 index c66bb230093..00000000000 --- a/ddtrace/tracing/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -from ddtrace._trace import trace_handlers # noqa: F401 -from ddtrace._trace._span_link import SpanLink # noqa: F401 -from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning -from ddtrace.vendor.debtcollector import deprecate - - -deprecate( - "The tracing module is deprecated and will be moved.", - message="A new interface will be provided by the _trace sub-package.", - category=DDTraceDeprecationWarning, -) diff --git a/releasenotes/notes/remove-deprecated-tracing-modules-a129231d42e1218d.yaml b/releasenotes/notes/remove-deprecated-tracing-modules-a129231d42e1218d.yaml new file mode 100644 index 00000000000..575bb8f1e55 --- /dev/null +++ b/releasenotes/notes/remove-deprecated-tracing-modules-a129231d42e1218d.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + tracing: Removes the deprecated tracing modules and constants from the ``ddtrace`` package. diff --git a/tests/internal/test_settings.py b/tests/internal/test_settings.py index a3f5fa97802..2ff1843690e 100644 --- a/tests/internal/test_settings.py +++ b/tests/internal/test_settings.py @@ -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 diff --git a/tests/llmobs/test_llmobs_ragas_evaluators.py b/tests/llmobs/test_llmobs_ragas_evaluators.py index c46dce740c2..a182653455a 100644 --- a/tests/llmobs/test_llmobs_ragas_evaluators.py +++ b/tests/llmobs/test_llmobs_ragas_evaluators.py @@ -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 diff --git a/tests/suitespec.yml b/tests/suitespec.yml index b135ba986c8..d9da18df66d 100644 --- a/tests/suitespec.yml +++ b/tests/suitespec.yml @@ -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 diff --git a/tests/tracer/test_tracer.py b/tests/tracer/test_tracer.py index 0a75e5fc037..1aa1c42bf1d 100644 --- a/tests/tracer/test_tracer.py +++ b/tests/tracer/test_tracer.py @@ -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])