diff --git a/CHANGELOG.md b/CHANGELOG.md index 691981868c..df138d36ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- Fixed null IServiceProvider in anonymous routes with OpenTelemetry ([#3401](https://github.com/getsentry/sentry-dotnet/pull/3401)) + ### Dependencies - Bump CLI from v2.31.2 to v2.32.1 ([#3398](https://github.com/getsentry/sentry-dotnet/pull/3398)) diff --git a/src/Sentry.AspNetCore/ScopeExtensions.cs b/src/Sentry.AspNetCore/ScopeExtensions.cs index a8e33677a7..dcddf56ded 100644 --- a/src/Sentry.AspNetCore/ScopeExtensions.cs +++ b/src/Sentry.AspNetCore/ScopeExtensions.cs @@ -38,7 +38,10 @@ public static void Populate(this Scope scope, HttpContext context, SentryAspNetC if (options.SendDefaultPii && !scope.HasUser()) { - var userFactory = context.RequestServices.GetService(); + // Although the compiler suggests context.RequestServices cannot be null, in practice it can be, so we + // have a null check here. + // See: https://github.com/getsentry/sentry-dotnet/issues/3395 + var userFactory = context.RequestServices?.GetService(); var user = userFactory?.Create(); if (user != null)