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.

Performance Monitoring using Sentry, Serilog, and AspNetCore

See original GitHub issue

Is 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

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
patrickklaerencommented, Apr 30, 2023

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:

builder.WebHost.UseSentry(d =>
{
    d.Dsn = // DSN;
    // And other configuration
});

Log.Logger = new LoggerConfiguration()
    .WriteTo.Sentry()
    .CreateLogger();

builder.Host.UseSerilog();

var app = builder.Build();
app.UseSerilogRequestLogging();
app.UseRouting();
app.UseSentryTracing();

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.

1reaction
bruno-garciacommented, Jul 26, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serilog | Sentry Documentation
Sentry provides an integration with Serilog through the Sentry.Serilog NuGet package . Installation. Add the Sentry dependency: Package Manager
Read more >
Set Up Performance for ASP.NET Core
With performance monitoring, Sentry tracks your software performance, measuring metrics like throughput and latency, and displaying the impact of errors ...
Read more >
Integrating Sentry with ASP.NET Core - YouTube
Quick demo on how to integrate the new (preview) SDK of Sentry. ... How Structured Logging With Serilog Can Make Your Life Easier....
Read more >
Logging to Sentry in ASP.NET Core | by Martin Cerruti | Medium
Sentry uses Raven to do its error reporting. For .NET Core, a package named RavenSharp.Core is available on NuGet. It's worth noting that...
Read more >
Sentry.Serilog 3.0.0-alpha.9
Official Serilog integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.
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