TracesSampler does not contain a path/name
See original GitHub issueEnvironment
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:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Sounds like we should add this to the docs @Tyrrrz
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: