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 null IServiceProvider in anonymous routes with OpenTelemetry #3401

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

jamescrosswell
Copy link
Collaborator

Resolves #3395

// 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<ISentryUserFactory>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. But how do we end up in a state where we cannot locate an ISentryuserFactory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we had a service collection reference, I think we'd find an ISentryUserFactory registered on it. I'm not sure what set of circumstances leads to context.RequestServices being null. That would require debugging some of the MS code, I think (or possibly the OpenTelemetry codebase).

Since, in this case, the reference will only be null when nobody is logged in, it doesn't present any difficulty to us... we leave the user context empty in this case (exactly what we want).

@bitsandfoxes bitsandfoxes merged commit 1447b55 into main Jun 5, 2024
20 checks passed
@bitsandfoxes bitsandfoxes deleted the userfactory-anonymous branch June 5, 2024 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASP.NET Core Telemetry: Failed invoking event handler in anonymous routes
2 participants