Skip to content

refactor: move constants out of internal.constants#18964

Open
emmettbutler wants to merge 23 commits into
mainfrom
emmett.butler/move-internal-constants
Open

refactor: move constants out of internal.constants#18964
emmettbutler wants to merge 23 commits into
mainfrom
emmett.butler/move-internal-constants

Conversation

@emmettbutler

@emmettbutler emmettbutler commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Description

This change relocates many constant definitions from ddtrace.internal.constants. For each constant, the destination was chosen based on the current set of dependent modules. Examples:

  • Imported by multiple contribs, appsec -> move to ddtrace.internal.utils.constants
  • Imported only by code related to propagation -> move to ddtrace.propagation._constants
  • Imported by dsm, llmobs -> move to ddtrace.internal.utils.constants
  • Imported by multiple contribs -> move to ddtrace.contrib.internal._constants

This approach reduces coupling by shrinking the widely-shared internal module slightly.

This change doesn't make any attempt to remove knowledge of external concepts from modules. For example, ddtrace.internal.utils.http currently knows about the concepts of sampling and span tags via its import of SAMPLING_DECISION_TRACE_TAG_KEY, but it ideally would not. Such abstraction leakage will be addressed in a future change.

Testing

No functional changes are expected

@emmettbutler emmettbutler requested review from a team as code owners July 9, 2026 16:58
@emmettbutler emmettbutler marked this pull request as draft July 9, 2026 16:58
@emmettbutler emmettbutler added the changelog/no-changelog A changelog entry is not required for this PR. label Jul 9, 2026
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jul 9, 2026

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 4974 circular imports that already exist on the base branch and have not been changed by this PR.

Show existing cycles (showing 5 of 4974 shortest)
ddtrace.internal.core -> ddtrace._trace.span -> ddtrace.internal.core
ddtrace.internal.datastreams -> ddtrace.internal.datastreams.kafka -> ddtrace.internal.datastreams
ddtrace.internal.datastreams -> ddtrace.internal.datastreams.aiokafka -> ddtrace.internal.datastreams
ddtrace.internal.datastreams -> ddtrace.internal.datastreams.kombu -> ddtrace.internal.datastreams
ddtrace.internal.datastreams -> ddtrace.internal.datastreams.google_cloud_pubsub -> ddtrace.internal.datastreams

To see all cycles, download the cycles-base.json and cycles-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/cycles.py compare cycles-base.json cycles-pr.json

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codeowners resolved as

ddtrace/appsec/_trace_utils.py                                          @DataDog/asm-python
tests/appsec/contrib_appsec/utils.py                                    @DataDog/asm-python
tests/tracer/test_processors.py                                         @DataDog/apm-sdk-capabilities-python @DataDog/apm-core-python
tests/tracer/test_sampler.py                                            @DataDog/apm-sdk-capabilities-python @DataDog/apm-core-python
tests/tracer/test_single_span_sampling_rules.py                         @DataDog/apm-sdk-capabilities-python @DataDog/apm-core-python

Comment thread ddtrace/propagation/constants.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b157a98c65

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ddtrace/propagation/constants.py Outdated
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 9 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741589-d2b8243-musllinux_1_2_aarch64, 1]   View in Datadog   GitLab

View all 9 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 6 jobs - 4 passed on retry View in Datadog

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c423a5c | Docs | Datadog PR Page | Give us feedback!

Comment thread ddtrace/internal/runtime/tag_collectors.py Outdated
Comment thread ddtrace/internal/_encoding.pyx
Comment thread ddtrace/_trace/constants.py Outdated
Comment thread ddtrace/internal/utils/http.py
@pr-commenter

pr-commenter Bot commented Jul 10, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-11 00:07:08

Comparing candidate commit b1d7f04 in PR branch emmett.butler/move-internal-constants with baseline commit 857c18a in branch main.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 621 metrics, 10 unstable metrics.

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+96.727µs; +107.236µs] or [+22.663%; +25.125%]

@emmettbutler emmettbutler changed the title refactor: move propagation constants to propagation module refactor: move constants out of internal.constants Jul 11, 2026
@emmettbutler emmettbutler marked this pull request as ready for review July 11, 2026 00:53
@emmettbutler emmettbutler requested review from a team as code owners July 11, 2026 00:53

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

Static analysis and adversarial constant-value tests confirm all 70+ constants were correctly relocated — values unchanged, no stale imports from ddtrace.internal.constants, new constants files are import-free (eliminating any circular-import risk), and every consumer (production + tests) now points to the new module path. The removed SPAN_API_OPENTRACING was dead code with zero callers.

Was this helpful? React 👍 or 👎

📊 Validated against 12 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit c423a5c · What is Autotest? · Any feedback? Reach out in #autotest

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM for Profiling.

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.

4 participants