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 a new SpanOption: SpanSampled #546

Merged
merged 2 commits into from Jan 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
- Add DSN getters ([#540](https://github.com/getsentry/sentry-go/pull/540))
- Add Span.SetData() ([#542](https://github.com/getsentry/sentry-go/pull/542))
- Add Span.IsTransaction() ([#543](https://github.com/getsentry/sentry-go/pull/543))
- Add a new SpanOption: `SpanSampled` ([#546](https://github.com/getsentry/sentry-go/pull/546))

## 0.17.0

Expand Down
7 changes: 7 additions & 0 deletions tracing.go
Expand Up @@ -706,6 +706,13 @@ func TransctionSource(source TransactionSource) SpanOption {
}
}

// SpanSampled updates the sampling flag for a given span.
func SpanSampled(sampled Sampled) SpanOption {
return func(s *Span) {
s.Sampled = sampled
}
}

// ContinueFromRequest returns a span option that updates the span to continue
// an existing trace. If it cannot detect an existing trace in the request, the
// span will be left unchanged.
Expand Down
4 changes: 1 addition & 3 deletions tracing_test.go
Expand Up @@ -645,9 +645,7 @@ func TestSample(t *testing.T) {
EnableTracing: true,
TracesSampleRate: 0.0,
})
span = StartSpan(ctx, "op", TransactionName("name"), func(s *Span) {
s.Sampled = SampledTrue
})
span = StartSpan(ctx, "op", TransactionName("name"), SpanSampled(SampledTrue))
if got := span.Sampled; got != SampledTrue {
t.Fatalf("got %s, want %s", got, SampledTrue)
}
Expand Down