Skip to content

Missing Parent in SamplingContext when using TracesSampler with Gin #1258

@boyski33

Description

@boyski33

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

26.3.1

Go version

1.25.1

Are you using Go Modules?

yes

Steps to reproduce

I have the following config in a Go service using Gin with the proper middleware:

	err := sentry.Init(sentry.ClientOptions{ 
		EnableTracing: true,
		TracesSampler: func(ctx sentry.SamplingContext) float64 {
			if ctx.Parent != nil && ctx.Parent.Sampled != sentry.SampledUndefined {
				return 1.0
			}
			return 0.1 // always this
		},
	})

This service is called by another upstream service also using Sentry with the following HTTP client:

http.Client{
		Transport: sentryhttpclient.NewSentryRoundTripper(nil),
	}

The traces sampling rate for the upstream service is set to 1.0. However, the parent sampling is ignored completely because there is no parent set on the SamplingContext. When using TracesSampleRate instead, the trace is sampled correctly - I'm getting the following debug log: "Using sampling decision from parent: SampledTrue". Which means the tracing headers are parsed correctly, but the parent remains unset on the context.

Is there any other way to have a custom sampler function which is able to inherit traces from its parent?

Expected result

The sampling decision is inherited from the upstream service when using a TracesSampler function. Getting the following debug log: [Sentry] 2026/04/09 15:50:58 Dropping transaction: TracesSampler returned rate: 0.100000.

Actual result

The Parent span is nil in the SamplingContext, so there is no way to inherit the sampling decision from the upstream service. Random sampling is used instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions