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

feat(tracing): Add the sampling decision to the trace envelope header #666

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions dynamic_sampling_context.go
Expand Up @@ -82,6 +82,12 @@ func DynamicSamplingContextFromTransaction(span *Span) DynamicSamplingContext {
entries["user_segment"] = userSegment
}

if span.Sampled.Bool() {
entries["sampled"] = "true"
} else {
entries["sampled"] = "false"
}

return DynamicSamplingContext{
Entries: entries,
Frozen: true,
Expand Down
15 changes: 8 additions & 7 deletions dynamic_sampling_context_test.go
Expand Up @@ -82,7 +82,7 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) {
input: func() *Span {
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
TracesSampleRate: 0.5,
TracesSampleRate: 1.0,
Dsn: "http://public@example.com/sentry/1",
Release: "1.0.0",
Environment: "test",
Expand All @@ -97,13 +97,14 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) {
want: DynamicSamplingContext{
Frozen: true,
Entries: map[string]string{
"sample_rate": "0.5",
"sample_rate": "1",
"trace_id": "d49d9bf66f13450b81f65bc51cf49c03",
"public_key": "public",
"release": "1.0.0",
"environment": "test",
"transaction": "name",
"user_segment": "user_segment",
"sampled": "true",
},
},
},
Expand All @@ -112,7 +113,7 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) {
input: func() *Span {
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
TracesSampleRate: 0.5,
TracesSampleRate: 0.0,
Dsn: "http://public@example.com/sentry/1",
Release: "1.0.0",
})
Expand All @@ -123,10 +124,10 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) {
want: DynamicSamplingContext{
Frozen: true,
Entries: map[string]string{
"sample_rate": "0.5",
"trace_id": "d49d9bf66f13450b81f65bc51cf49c03",
"public_key": "public",
"release": "1.0.0",
"trace_id": "d49d9bf66f13450b81f65bc51cf49c03",
"public_key": "public",
"release": "1.0.0",
"sampled": "false",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions otel/propagator_test.go
Expand Up @@ -131,7 +131,7 @@ func testInjectUsesSetsValidTrace(t *testing.T, withChildSpan bool) {
spanID: "6e0c63257de34c92",
sampled: sentry.SampledTrue,
},
wantBaggage: stringPtr("sentry-environment=testing,sentry-release=1.2.3,sentry-transaction=sampled-transaction,sentry-public_key=abc,sentry-trace_id=d4cda95b652f4a1592b449d5929fda1b,sentry-sample_rate=1"),
wantBaggage: stringPtr("sentry-environment=testing,sentry-release=1.2.3,sentry-transaction=sampled-transaction,sentry-public_key=abc,sentry-trace_id=d4cda95b652f4a1592b449d5929fda1b,sentry-sample_rate=1,sentry-sampled=true"),
wantSentryTrace: stringPtr("d4cda95b652f4a1592b449d5929fda1b-6e0c63257de34c92-1"),
},
{
Expand All @@ -142,7 +142,7 @@ func testInjectUsesSetsValidTrace(t *testing.T, withChildSpan bool) {
spanID: "6e0c63257de34c92",
sampled: sentry.SampledFalse,
},
wantBaggage: stringPtr("sentry-environment=testing,sentry-release=1.2.3,sentry-transaction=not-sampled-transaction,sentry-public_key=abc,sentry-trace_id=d4cda95b652f4a1592b449d5929fda1b"),
wantBaggage: stringPtr("sentry-environment=testing,sentry-release=1.2.3,sentry-transaction=not-sampled-transaction,sentry-public_key=abc,sentry-trace_id=d4cda95b652f4a1592b449d5929fda1b,sentry-sampled=false"),
wantSentryTrace: stringPtr("d4cda95b652f4a1592b449d5929fda1b-6e0c63257de34c92-0"),
},
{
Expand Down
2 changes: 1 addition & 1 deletion otel/span_processor_test.go
Expand Up @@ -124,7 +124,7 @@ func TestOnStartRootSpan(t *testing.T) {
testutils.AssertBaggageStringsEqual(
t,
sentrySpan.ToBaggage(),
"sentry-transaction=spanName,sentry-environment=testing,sentry-public_key=abc,sentry-release=1.2.3,sentry-sample_rate=1,sentry-trace_id="+otelTraceId.String(),
"sentry-transaction=spanName,sentry-environment=testing,sentry-public_key=abc,sentry-release=1.2.3,sentry-sample_rate=1,sentry-sampled=true,sentry-trace_id="+otelTraceId.String(),
)
}

Expand Down
10 changes: 5 additions & 5 deletions tracing_test.go
Expand Up @@ -817,25 +817,25 @@ func TestGetTransactionReturnsNilOnManuallyCreatedSpans(t *testing.T) {

func TestToBaggage(t *testing.T) {
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
SampleRate: 1.0,
Release: "test-release",
EnableTracing: true,
TracesSampleRate: 1.0,
Release: "test-release",
})
transaction := StartTransaction(ctx, "transaction-name")
transaction.TraceID = TraceIDFromHex("f1a4c5c9071eca1cdf04e4132527ed16")

assertBaggageStringsEqual(
t,
transaction.ToBaggage(),
"sentry-trace_id=f1a4c5c9071eca1cdf04e4132527ed16,sentry-release=test-release,sentry-transaction=transaction-name",
"sentry-trace_id=f1a4c5c9071eca1cdf04e4132527ed16,sentry-release=test-release,sentry-transaction=transaction-name,sentry-sample_rate=1,sentry-sampled=true",
)

// Calling ToBaggage() on a child span should return the same result
child := transaction.StartChild("op-name")
assertBaggageStringsEqual(
t,
child.ToBaggage(),
"sentry-trace_id=f1a4c5c9071eca1cdf04e4132527ed16,sentry-release=test-release,sentry-transaction=transaction-name",
"sentry-trace_id=f1a4c5c9071eca1cdf04e4132527ed16,sentry-release=test-release,sentry-transaction=transaction-name,sentry-sample_rate=1,sentry-sampled=true",
)
}

Expand Down