Performance Monitoring using Sentry, Serilog, and AspNetCore
See original GitHub issueIs it possible to get the Sentry Tracing to work, when using the Sentry Serilog ASP Core integration Library?
Sorry to log this as a bug, it’s more of a configuration question.
Environment
On-premise - Sentry 21.7.0.dev0
.NET 5.0 Sentry.AspNetCode v3.8.2 Sentry.Serilog v3.8.2
Steps to Reproduce
Using the following in our appsettings.json file to enable TracesSampleRate:
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Sentry.Serilog" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Sentry",
"Args": {
"MinimumBreadcrumbLevel": "Debug",
"MaxBreadcrumbs": 500,
"MinimumEventLevel": "Warning",
"DSN": "http://73e3c7c0d70947c5b764751db123f89d@ourlocalonpremisesentry.lan:9000/3",
"AttachStacktrace": true,
"SendDefaultPii": true,
"IncludeActivityData": true,
"IncludeRequestPayload": true,
"TracesSampleRate": 1.0,
"Release": "Development 20210721"
}
},
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithExceptionDetails", "WithProcessId", "WithThreadId" ]
}
Running the following function does not seem to populate any Trace Data to make it’s way into the “Performance” section of Sentry.
public async Task<Customer> GetCustomer(string customerid, bool getservicesummary = false, bool usecached = false)
{
var transaction = SentrySdk.StartTransaction("get-customer-transaction", "get-customer-operation");
var span = transaction.StartChild("test-child-operation");
Customer c = null;
if (usecached && (_cache.TryGetValue("customer-" + customerid, out c)))
{
return c;
}
await _conn.OpenAsync();
try
{
// Program Logic ommitted
finally
{
await _conn.CloseAsync();
}
if (usecached) _cache.Set("customer-" + customerid, c, DateTime.Now.AddMinutes(1));
span.Finish();
transaction.Finish();
return c;
}
Other relevant Code:
.UseWindowsService()
.ConfigureWebHostDefaults(webBuilder => {
webBuilder.UseStartup<Startup>()
//.UseSentry() //UseSentry is not in use here, as we use the Serilog Integration
.UseSerilog();
});
The following is also not in use, as we rely on the Serilog integration, not the standard Sentry one.
//app.UseSentryTracing();
Expected Result
The Performance section of Sentry would show something new
Actual Result
I still see the Pinpoint problems image when navigating to the “Performance” section of Sentry
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
For anyone who comes here, after much trial and error and just observing what happens in a test application, my configuration (slimmed down) is as follows:
This does everything you’d expect it to do in terms of logging on Sentry’s side as far as I can tell (without duplicates).
Usually I am very happy with what Sentry offers for developers - but the Serilog integration definitely does not make this straight forward or obvious.
Happy to be corrected if the above is incorrect.
Thank you for raising and clarifying the steps and outcomes of the different combinations. It’s definitely going to be useful to anyone trying to init Serilog+ASP.NET Core and tracing.
I think we can improve docs and also improve the integration. As you said, have the ASP.NET Core integration, in particular tracing (if not the whole thing) be enabled when Sentry was already initialzied in the process. For example, through Serilog’s integration.