Conversation
5562df0 to
0e6bf84
Compare
0e6bf84 to
09cf02b
Compare
09cf02b to
388298c
Compare
388298c to
569c73b
Compare
569c73b to
580aec3
Compare
580aec3 to
75a6927
Compare
75a6927 to
bee39bc
Compare
bee39bc to
ba9db9a
Compare
5a7b7e9 to
ec45c0b
Compare
fa24cc9 to
12311a2
Compare
12311a2 to
e0c450d
Compare
e0c450d to
8a4508e
Compare
8a4508e to
80793c9
Compare
szokeasaurusrex
left a comment
There was a problem hiding this comment.
I think this mostly looks good! I left some questions about some items I was unclear on
|
|
||
| func (client *Client) prepareEvent(event *Event, scope *Scope, opts captureOptions) *Event { | ||
| scopeProcessors := scope.applyToEvent(event, client, opts.hint, client.options.MaxBreadcrumbs) | ||
| func (client *Client) prepareEvent(ctx context.Context, event *Event, scope *Scope, opts captureOptions) *Event { |
There was a problem hiding this comment.
[question] why do we still take an explicitly passed scope here? Can't we take it from the ctx?
| ctx := ContextWithClient(ContextWithScope(context.Background(), scope), client) | ||
| transaction := StartTransaction(ctx, "request", WithOpName("http.server")) | ||
|
|
||
| require.NotNil(t, client.CaptureMessage(transaction.Context(), "message")) |
There was a problem hiding this comment.
I notice here we pass transaction.Context(), not ctx. I am assuming that is because of the copy-on-write behavior we were discussing earlier (i.e. ctx remains unchanged and the new context goes on the transaction)?
If that is the case, this new API does seem somewhat unergonomic because it requires an SDK user to remember to capture the message on the specific transaction context in order to get the message to show correctly within said transaction. Is this something you have considered? Is there an alternative API planned which will make this easier for users, or is it a tradeoff we need to accept?
| // hubFromContext returns either a hub stored in the context or the current hub. | ||
| // The return value is guaranteed to be non-nil, unlike GetHubFromContext. | ||
| func hubFromContext(ctx context.Context) *Hub { | ||
| func hubFromContext(ctx context.Context) *Hub { // nolint: unused |
There was a problem hiding this comment.
[question] why are we keeping this around if it is unused?
There was a problem hiding this comment.
removing on the remove hub branch.
| maxSpans := defaultMaxSpans | ||
| if client := CurrentHub().Client(); client.IsEnabled() { | ||
| if client != nil && client.IsEnabled() { | ||
| maxSpans = client.options.MaxSpans |
There was a problem hiding this comment.
I guess technically out of scope for this PR, but I believe max spans is not meant to be user-configurable? It is not listed as one of the options on this page
There was a problem hiding this comment.
Yeah, agreed, but this probably needs to be a separate change.
| func TestContinueSpanFromRequest(t *testing.T) { | ||
| traceID := TraceIDFromHex("bc6d53f15eb88f4320054569b8c553d4") | ||
| spanID := SpanIDFromHex("b72fa28504b07285") | ||
|
|
||
| for _, sampled := range []Sampled{SampledTrue, SampledFalse, SampledUndefined} { | ||
| sampled := sampled | ||
| t.Run(sampled.String(), func(t *testing.T) { | ||
| var s Span | ||
| s.ctx = context.Background() | ||
| hkey := http.CanonicalHeaderKey("sentry-trace") | ||
| hval := (&Span{ | ||
| TraceID: traceID, | ||
| SpanID: spanID, | ||
| Sampled: sampled, | ||
| }).ToSentryTrace() | ||
| header := http.Header{hkey: []string{hval}} | ||
| ContinueFromRequest(&http.Request{Header: header})(&s) | ||
| if s.TraceID != traceID { | ||
| t.Errorf("got %q, want %q", s.TraceID, traceID) | ||
| } | ||
| if s.ParentSpanID != spanID { | ||
| t.Errorf("got %q, want %q", s.ParentSpanID, spanID) | ||
| } | ||
| if s.Sampled != sampled { | ||
| t.Errorf("got %q, want %q", s.Sampled, sampled) | ||
| } | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Have this test (and the other removed tests in this file) been fully removed, or is the same logic moving elsewhere?
80793c9 to
37acc6f
Compare
37acc6f to
645b45e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 645b45e. Configure here.
Use context.Context for active span lookup and parenting while retaining the request transaction on its scope as a stable correlation fallback. Child spans never replace or restore that fallback, and finishing a transaction preserves request correlation. Freeze dynamic sampling context once for baggage, error capture, and transaction delivery. Explicit client bindings remain authoritative; unbound contexts follow Init. Keep incoming sampling decisions when recording is disabled, inherit local parent sampling before client overrides, and reject inconsistent continuation metadata without retaining a previous request's trace. ContinueTrace accepts incoming header values as a span option without changing scope state before a transaction starts. StartTransaction returns the existing root without changing its context; callers reusing a transaction must retain their caller context and leave finishing to its owner.
645b45e to
65227ad
Compare

Description
Modify existing tracing and propagation behavior to rely on
context.Context. Tracing now resolves state from context rather than hubs. This includes a breaking change onContinueTraceremoving the need for a hub to be passed.#skip-changelog
Issues
context.Context#1367Changelog Entry Instructions
To add a custom changelog entry, uncomment the section above. Supports:
For more details: custom changelog entries
Reminders
feat:,fix:,ref:,meta:)