Skip to content

refactor: remove ExecutionContext._inner_span#19084

Open
emmettbutler wants to merge 20 commits into
mainfrom
emmett.butler/no-inner-span
Open

refactor: remove ExecutionContext._inner_span#19084
emmettbutler wants to merge 20 commits into
mainfrom
emmett.butler/no-inner-span

Conversation

@emmettbutler

@emmettbutler emmettbutler commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

This change removes the _inner_span attribute from ddtrace.core.ExecutionContext, replacing it with an _inner_span datum stored via existing mechanisms. This eliminates Spans as a special case in the Core API, treating them like any other piece of data stored in the context tree.

span_bus is introduced containing two of the span-related helper functions from core, indicating the separateness of Span management from Core. Note that while this separation does fix the import-time coupling between _trace and core, it does not address the functional dependence of certain products on _trace, specifically those that use Spans as context tracking.

@emmettbutler
emmettbutler requested review from a team as code owners July 15, 2026 18:01
@emmettbutler
emmettbutler requested review from brettlangdon, rachelyangdog and wconti27 and removed request for a team July 15, 2026 18:01
@emmettbutler
emmettbutler marked this pull request as draft July 15, 2026 18:01
@datadog-official

datadog-official Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 3 jobs - 2 passed on retry View in Datadog

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

@cit-pr-commenter-54b7da

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

Copy link
Copy Markdown

Codeowners resolved as

ddtrace/internal/core/__init__.py                                       @DataDog/apm-core-python

@cit-pr-commenter-54b7da

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

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

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

Show existing cycles (showing 5 of 42 shortest)
ddtrace.internal.datastreams -> ddtrace.internal.datastreams.botocore -> ddtrace.internal.datastreams
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

✅ Circular imports removed

19 circular import(s) have been removed by this PR.

Show removed cycles (showing 5 of 19 shortest)
ddtrace.internal.core -> ddtrace._trace.span -> ddtrace.internal.core
ddtrace.internal.utils -> ddtrace.internal.core -> ddtrace._trace.span -> ddtrace._trace.context -> ddtrace.internal.utils.http -> ddtrace.internal.utils
ddtrace.internal.core -> ddtrace._trace.span -> ddtrace.internal.settings._config -> ddtrace.internal.telemetry -> ddtrace.internal.telemetry.writer -> ddtrace.internal.core
ddtrace.internal.core -> ddtrace._trace.span -> ddtrace._trace._span_pointer -> ddtrace._trace.telemetry -> ddtrace.internal.telemetry -> ddtrace.internal.telemetry.writer -> ddtrace.internal.core
ddtrace.internal.utils -> ddtrace.internal.core -> ddtrace._trace.span -> ddtrace.internal.settings._config -> ddtrace.internal.settings.http -> ddtrace.internal.utils.http -> ddtrace.internal.utils

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

@emmettbutler emmettbutler added the changelog/no-changelog A changelog entry is not required for this PR. label Jul 15, 2026
@pr-commenter

pr-commenter Bot commented Jul 15, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-15 19:33:33

Comparing candidate commit 72f665e in PR branch emmett.butler/no-inner-span with baseline commit 7edd95d in branch emmett.butler/no-core-tracer.

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

scenario:iastaspects-lstrip_aspect

  • 🟥 execution_time [+67.393µs; +72.555µs] or [+20.798%; +22.391%]

scenario:iastaspects-repr_aspect

  • 🟥 execution_time [+56.101µs; +63.662µs] or [+14.756%; +16.745%]

scenario:iastaspects-translate_aspect

  • 🟥 execution_time [+65.680µs; +72.033µs] or [+12.857%; +14.100%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+100.585µs; +107.587µs] or [+24.191%; +25.875%]

scenario:span-start

  • 🟥 execution_time [+1.312ms; +1.490ms] or [+8.338%; +9.475%]

Base automatically changed from emmett.butler/no-core-tracer to main July 17, 2026 02:47
@emmettbutler
emmettbutler marked this pull request as ready for review July 17, 2026 03:23
@emmettbutler
emmettbutler requested review from a team as code owners July 17, 2026 03:23

@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: 683a5f6517

ℹ️ 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".

return span._local_root or span


def span_from_context(ctx: core.ExecutionContext[t.Any]) -> "Span":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update remaining ctx.span benchmark callers

Now that span access has moved to span_from_context, the repo still has ctx.span in benchmarks/events_api/scenario.py at lines 53 and 85. When the events_api benchmark runs those handlers after _start_span, ExecutionContext no longer has a span attribute, so the benchmark aborts with AttributeError instead of measuring the refactor. Please update the benchmark callers to use this helper or keep a compatibility alias.

Useful? React with 👍 / 👎.

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.

1 participant