Skip to content
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

fix(dynamic-sampling): Do not freeze DSC if no Sentry values are present #532

Merged
merged 5 commits into from Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion dynamic_sampling_context.go
Expand Up @@ -33,7 +33,8 @@ func DynamicSamplingContextFromHeader(header []byte) (DynamicSamplingContext, er

return DynamicSamplingContext{
Entries: entries,
Frozen: true,
// If there's at least one Sentry value, we consider the DSC frozen
Frozen: len(entries) > 0,
}, nil
}

Expand Down
30 changes: 25 additions & 5 deletions dynamic_sampling_context_test.go
Expand Up @@ -8,16 +8,27 @@ import (

func TestDynamicSamplingContextFromHeader(t *testing.T) {
tests := []struct {
input []byte
want DynamicSamplingContext
input []byte
want DynamicSamplingContext
errMsg string
}{
// Empty baggage header
{
input: []byte(""),
want: DynamicSamplingContext{
Frozen: true,
Frozen: false,
Entries: map[string]string{},
},
},
// Third-party baggage
{
input: []byte("other-vendor-key1=value1;value2, other-vendor-key2=value3"),
want: DynamicSamplingContext{
Frozen: false,
Entries: map[string]string{},
},
},
// Sentry-only baggage
{
input: []byte("sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1"),
want: DynamicSamplingContext{
Expand All @@ -29,6 +40,7 @@ func TestDynamicSamplingContextFromHeader(t *testing.T) {
},
},
},
// Mixed baggage
{
input: []byte("sentry-trace_id=d49d9bf66f13450b81f65bc51cf49c03,sentry-public_key=public,sentry-sample_rate=1,foo=bar;foo;bar;bar=baz"),
want: DynamicSamplingContext{
Expand All @@ -40,14 +52,22 @@ func TestDynamicSamplingContextFromHeader(t *testing.T) {
},
},
},
// Invalid baggage value
{
input: []byte(","),
want: DynamicSamplingContext{
Frozen: false,
},
errMsg: "invalid baggage list-member: \"\"",
},
}

for _, tc := range tests {
got, err := DynamicSamplingContextFromHeader(tc.input)
assertEqual(t, got, tc.want, "Context mismatch")
if err != nil {
t.Fatal(err)
assertEqual(t, err.Error(), tc.errMsg, "Error mismatch")
}
assertEqual(t, got, tc.want)
}
}

Expand Down