-
Notifications
You must be signed in to change notification settings - Fork 483
feat(ddtrace/tracer): introduce ExtractCtx to support propagated context #3866
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
base: main
Are you sure you want to change the base?
Conversation
BenchmarksBenchmark execution time: 2025-08-13 09:29:15 Comparing candidate commit 831161b in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 metrics, 0 unstable metrics. |
if err != nil { | ||
return nil, err | ||
} | ||
return contextWithSpanContext(ctx, sctx), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Extract
returns a nil sctx
, then we set nil on the context at the key. Is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, you are totally right, and I think it's not ok. We should avoid setting any nil
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved. Thanks!
ddtrace/tracer/context.go
Outdated
|
||
// contextWithSpanContext returns a copy of the given context which includes the span context sctx. | ||
func contextWithSpanContext(ctx context.Context, sctx *SpanContext) context.Context { | ||
return orchestrion.CtxWithValue(ctx, internal.ActiveSpanKey, sctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be internal.ActiveSpanContextKey
instead of internal.ActiveSpanKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is just a draft, but looking forward to the tests to better understand how these functions will be used!
d609de6
to
831161b
Compare
What does this PR do?
Adds
ExtractCtx
to simplify the creation of child spans from propagated contexts.Some notes:
ExtractCtx
to reduce the increase on public API.ChildOf
internally, which expects aSpanContext
, so instead of reusing the existingActiveSpanKey
we create a new one forActiveSpanContextKey
(which it doesn't have precedence overActiveSpanKey
value).Motivation
Fixes #3793
Reviewer's Checklist
./scripts/lint.sh
locally.Unsure? Have a question? Request a review!