Event Processors
You can enrich events with additional data by adding your own event processors, either on the scope level or globally. Though event processors are similar to BeforeSend
and BeforeSendTransaction
, there are two key differences:
BeforeSend
andBeforeSendTransaction
are guaranteed to be run last, after all other event processors, (which means they get the final version of the event right before it's sent, hence the name). Event processors added with either of the methods below run in an undetermined order, which means changes to the event may still be made after the event processor runs.- While
BeforeSend
,BeforeSendTransaction
, and processors added withSentry.addGlobalEventProcessor
run globally, regardless of scope, processors added withScope.addEventProcessor
only run on events captured while that scope is active.
Like BeforeSend
and BeforeSendTransaction
, event processors are passed two arguments, the event itself and a hint
object containing extra metadata.
You can create your own event processors by implementing the ISentryEventProcessor
interface. You can also create custom processors for transactions by implementing the ISentryTransactionProcessor
.
using Sentry;
using Sentry.Extensibility;
public class CustomEventProcessor : ISentryEventProcessor
{
public SentryEvent? Process(SentryEvent @event)
{
// Add anything to the event here
// returning `null` will drop the event
return @event;
}
}
Processors run on every event sent once they've been added. While there are multiple ways of doing this, adding processors to the options ensures that they run with every event after initialization.
options.AddEventProcessor(new CustomEventProcessor());
If AddEventProcessor
has been added to the scope, it'll apply to both the current and the following scopes:
SentrySdk.ConfigureScope(scope => scope.AddEventProcessor(new CustomEventProcessor()));
But if an event processor has only been added to a local scope using withScope
, it'll only apply to events captured inside that scope.
SentrySdk.WithScope(scope => scope.AddEventProcessor(new CustomEventProcessor()));
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- nuget:Sentry
- Version:
- 4.4.0
- Repository:
- https://github.com/getsentry/sentry-dotnet