Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Sentry skips User Agent parsing if context is set; SentryEvent.Context is internal #261

Closed
kanadaj opened this issue Jun 30, 2018 · 4 comments
Labels

Comments

@kanadaj
Copy link

kanadaj commented Jun 30, 2018

As said in the title, Sentry's own User Agent parser always skips parsing if there is a Context specified. In use cases like ASP.NET and ASP.NET Core, the context usually contains no real value (as the runtime and OS version is controller by the developers), so being able to set Context to null would be a boon.

In the meanwhile, for anyone who is looking into why User-Agent isn't parsed into Browser and OS, here is a quick workaround to remove server info from the context and instead have the User Agent parsed:

var sentryEvent = new SentryEvent(ex);

var contextsProperty = sentryEvent.GetType().GetProperty("Contexts");
contextsProperty.SetValue(sentryEvent, null);
@bruno-garcia
Copy link
Member

Thank you for raising the issue.
We are working on a solution.

For ASP.NET Core, we've just released a preview of a new integration which hooks into the WebHost. Development is happening here.

It's also affected by the non-rendering of User-Agent when Contexts are available but you don't need to use reflection to work around it as it has a public setter which can be modified on BeforeSend:

Here's an example of the BeforeSend hook:

https://github.com/getsentry/sentry-dotnet/blob/cf470a74995a58f0aa1a26b7bb654c21c5ed71dc/samples/Sentry.Samples.Console.Customized/Program.cs#L43

You can simply:

@event.Contexts = null;

It's unfortunate that all the Contexts interface will be unavailable but I understand the User-Agent info being at the top is the most relevant in the case of ASP.NET and ASP.NET Core.

If you have the chance to try our preview and give any feedback, I'd really appreciate it.

@kanadaj
Copy link
Author

kanadaj commented Jun 30, 2018

That looks like a very ominous version number to put on a production server, but I'll play around with it for the project we are starting on Monday :) .

The problem isn't as much of the User-Agent being on the top as having the string parsed and the browser info tagged, since without it, it's hard to spot cases where a specific browser is the cause of an issue.

It'd be preferable if the platform itself supported a combination of runtime information and user agent parsing (as well as getting those fancy widgets on the top for browser info), but that's a problem for another repository.

@bruno-garcia
Copy link
Member

Yeah I see what you are saying. Makes sense.

If User-Agent is available, the tagging as you suggested and also the widgets are shown. And additionally, the server information also available, perhaps further down the screen. This is something we have to work on Sentry itself and @billyvg will surely have a saying on this :)

True that a 0.0.1-preview1 is not something you'd want to put in production. But at the same time we need to run some tests in different apps to make sure it's good to release a 1.0 version of it.

Thank you for giving it a try, even if just in Staging or just on a new project with little load/impact it helps us a lot!

I'm online on Gitter if you have any questions: https://gitter.im/getsentry/dotnet

@bruno-garcia
Copy link
Member

We've released the new SDK which solves this issue:

https://github.com/getsentry/sentry-dotnet/releases

https://www.nuget.org/packages/Sentry

I'll close this issue but please feel free to reopen or open one in the new repository if you have any issues integrating. We'll be happy to help you moving over to the new SDK.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants