-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dynamic Sampling] Head of trace (#492)
Co-authored-by: Abhijeet Prasad <[email protected]>
- Loading branch information
1 parent
d01ce46
commit f219a81
Showing
5 changed files
with
186 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import ( | |
"testing" | ||
) | ||
|
||
func TestNewDynamicSamplingContext(t *testing.T) { | ||
func TestDynamicSamplingContextFromHeader(t *testing.T) { | ||
tests := []struct { | ||
input []byte | ||
want DynamicSamplingContext | ||
|
@@ -41,10 +41,90 @@ func TestNewDynamicSamplingContext(t *testing.T) { | |
} | ||
|
||
for _, tc := range tests { | ||
got, err := NewDynamicSamplingContext(tc.input) | ||
got, err := DynamicSamplingContextFromHeader(tc.input) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assertEqual(t, got, tc.want) | ||
} | ||
} | ||
|
||
func TestDynamicSamplingContextFromTransaction(t *testing.T) { | ||
tests := []struct { | ||
input *Span | ||
want DynamicSamplingContext | ||
}{ | ||
// Normal flow | ||
{ | ||
input: func() *Span { | ||
ctx := NewTestContext(ClientOptions{ | ||
EnableTracing: true, | ||
TracesSampleRate: 0.5, | ||
Dsn: "http://[email protected]/sentry/1", | ||
Release: "1.0.0", | ||
Environment: "test", | ||
}) | ||
hubFromContext(ctx).ConfigureScope(func(scope *Scope) { | ||
scope.SetUser(User{Segment: "user_segment"}) | ||
}) | ||
txn := StartTransaction(ctx, "name", TransctionSource(SourceCustom)) | ||
txn.TraceID = TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03") | ||
return txn | ||
}(), | ||
want: DynamicSamplingContext{ | ||
Frozen: true, | ||
Entries: map[string]string{ | ||
"sample_rate": "0.5", | ||
"trace_id": "d49d9bf66f13450b81f65bc51cf49c03", | ||
"public_key": "public", | ||
"release": "1.0.0", | ||
"environment": "test", | ||
"transaction": "name", | ||
"user_segment": "user_segment", | ||
}, | ||
}, | ||
}, | ||
// Transaction with source url, do not include in Dynamic Sampling context | ||
{ | ||
input: func() *Span { | ||
ctx := NewTestContext(ClientOptions{ | ||
EnableTracing: true, | ||
TracesSampleRate: 0.5, | ||
Dsn: "http://[email protected]/sentry/1", | ||
Release: "1.0.0", | ||
}) | ||
txn := StartTransaction(ctx, "name") | ||
txn.TraceID = TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03") | ||
return txn | ||
}(), | ||
want: DynamicSamplingContext{ | ||
Frozen: true, | ||
Entries: map[string]string{ | ||
"sample_rate": "0.5", | ||
"trace_id": "d49d9bf66f13450b81f65bc51cf49c03", | ||
"public_key": "public", | ||
"release": "1.0.0", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
got := DynamicSamplingContextFromTransaction(tc.input) | ||
assertEqual(t, got, tc.want) | ||
} | ||
} | ||
|
||
func TestHasEntries(t *testing.T) { | ||
var dsc DynamicSamplingContext | ||
|
||
dsc = DynamicSamplingContext{} | ||
assertEqual(t, dsc.HasEntries(), false) | ||
|
||
dsc = DynamicSamplingContext{ | ||
Entries: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
} | ||
assertEqual(t, dsc.HasEntries(), true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters