Skip to content

[otel] integration should sync sampling decision to/from otel in the "parentless" case #678

Closed
@costela

Description

@costela

Summary

Currently, using something like the following seems to lead to unexpected results:

	trace.NewTracerProvider(
		trace.WithSampler(
			trace.ParentBased(
				trace.TraceIDRatioBased(cfg.SampleRate),
			),
		),
		trace.WithSpanProcessor(sentryotel.NewSentrySpanProcessor()),
	)

The decision from the otel sampler is ignored by sentry, which then samples again based on its own logic, leaving the otel and sentry samplig decisions disconnected.

Using only sentry.ClientOptions.TracesSampler is not an option for similar reasons: its decision does not get passed back to otel, so otel's Span.IsSampled() returns an unrelated value to sentry's decision (so that you end up - e.g. - using a traceID in exemplars and logs that never actually got sent to sentry, or the other way around).

The otel and sentry sides seem to agree in the case where a parent span could be found.

Am I holding it wrong? 😅

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

Sentry should respect OTel's span.IsSampled() and only sample trances if and only if it is true.

(The other way around seems a bit more difficult to pull off?)

Environment

SDK

  • sentry-go 0.22.0:
  • Go version: 1.20
  • Using Go Modules? yes

Sentry

  • Using hosted Sentry in sentry.io? yes

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions