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.

TracesSampler does not contain a path/name

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? Sentry 3.0.3, .Net 3.1

Steps to Reproduce

I just upgraded to 3.0.3 and was going to use the performance monitor feature. It worked great, but unfortunately not the TracesSampler that I wanted to use to filter out calls to /healthcheck. The documentation is not correct because the CustomSamplingContext is not a string as in the example here: https://docs.sentry.io/platforms/dotnet/performance/sampling/.

I used the following code in Program.cs. The transaction name seems to be prefixed with GET and I couldn’t find a property with just the path.

options.TracesSampler = context =>
{
    var ctx = context.TransactionContext;
    return ctx.Name switch
    {
        // The health check endpoint is just noise - drop all transactions
        "GET /healthcheck" => 0.0,

        // Default sample rate
        _ => null
    };
};

That would still have been fine, but in my case the name was Unknown Route. It seems the transaction name is set after the TracesSampler is called. The code in Startup.cs file looks something like below.

app.UseRouting();
app.UseSentryTracing();
app.UseCors();

app.UseEndpoints(endpoints =>
{
    endpoints.Map("/healthcheck", _ => Task.CompletedTask);
    endpoints.MapControllers();
});

If I move UseSentryTracing to below UseEndpoints it doesn’t call TracesSampler at all.

Am I missing something or is it a bug?

Expected Result

I expected TracesSampler to be called with a context that contains the path of the call in order to avoid sending transactions that is not relevant.

Actual Result

TracesSampler was called with a context where the transaction name was Unknown route.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
bruno-garciacommented, Feb 10, 2021

Sounds like we should add this to the docs @Tyrrrz

1reaction
Tyrrrzcommented, Feb 12, 2021

That should be possible to do with dynamic sampling already, I think. You can implement it in such way that it counts how many times it was called in the past minute and either returns 1.0 (sample in) or 0.0 (sample out). Something like this:

UseSentry(options =>
{
     var lastTransanctionTimestamp = DateTimeOffset.MinValue;
     var transactionCount = 0;

     options.TracesSampler = ctx =>
     {
          var now = DateTimeOffset.Now;
          if (now.Minute != lastTransanctionTimestamp.Minute || now - lastTransanctionTimestamp > TimeSpan.FromMinutes(1))
          {
                transactionCount = 0;
          }

          var sampleRate = transactionCount < 50 ? 1.0 : 0.0;
          
          lastTransanctionTimestamp = now;
          transactionCount++;

          return sampleRate;
     }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatic Instrumentation for Browser JavaScript
The BrowserTracing integration creates a new transaction for each page load and navigation event, and creates a child span for every XMLHttpRequest or...
Read more >
Automatic Instrumentation for Ember
Learn what transactions are captured after tracing is enabled.
Read more >
sentry - Go Packages
Package sentry is the official Sentry SDK for Go. Use it to report errors and track application performance through distributed tracing. For ...
Read more >
sentry - Go Packages
EventID is a hexadecimal string representing a unique uuid4 for an Event. An EventID must be 32 characters long, lowercase and not have...
Read more >
Guidelines for Performance Monitoring
This document covers how SDKs should add support for Performance Monitoring with Distributed Tracing . This should give an overview of the APIs...
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