Open bruno-garcia opened 3 years ago
Idea: use weakref to track the scope at the time the exception is thrown, and associate them later.
Hello @bruno-garcia Do you guys have an idea when this enhancement will be released?
We have some standards in my organization about when we must create an entry to the logs. For us is required to create a new log entry in every write operation to the DB. After using "WithScope" to include some data/tags and create a new log entry about this operation, the following log entries include the same data (we don't want that to happen). We want to use sentry to replace our internal logger (an internal app) and our exception handler for over 100 applications (WebForms, ASP .NET 5, React). So far this issue is what is keeping us waiting to move forward with you product.
I think the simplest solution for this is to remove the call from ILogger.BeginScope
to SentrySdk.PushScope
.
And remove the ScopeLock thing after that.
Possibly this could be done and shipped as part of the version 4.0.0 of the SDK. Combined with other changes. @SimonCropp thoughts?
@Bruno-garcia do you have an estimated date for the release of version 4.x?
@CteixeiraPW We don't have a ETA yet. Is this something you're willing to send a PR?
Relates to #675
Actually, related to #1492
It would be good to get some clarity around what we want the SDK to do.
We've added a nice API to add data to an event through the instance of the exception.
To extend that to add attachments, we have the problem that attachments live on the Scope. And the code pulling data from the Exception only has SentryEvent, and no scope.
It's worth noting that the only place where exception processors get applied is here, and the scope is available there, so we could easily pass it as an additional parameter to the Process
event... that would be a breaking change (to the interface) but we could do it in a major release:
https://github.com/getsentry/sentry-dotnet/blob/5b35d8ea901225019929ff93bf7b24720f604d95/src/Sentry/SentryClient.cs#L302-L309
What would we like a [potential] new API to look like? Is is something like exception.AddAttachment(/*...*/)
?
The problem with that is presumably that if the scope is locked then we can't push and pop a scope to temporarily store the attachment on the scope while capturing the event?
The API such as WithScope doesn't work properly on ASP.NET Core due to "scope lock" which was a work around to keep breadcrumbs around even though the ILogger interface BeginScope mapped to the SDK PushScope.
The API no longer appears to include a WithScope
method. We can still manually push and pop scopes though.
The unified API also includes overloads to the public API to pass a local scope, or mutate a clone. Such as:
Sentry.CaptureException(exception, s => s.SetTag() which isn't in .NET yet since lots of use cases in .NET are done through the logger integration anyway: BeginScope and structured logging.
The API does now have support for a configure scope callback https://github.com/getsentry/sentry-dotnet/blob/76e9f660296dd23ff5d1f63e8c3f55e9815c8e6d/src/Sentry/SentrySdk.cs#L458-L459
@jamescrosswell we can keep calling into the Sentry SDK to set the scope data, we just sholdn't call PushScope
in Sentry.
We want the data they pass in, but we don't want scope isolation. There might be some side effect to this (possibly a leak in case we're just appending stuff? We have a ring buffer for breadcrumbs but other data are just maps for example)
Note that this ticket rquests the behavior that we have on ASP.NET Core already.
One idea that came up in a chat:
BeginScope
could then create a breadcrumb. The data passed as argument to BeginScope can be passed to the breadcrumb Data bag. So we can see clearly when scope was created or disposed, and the values added to it.
In this case we could pop the scope dropping all other data, but the breadcrumb would live in the parent scope
We've added a nice API to add data to an event through the instance of the exception.
To extend that to add attachments, we have the problem that attachments live on the Scope. And the code pulling data from the Exception only has SentryEvent, and no scope.
The API such as
WithScope
doesn't work properly on ASP.NET Core due to "scope lock" which was a work around to keep breadcrumbs around even though the ILogger interfaceBeginScope
mapped to the SDK PushScope. To avoid dropping these breadcrumbs. Ideally we'd simply not map BeingScope to PushScope and simply abandon "scope lock". The negative side effect here is that adding an attachment withWithScope
with a locked scope actually means the attachment never goes away, and each new call adds yet another attachment.The unified API also includes overloads to the public API to pass a local scope, or mutate a clone. Such as:
Sentry.CaptureException(exception, s => s.SetTag()
which isn't in .NET yet since lots of use cases in .NET are done through the logger integration anyway:BeginScope
and structured logging.