Skip to content

Commit

Permalink
refactor ContinueFromHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyo committed Jan 17, 2023
1 parent 9df4019 commit ade23ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 10 additions & 5 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,19 @@ func ContinueFromRequest(r *http.Request) SpanOption {
// an existing TraceID and propagates the Dynamic Sampling context.
func ContinueFromHeaders(trace, baggage string) SpanOption {
return func(s *Span) {
if trace != "" {
s.updateFromSentryTrace([]byte(trace))
}
if baggage != "" {
s.updateFromBaggage([]byte(baggage))
}
if trace != "" {
s.updateFromSentryTrace([]byte(trace))
// In case a sentry-trace header is present, we want to freeze the
// DynamicSamplingContext in all cases.
s.dynamicSamplingContext.Frozen = true

// In case a sentry-trace header is present but there are no sentry-related
// values in the baggage, create an empty, frozen DynamicSamplingContext.
if trace != "" && !s.dynamicSamplingContext.HasEntries() {
s.dynamicSamplingContext = DynamicSamplingContext{
Frozen: true,
}
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ func TestContinueTransactionFromHeaders(t *testing.T) {
},
},
{
// sentry-trace and baggage with Sentry values => we
// immediately.
// sentry-trace and baggage with Sentry values => we freeze immediately.
traceStr: "bc6d53f15eb88f4320054569b8c553d4-b72fa28504b07285-1",
baggageStr: "sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1",
wantSpan: Span{
Expand All @@ -497,6 +496,19 @@ func TestContinueTransactionFromHeaders(t *testing.T) {
},
},
},
// TODO(anton): we should handle this case properly
// {
// // No sentry-trace, but baggage with Sentry values => this is a head SDK, so the DSC
// // should be empty and unfrozen.
// traceStr: "",
// baggageStr: "sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1",
// wantSpan: Span{
// isTransaction: true,
// dynamicSamplingContext: DynamicSamplingContext{
// Frozen: false,
// },
// },
// },
}

for _, tt := range tests {
Expand Down

0 comments on commit ade23ec

Please sign in to comment.