Skip to content

refactor(profiling): support native logical span links - #20346

Closed
taegyunkim wants to merge 8 commits into
mainfrom
taegyunkim/profiling-native-span-links
Closed

taegyunkim wants to merge 8 commits into
mainfrom
taegyunkim/profiling-native-span-links

Conversation

@taegyunkim

@taegyunkim taegyunkim commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Stacked on #20344.

Generalize the native span-link manager from thread-only keys to (domain, identifier) keys. Preserve the existing physical-thread methods while adding private native operations for asyncio task and gevent greenlet targets, finished-span cleanup across all domains, and explicit reset support.

This layer intentionally does not expose runtime tracking queries or change task or greenlet rendering. Those queries are added alongside their first consumers in the asyncio and gevent PRs. Until the corresponding Python provider is added, task samples continue using the existing physical-thread attribution behavior.

Testing

  • Added native unit coverage for logical target lifecycle, domain isolation, reset, finished-span cleanup, and relinking.
  • scripts/lint checks
  • scripts/lint profiling-native-check
  • scripts/run-tests --venv 1ed51fe
    • Python 3.12 profiling suite: 406 passed, 37 skipped, 2 xfailed
  • scripts/run-benchmarks --list ...
    • No benchmark suites match these native profiling files

Risks

The native manager's internal key and reverse-index representations change. Existing thread operations retain their API and locking behavior, and the profiling suite rebuilt and exercised the native extension.

Fork handling reconstructs the generalized maps in place using the existing child-process safety pattern. No new GIL acquisition, Python object ownership, allocator hook, or unbounded iteration behavior is introduced.

Additional Notes

No release note is needed because this is an internal foundation with no customer-visible behavior change. Asyncio task rendering and Python lifecycle routing are intentionally deferred to follow-up PRs.

Review this stack in order:

Order PR Purpose
1 #20344 (merged) Rename the native span-link manager
2 #20346 Add domain-aware native span-link storage
3 #20347 Centralize Python routing and lifecycle handling
4 #19736 Attribute asyncio task samples
5 #19737 Propagate attribution into AnyIO worker threads
6 #19420 Attribute gevent greenlet samples

@taegyunkim taegyunkim added the changelog/no-changelog A changelog entry is not required for this PR. label Sep 15, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

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

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 218 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 218 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=133)
ddtrace.llmobs._integrations.langgraph -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=131)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=131)
ddtrace.profiling.collector.stack -×-> ddtrace.trace  (product:profiling -> product:tracing, score=131)
ddtrace.llmobs._integrations.google_adk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=131)

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

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datadog/profiling/stack/__init__.pyi                   @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/_stack.pyi                     @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/include/span_links.hpp         @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/sampler.cpp                @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/span_links.cpp             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack.cpp                  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/test/test_span_links.cpp       @DataDog/profiling-python

Base automatically changed from taegyunkim/profiling-span-links-rename to main September 15, 2026 20:23
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6059428 | Docs | View more details | Give us feedback!

@taegyunkim

Copy link
Copy Markdown
Contributor Author

Superseded by the rewritten runtime-specific stack. Native reset now lives in #20347, shared keyed storage and task-specific operations are introduced with the asyncio consumer in #19736, and greenlet-specific operations are introduced with the gevent consumer in #19420. The generic logical-span API and exported domain constants were removed.

@taegyunkim taegyunkim closed this Sep 16, 2026
@taegyunkim
taegyunkim deleted the taegyunkim/profiling-native-span-links branch September 16, 2026 16:23
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