Skip to content

[otel] breaks sampling when used together with sentry middleware #788

Open
@costela

Description

@costela

Summary

This is a follow-up to #678, which was closed before the actual issue got resolved.

When using the otel integration for tracing, but sentry for exceptions, the sentry middleware always starts a transaction, which is then "invisible" to the otel integration (regardless of middleware ordering; more info in #679) and causes sampling decisions to diverge.

Steps To Reproduce

Initialize otel with:

trace.NewTracerProvider(
	trace.WithSampler(trace.AlwaysSample()),
	trace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
)

Initialize sentry with:

sentry.ClientOptions{
	//...
	EnableTracing:    true,
	TracesSampleRate: 0.0,
	//...
}

All traces created with otel.Tracer("").Start() will have span.IsSampled() == true, but none of them will be sent to sentry.

Switching the to NeverSample()/TracesSampleRate: 1.0 causes the opposite problem.

Expected Behavior

Both stacks would agree on sampling.

Environment

SDK

  • sentry-go version: v0.27.0
  • Go version: 1.22
  • Using Go Modules? yes

Sentry

  • Using hosted Sentry in sentry.io? yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions