diff --git a/client.go b/client.go index ab8e5c3cb..5b712b845 100644 --- a/client.go +++ b/client.go @@ -307,12 +307,7 @@ func NewClient(options ClientOptions) (*Client, error) { switch options.Instrumenter { case "": options.Instrumenter = "sentry" - case "sentry": - // noop - case "otel": - // sampling is performed by the OpenTelemetry SDK - options.TracesSampleRate = 1.0 - options.TracesSampler = nil + case "sentry", "otel": // noop default: return nil, fmt.Errorf("invalid value for TracesInstrumenter (supported are 'sentry' and 'otel'): %q", options.Instrumenter) } diff --git a/otel/span_processor.go b/otel/span_processor.go index d32e2b55b..bc57b8197 100644 --- a/otel/span_processor.go +++ b/otel/span_processor.go @@ -46,11 +46,11 @@ func (ssp *sentrySpanProcessor) OnStart(parent context.Context, s otelSdkTrace.R sentrySpanMap.Set(otelSpanID, span) } else { - traceParentContext := getTraceParentContext(parent) + sampled := getSampled(parent, s) transaction := sentry.StartTransaction( parent, s.Name(), - sentry.WithSpanSampled(traceParentContext.Sampled), + sentry.WithSpanSampled(sampled), ) transaction.SpanID = sentry.SpanID(otelSpanID) transaction.TraceID = sentry.TraceID(otelTraceID) @@ -112,12 +112,17 @@ func flushSpanProcessor(ctx context.Context) error { return nil } -func getTraceParentContext(ctx context.Context) sentry.TraceParentContext { +func getSampled(ctx context.Context, s otelSdkTrace.ReadWriteSpan) sentry.Sampled { traceParentContext, ok := ctx.Value(sentryTraceParentContextKey{}).(sentry.TraceParentContext) - if !ok { - traceParentContext.Sampled = sentry.SampledUndefined + if ok { + return traceParentContext.Sampled } - return traceParentContext + + if s.SpanContext().IsSampled() { + return sentry.SampledTrue + } + + return sentry.SampledFalse } func updateTransactionWithOtelData(transaction *sentry.Span, s otelSdkTrace.ReadOnlySpan) { diff --git a/otel/span_processor_test.go b/otel/span_processor_test.go index 3154b4e54..8bc1e64ba 100644 --- a/otel/span_processor_test.go +++ b/otel/span_processor_test.go @@ -41,7 +41,7 @@ func emptyContextWithSentry() context.Context { Environment: "testing", Release: "1.2.3", EnableTracing: true, - TracesSampleRate: 1.0, + TracesSampleRate: 0.0, // we want to ensure otel's sampling decision (AlwaysSample) is used instead Transport: &TransportMock{}, }) hub := sentry.NewHub(client, sentry.NewScope())