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

Fixed Sentry SDK has not been initialised when using ASP.NET Core, Serilog and OpenTelemetry #2911

Merged
merged 6 commits into from Nov 28, 2023

Conversation

jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Nov 28, 2023

Resolves #2738

Problem

When using Sentry in an ASP.NET Core application, using SeriLog for logging and OpenTelemetry for tracing, the SentrySpanProcessor would throw an exception:

throw new InvalidOperationException(
"The Sentry SDK has not been initialised. To use Sentry with OpenTelemetry tracing you need to " +
"initialize the Sentry SDK.");

Solution

When the logging backend is replaced by SeriLog, SentrySdk.CurrentHub doesn't get initialized until after TracerProviderBuilderExtensions.AddSentry gets run. I don't fully understand all the mechanics, to be honest - as far as I can tell, our ConfigureLogging code does actually get called, then it gets nuked by the SeriLog initialization, and finally our SDK gets initialized in by the SentryStartupFilter.

In any event, retrieving an IHub from DI rather than pulling it off the SentrySdk static class ensures we are always able to resolve this (regardless of whether the MEL backend has been replaced or not).

I'd love a better explanation of what's going on here, if anyone else can provide one.

Backport

@bruno-garcia bruno-garcia changed the title Fixed Sentry SDK has not been initialised when using ASP.NET Core, SeriLog and OpenTelemetry Fixed Sentry SDK has not been initialised when using ASP.NET Core, Serilog and OpenTelemetry Nov 28, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
@jamescrosswell jamescrosswell merged commit 91724e3 into main Nov 28, 2023
20 checks passed
@jamescrosswell jamescrosswell deleted the fix/sentry_not_initialized_2738 branch November 28, 2023 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants