Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not obvious DSN settings Serilog and ASP .NET Core #1223

Closed
olsh opened this issue Sep 29, 2021 · 3 comments
Closed

Not obvious DSN settings Serilog and ASP .NET Core #1223

olsh opened this issue Sep 29, 2021 · 3 comments

Comments

@olsh
Copy link
Contributor

olsh commented Sep 29, 2021

If you use both Sentry.AspNetCore and Sentry.Serilog and set DSN with the Serilog integration, Sentry doesn't work.
So, to fix it, you should configure Sentry with UseSentry() from ASP .NET Core integration package.

It's kind of not obvious, probably examples and the methods (UseSentry) comments should be updated.

Environment

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

Which SDK and version?
Sentry.AspNetCore 3.9.3
Sentry.Serilog 3.9.3

Steps to Reproduce

  1. Create default ASP.NET Core 3.1 Project
  2. Use the following code in Program.cs
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>()
                        .UseSerilog((_, c) =>
                            c.Enrich
                                .FromLogContext()
                                .WriteTo.Sentry("PUT_YOUR_DSN_HERE"))
                        .UseSentry();
                });
        }

        public static void Main(string[] args)
        {
            CreateHostBuilder(args)
                .Build()
                .Run();
        }
  1. Try to throw an exception somewhere

Expected Result

Sentry received the error

Actual Result

Sentry doesn't receive the error

@bruno-garcia bruno-garcia added Bug Something isn't working Documentation labels Sep 29, 2021
@bruno-garcia
Copy link
Member

Thanks for raising @olsh. I agree it's confusing. In fact, it's also not ideal right now for a few reasons.

Technically the 'right' way would be to add the DSN to both of them. That is, if there's a crash while bootstrapping the ASP.NET Core host after the logging infra started, only if Serilog had the DSN that crash would be captured. That results in the SDK having to be initialized twice (through the Serilog integration then again after that through ASP.NET Core integration).

Things were built in a way that at least work even after reinitialization but it does mean that any callback (i.e: BeforeSend or eventProcessor) would need to be set twice which is far from sub-optimal. I had this challenge also on NuGet Trends and identified the need to improve this. There I left all config in appsettings.json/env var and I defined the DSN twice.

Other than documenting this behavior, and suggesting best practices I'm not sure the path forward. Since these are two different packages, disconnected with different configuration options, etc.

Some somewhat related issues are: #1001 #257 #1137

@mattjohnsonpint
Copy link
Contributor

So, if I understand correctly, this isn't really a bug but rather a pitfall that needs to be either better documented or to have a new design.

@bitsandfoxes
Copy link
Contributor

Considering this closed as part of #2928

@github-project-automation github-project-automation bot moved this to Done in GDX Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Archived in project
Development

No branches or pull requests

5 participants