Skip to content

Commit

Permalink
feat(tracing): Add a new SpanOption: SpanSampled (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyo committed Jan 24, 2023
1 parent ccb6055 commit 907ce4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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

0 comments on commit 907ce4a

Please sign in to comment.