refactor: move sampling interfaces to SpanData and Context - #19811
refactor: move sampling interfaces to SpanData and Context#19811emmettbutler wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c88b419d1e
ℹ️ 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".
| let copied = parent | ||
| .bind(py) | ||
| .call_method1("copy", (trace_id_obj, span_id_obj))?; |
There was a problem hiding this comment.
Release the SpanData borrow before dispatching Context.copy
When a public Context subclass overrides copy() and that method reads the current span (for example via a context provider), call_method1 executes the override while this getter's &mut self still holds the span's mutable PyO3 borrow. The reentrant span read then fails with an Already mutably borrowed/PanicException, whereas the previous Python getter invoked parent.copy() without holding such a borrow. Split this into immutable-read, Python-call, and mutable-write phases so valid custom contexts cannot crash when a child first reads .context.
AGENTS.md reference: AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
| # `context`/`_context` (lazy build of this span's trace Context, cached on | ||
| # first read) are implemented natively on `SpanData` and inherited here. |
There was a problem hiding this comment.
Preserve context in the rendered Span API docs
docs/api.rst renders ddtrace.trace.Span with :members: but without :inherited-members:. Replacing the Python property with an inherited SpanData descriptor therefore removes context—including the detailed customer-facing documentation deleted here—from the generated Span API reference. Keep a documented forwarding property on Span or explicitly include and document this inherited member.
AGENTS.md reference: AGENTS.md:L24-L29
Useful? React with 👍 / 👎.
|
BenchmarksBenchmark execution time: 2026-08-21 20:31:27 Comparing candidate commit bb2ee36 in PR branch Found 0 performance improvements and 11 performance regressions! Performance is the same for 601 metrics, 10 unstable metrics.
|
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
This change removes a layering violation between Span and sampling.py by moving the relevant functionality to SpanData and Context.