sentry-dotnet
sentry-dotnet copied to clipboard
Align SDK with docs regarding session update for dropped events
Problem Statement
We've updated the docs (https://github.com/getsentry/develop/pull/551) to explain how we would like to handle event filter order, updating of sessions for dropped events and sending of session updates. We should check if we're aligned and adapt if necessary. Here's the issue from the Java SDK where all of this started: https://github.com/getsentry/sentry-java/issues/1916
Solution Brainstorm
See https://github.com/getsentry/develop/pull/551
https://develop.sentry.dev/sdk/sessions/#filter-order
What this really needs to check is that in all paths, if an unhandled exception causes the session to become unhealthy, that we always update the session. If, for example, we set SentryOptions.SampleRate = 0.0001
and the sessions was unhealthy, we'd still want to send a session update.
https://develop.sentry.dev/sdk/sessions/#session-update-filtering
https://develop.sentry.dev/sdk/sessions/#filter-order
Most this happens in SentryClient.DoSendEvent
in the .NET SDK.
We don't currently do things in the same order as Python then.
Python Order
- Check for ignored exception types (a.k.a
ignore_errors
)- Apply scoped
event_processor
(a.k.aerror_processor
)- Apply global
event_processor
- Apply
before_send
- Update the session if an event made it this far
- Apply sampling rate
Current order in .NET:
- Apply sampling rate
- Check for ignored exception types (a.k.a ignore_errors) - ApplyExceptionFilters in .NET
- Apply scoped event_processor (a.k.a error_processor)
- Apply global event_processor
- Apply before_send Update the session if an event made it this far ???
Questions
I'm not sure what is meant by "Update the session if an event made it this far" in the issue description.
In .NET, if an event has an error then we end the session or increment the error count in Hub.CaptureEventInternal
, just before SentryClient.DoSendEvent
gets called:
var hasTerminalException = evt.HasTerminalException();
if (hasTerminalException)
{
// Event contains a terminal exception -> end session as crashed
_options.LogDebug("Ending session as Crashed, due to unhandled exception.");
actualScope.SessionUpdate = _sessionManager.EndSession(SessionEndStatus.Crashed);
}
else if (evt.HasException())
{
// Event contains a non-terminal exception -> report error
// (this might return null if the session has already reported errors before)
actualScope.SessionUpdate = _sessionManager.ReportError();
}
Is that "updating the session"? I'm not sure.
The SessionUpdate
created above gets included in the Envelope
along with the Event
when the Event
gets sent after all of the other stuff in SentryClient.DoSendEvent
... so that's when it gets sent to Sentry. Is that "updating the session"?
@bruno-garcia or @bitsandfoxes it would be good to get your steer here.
btw: I've moved the sampling decision after all the exception/event processors already (see the related PR).