question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom TracesSampler ignores sampling decision from sentry-trace header

See original GitHub issue

Package

Sentry.AspNetCore

.NET Flavor

.NET Core

.NET Version

6.0.0

OS

Any

SDK Version

3.17.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

Set up an ASP.NET Core application, include .UseSentryTracing(), and add a custom TracesSampler:

webBuilder.UseSentry(o =>
{
    o.TracesSampler = ctx =>
    {
        return 1;
    }
})

Run it, make a request using Postman (or similar tool), and include the sentry-trace HTTP request header:

sentry-trace: 00000000000000000000000000000000-0000000000000000-0

The -0 at the end indicates the transaction should not be sampled.

Expected Result

The transaction should not be sent to Sentry.

Actual Result

The transaction is sent to Sentry anyway, because the TracesSampler return value overrides the value in the sentry-trace header.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattjohnsonpintcommented, Jun 4, 2022

OK. Then nothing to do here. Closing as works as designed. Thanks for the clarity.

1reaction
bruno-garciacommented, Jun 4, 2022

The background story on why the sampler callback always runs (even if the sentry-trace has a sampled transaction) is that otherwise there’s no way for a backend to control the volume if it gets overwhelmed by incoming transactions initiated by a front end. That said, I agree it’s a pitfall, and the only thing done, to my knowledge, to hedge the risk of users falling into this issue, was to add to our docs in all sample code snippets that users should peek into the parent sampling decision if they care about that, examples:

More context:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guidelines for Performance Monitoring
Unlike with b3 headers, a sentry-trace header should never consist solely of a sampling decision, with no traceid or spanid values. There are...
Read more >
Sampling for ASP.NET
If TracesSampler is defined, its decision will be used. It can choose to keep or ignore any parent sampling decision, use the sampling...
Read more >
sentry - Go Packages
A SamplingContext is passed to a TracesSampler to determine a sampling decision. TODO(tracing): possibly expand SamplingContext to include custom / user- ...
Read more >
Technical distributed tracing details
Technical details of New Relic's distributed tracing, including limits, explanation of sampling, trace data structure, and trace storage.
Read more >
sentry/types@7.62.0
Function to compute tracing sample rate dynamically and filter unwanted traces. Tracing is enabled if either this or tracesSampleRate is defined. If both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found