Skip to content

chore(tracing): removes tracer._configure from products and tests #12696

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

Merged
merged 26 commits into from
Mar 25, 2025

Conversation

mabdinur
Copy link
Contributor

@mabdinur mabdinur commented Mar 11, 2025

Background

In ddtrace v3.0, most functionality previously handled by tracer.configure(...) was internalized. As a result, ddtrace >3.0 no longer provides a public API for configuring agent connections, custom samplers, UDS, or enabling tracing. To avoid refactoring all tests and products relying on tracer.configure(...), we introduced the private method tracer._configure.

This method has been used across ddtrace products (e.g., ASM, MLObs, and CiVis), integrations (e.g., Tornado, Vertex AI), and hundreds of tests. Now, it’s time to fully migrate away from this API. 🫡

Motivation

This refactor encourages the use of environment variables and/or remote configuration for setting up tracing features. Even though tracer._configure is internal, it can still be used to enable unsupported behavior. This PR aims to put an end to that. 🫡

Changes

  • Removes ddtrace.Tracer._configure from the library.
  • Updates tests requiring global tracer reconfiguration to run in a subprocess.
  • Introduces Tracer._reset.
  • Removes tests validating unsupported behavior (e.g., using tracer.configure to change the agent URL).
  • Removes tests validating unsupported behavior (e.g., using tracer.configure to change the agent URL).

Note: This PR also introduces Tracer._recreate(...), a private method used in ASM and CIVis tests to recreate the agent writer and span processors. This was added to limit the scope of changes in this PR. Ideally, tests requiring tracer reconfiguration/restart should be run in a subprocess. This is a temporary workaround (hopefully).

Follow up:

  • Deprecate tracer.configure(...).
  • Provide a public method for setting trace processors (ex: Tracer.set_processor)
  • Encourage ASM users to enable features via environment variables
  • Remove tracer.configure(...) from all tests.

Checklist

  • 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
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • 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 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

Copy link
Contributor

github-actions bot commented Mar 11, 2025

CODEOWNERS have been resolved as:

benchmarks/threading/scenario.py                                        @DataDog/apm-core-python
ddtrace/_trace/tracer.py                                                @DataDog/apm-sdk-api-python
ddtrace/appsec/_remoteconfiguration.py                                  @DataDog/asm-python
ddtrace/contrib/internal/tornado/application.py                         @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/tornado/patch.py                               @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/ci_visibility/recorder.py                              @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/writer.py                                @DataDog/ci-app-libraries
ddtrace/llmobs/_integrations/base.py                                    @DataDog/ml-observability
ddtrace/opentracer/tracer.py                                            @DataDog/apm-sdk-api-python
tests/appsec/appsec/test_asm_standalone.py                              @DataDog/asm-python
tests/appsec/appsec/test_remoteconfiguration.py                         @DataDog/asm-python
tests/appsec/appsec/test_telemetry.py                                   @DataDog/asm-python
tests/appsec/contrib_appsec/django_app/settings.py                      @DataDog/asm-python
tests/appsec/contrib_appsec/flask_app/app.py                            @DataDog/asm-python
tests/appsec/contrib_appsec/utils.py                                    @DataDog/asm-python
tests/appsec/iast/fixtures/integration/main_configure.py                @DataDog/asm-python
tests/appsec/iast/fixtures/integration/main_configure_right.py          @DataDog/asm-python
tests/appsec/iast/fixtures/integration/main_configure_wrong.py          @DataDog/asm-python
tests/appsec/integrations/django_tests/django_app/settings.py           @DataDog/asm-python
tests/appsec/integrations/django_tests/test_django_appsec.py            @DataDog/asm-python
tests/appsec/integrations/django_tests/test_django_appsec_iast.py       @DataDog/asm-python
tests/appsec/integrations/fastapi_tests/test_fastapi_appsec_iast.py     @DataDog/asm-python
tests/appsec/integrations/flask_tests/test_appsec_flask.py              @DataDog/asm-python
tests/appsec/integrations/flask_tests/test_appsec_flask_telemetry.py    @DataDog/asm-python
tests/appsec/integrations/flask_tests/test_iast_flask.py                @DataDog/asm-python
tests/appsec/utils.py                                                   @DataDog/asm-python
tests/ci_visibility/test_ci_visibility.py                               @DataDog/ci-app-libraries
tests/commands/ddtrace_run_integration.py                               @DataDog/apm-core-python
tests/contrib/aiohttp/test_request_safety.py                            @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/anthropic/conftest.py                                     @DataDog/ml-observability
tests/contrib/asynctest/test_asynctest.py                               @DataDog/ci-app-libraries
tests/contrib/django/django_app/settings.py                             @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/djangorestframework/test_appsec.py                        @DataDog/asm-python
tests/contrib/falcon/test_suite.py                                      @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/flask/app.py                                              @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/google_generativeai/conftest.py                           @DataDog/ml-observability
tests/contrib/grpc/test_grpc.py                                         @DataDog/apm-idm-python @DataDog/asm-python
tests/contrib/grpc_aio/test_grpc_aio.py                                 @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/gunicorn/wsgi_mw_app.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/kafka/test_kafka.py                                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/langchain/conftest.py                                     @DataDog/ml-observability
tests/contrib/openai/conftest.py                                        @DataDog/ml-observability
tests/contrib/openai/test_openai_v1.py                                  @DataDog/ml-observability
tests/contrib/pymongo/test.py                                           @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/pyramid/app/app.py                                        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/pyramid/pserve_app/app/__init__.py                        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/redis/test_redis.py                                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/sanic/run_server.py                                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/urllib3/test_urllib3.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/vertexai/conftest.py                                      @DataDog/ml-observability
tests/integration/test_debug.py                                         @DataDog/apm-core-python
tests/integration/test_integration.py                                   @DataDog/apm-core-python
tests/integration/test_integration_civisibility.py                      @DataDog/ci-app-libraries
tests/integration/test_integration_snapshots.py                         @DataDog/apm-core-python
tests/integration/test_sampling.py                                      @DataDog/apm-core-python
tests/integration/test_trace_stats.py                                   @DataDog/apm-core-python
tests/opentelemetry/flask_app.py                                        @DataDog/apm-sdk-api-python
tests/opentracer/conftest.py                                            @DataDog/apm-core-python
tests/profiling/test_profiler.py                                        @DataDog/profiling-python
tests/telemetry/test_telemetry.py                                       @DataDog/apm-python
tests/tracer/runtime/test_tag_collectors.py                             @DataDog/apm-sdk-api-python
tests/tracer/test_processors.py                                         @DataDog/apm-sdk-api-python
tests/tracer/test_propagation.py                                        @DataDog/apm-sdk-api-python
tests/tracer/test_sampler.py                                            @DataDog/apm-sdk-api-python
tests/tracer/test_tracer.py                                             @DataDog/apm-sdk-api-python
tests/utils.py                                                          @DataDog/python-guild
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_float_special_case_do_not_match.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_float_special_case_match_star.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_glob_multi_rule.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_resource.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_and_name_glob.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_and_resource.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_and_resource_glob.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_and_service_glob.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_glob.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_tags_glob_insensitive_case_match.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_w_None.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_w_None_meta.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_w_metrics.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_extended_sampling_w_tags_none.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_sampling_with_defaults.json  @DataDog/apm-python
tests/snapshots/tests.integration.test_sampling.test_sampling_with_rate_limit_3.json  @DataDog/apm-python

@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from f0ad5a4 to a925600 Compare March 11, 2025 17:33
@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from a925600 to 64f1622 Compare March 11, 2025 17:49
@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from 21474ae to 5a4256b Compare March 11, 2025 22:00
@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from 2c06702 to 0564439 Compare March 12, 2025 17:39
@DataDog DataDog deleted a comment from pr-commenter bot Mar 12, 2025
@mabdinur mabdinur marked this pull request as ready for review March 12, 2025 17:39
@mabdinur mabdinur requested review from a team as code owners March 12, 2025 17:39
@pr-commenter
Copy link

pr-commenter bot commented Mar 12, 2025

Benchmarks

Benchmark execution time: 2025-03-25 15:15:58

Comparing candidate commit 8772d56 in PR branch munir/remove-references-to-trace-configure with baseline commit 479d945 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 498 metrics, 2 unstable metrics.

@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from dade3a6 to 1322497 Compare March 14, 2025 14:41
Copy link
Contributor

@Yun-Kim Yun-Kim left a comment

Choose a reason for hiding this comment

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

LGTM from team mlobs, thanks for the update!

Copy link
Contributor

github-actions bot commented Mar 14, 2025

Bootstrap import analysis

Comparison of import times between this PR and main.

Summary

The average import time in this PR is: 242 ± 3 ms.

The average import time in main is: 245 ± 4 ms.

The import time difference between this PR and main is: -3.4 ± 0.2 ms.

Import time breakdown

The following import paths have grown:

ddtrace.auto 2.594 ms (1.07%)
ddtrace.bootstrap.sitecustomize 2.515 ms (1.04%)
ddtrace.bootstrap.preload 2.393 ms (0.99%)
ddtrace.internal.products 2.248 ms (0.93%)
ddtrace.internal.symbol_db.remoteconfig 0.948 ms (0.39%)
multiprocessing.sharedctypes 0.864 ms (0.36%)
multiprocessing.heap 0.864 ms (0.36%)
mmap 0.864 ms (0.36%)
ddtrace.internal.symbol_db.symbols 0.085 ms (0.04%)
ddtrace.internal.safety 0.085 ms (0.04%)
ddtrace.internal.uwsgi 0.927 ms (0.38%)
importlib.metadata 0.203 ms (0.08%)
importlib.abc 0.075 ms (0.03%)
importlib.resources 0.075 ms (0.03%)
importlib.resources._common 0.075 ms (0.03%)
importlib.resources._adapters 0.075 ms (0.03%)
importlib.metadata._adapters 0.062 ms (0.03%)
ddtrace.settings.dynamic_instrumentation 0.090 ms (0.04%)
ddtrace.internal.remoteconfig.client 0.080 ms (0.03%)
ddtrace.internal.remoteconfig._pubsub 0.080 ms (0.03%)
ddtrace.internal.remoteconfig._publishers 0.080 ms (0.03%)
ddtrace.settings.crashtracker 0.088 ms (0.04%)
ddtrace.internal.flare.flare 0.057 ms (0.02%)
ddtrace._trace.trace_handlers 0.122 ms (0.05%)
ddtrace._trace.utils_botocore.span_tags 0.062 ms (0.03%)
ddtrace._trace.utils_botocore.aws_payload_tagging 0.062 ms (0.03%)
ddtrace.vendor.jsonpath_ng 0.062 ms (0.03%)
ddtrace.vendor.jsonpath_ng.jsonpath 0.062 ms (0.03%)
ddtrace.vendor.jsonpath_ng.lexer 0.062 ms (0.03%)
ddtrace._trace.utils 0.060 ms (0.03%)
ddtrace 0.078 ms (0.03%)
ddtrace.trace 0.078 ms (0.03%)

The following import paths have shrunk:

ddtrace.auto 5.030 ms (2.08%)
ddtrace.bootstrap.sitecustomize 4.178 ms (1.73%)
ddtrace.bootstrap.preload 3.998 ms (1.65%)
ddtrace.internal.products 2.956 ms (1.22%)
ddtrace.internal.symbol_db.remoteconfig 1.213 ms (0.50%)
multiprocessing 0.931 ms (0.39%)
multiprocessing.context 0.931 ms (0.39%)
multiprocessing.reduction 0.848 ms (0.35%)
pickle 0.848 ms (0.35%)
_compat_pickle 0.848 ms (0.35%)
multiprocessing.process 0.083 ms (0.03%)
ddtrace.internal.remoteconfig._connectors 0.100 ms (0.04%)
ddtrace.internal.symbol_db.symbols 0.096 ms (0.04%)
ddtrace.settings.symbol_db 0.096 ms (0.04%)
multiprocessing.sharedctypes 0.086 ms (0.04%)
multiprocessing.heap 0.086 ms (0.04%)
multiprocessing.util 0.086 ms (0.04%)
ddtrace.internal.remoteconfig.client 0.682 ms (0.28%)
importlib.metadata 0.223 ms (0.09%)
importlib.abc 0.087 ms (0.04%)
importlib.resources 0.087 ms (0.04%)
importlib.resources._common 0.087 ms (0.04%)
csv 0.074 ms (0.03%)
importlib.metadata._collections 0.062 ms (0.03%)
ddtrace.debugging._config 0.070 ms (0.03%)
ddtrace.settings.exception_replay 0.070 ms (0.03%)
ddtrace.settings.profiling 0.869 ms (0.36%)
ddtrace.vendor.psutil 0.869 ms (0.36%)
ddtrace.vendor.psutil._pslinux 0.869 ms (0.36%)
ddtrace.vendor.psutil._psutil_linux 0.085 ms (0.04%)
ddtrace.settings.crashtracker 0.093 ms (0.04%)
ddtrace.internal.datadog.profiling.crashtracker 0.093 ms (0.04%)
ddtrace.internal.datadog.profiling.crashtracker._crashtracker 0.093 ms (0.04%)
ddtrace.internal.flare._subscribers 0.080 ms (0.03%)
ddtrace._trace.trace_handlers 0.180 ms (0.07%)
ddtrace._trace.utils_botocore.span_pointers 0.092 ms (0.04%)
ddtrace._trace.utils_botocore.span_pointers.dynamodb 0.092 ms (0.04%)
ddtrace._trace.utils_botocore.span_tags 0.088 ms (0.04%)
ddtrace._trace.utils_botocore.aws_payload_tagging 0.088 ms (0.04%)
ddtrace.vendor.jsonpath_ng 0.088 ms (0.04%)
ddtrace.vendor.jsonpath_ng.jsonpath 0.088 ms (0.04%)
ddtrace.vendor.jsonpath_ng.lexer 0.088 ms (0.04%)
ddtrace.vendor.ply.lex 0.088 ms (0.04%)
ddtrace 0.852 ms (0.35%)
ddtrace.trace 0.155 ms (0.06%)
ddtrace._trace.tracer 0.155 ms (0.06%)

@mabdinur mabdinur added the changelog/no-changelog A changelog entry is not required for this PR. label Mar 17, 2025
Copy link
Contributor

@wconti27 wconti27 left a comment

Choose a reason for hiding this comment

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

integration changes LGTM

@mabdinur mabdinur enabled auto-merge (squash) March 19, 2025 20:18
Copy link
Contributor

@ZStriker19 ZStriker19 left a comment

Choose a reason for hiding this comment

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

Just need to add back in those sampling tests (commented on above) with an envar and I think we're good!

@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch 4 times, most recently from 598e747 to 5f96efb Compare March 25, 2025 03:28
@mabdinur mabdinur force-pushed the munir/remove-references-to-trace-configure branch from 5f96efb to d9bbafb Compare March 25, 2025 03:31
@mabdinur mabdinur merged commit c4644f0 into main Mar 25, 2025
837 checks passed
@mabdinur mabdinur deleted the munir/remove-references-to-trace-configure branch March 25, 2025 15:58
brettlangdon added a commit that referenced this pull request Mar 25, 2025
…ests" (#12878)

This PR reverts #12696 which is not compatible with #12821 which were
both merged close together, but not compatible with each other.

- [x] Reverts #12696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants