Skip to content

Commit e1cba57

Browse files
authored
feat(js sdks): Add addGlobalEventProcessor to Event Processors page (#5803)
This adds the top-level `addGlobalEventProcessor` method to the Enriching Events -> Event Processors page alongside `addEventProcessor`. Note that though this page is in the `common` section, it only applies to the JS-based SDKs (browser, node, and react native), as they are the only ones not included in the `notSupported` list.
1 parent 4ee1b20 commit e1cba57

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/platforms/common/enriching-events/event-processors.mdx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Event Processors
33
sidebar_order: 300
4-
description: "Learn more about how you can add your own `eventProcessor` on the current scope."
4+
description: "Learn more about how you can add your own event processors globally or to the current scope."
55
notSupported:
66
- android
77
- apple
@@ -22,27 +22,45 @@ notSupported:
2222
- unreal
2323
---
2424

25-
With `eventProcessors` you can hook into the process of enriching the event with additional data. You can add your own `eventProcessor` on the current scope. The difference between `beforeSend` and `eventProcessors` is that `eventProcessors` run on the scope level whereas `beforeSend` runs globally, no matter which scope you're in.
26-
Also, `eventProcessors` optionally receive the hint (see: <PlatformLink to="/configuration/filtering/#using-hints">hints</PlatformLink>).
25+
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`, there are two key differences:
26+
27+
- `beforeSend` is guaranteed to be run last, after all other event processors, which means it gets 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.
28+
- While `beforeSend` and processors added with `Sentry.addGlobalEventProcessor` run globally, regardless of scope, processors added with `scope.addEventProcessor` only run on events captured while that scope is active.
29+
30+
Both `beforeSend` and event processors are passed two arguments, the event itself and <PlatformLink to="/configuration/filtering/#using-hints">a `hint` object</PlatformLink> containing extra metadata.
31+
32+
Event processors added to the global scope will run on every event sent after they are added.
2733

2834
```javascript
29-
// This will be set globally for every succeeding event send
3035
Sentry.configureScope(function(scope) {
3136
scope.addEventProcessor(function(event, hint) {
3237
// Add anything to the event here
33-
// returning null will drop the event
38+
// returning `null` will drop the event
3439
return event;
3540
});
3641
});
3742

38-
// Using withScope, will only call the event processor for all "sends"
39-
// that happen within withScope
43+
// You can do the same thing using `addGlobalEventProcessor`
44+
Sentry.addGlobalEventProcessor(function(event, hint) {
45+
// Add anything to the event here
46+
// returning `null` will drop the event
47+
return event;
48+
});
49+
```
50+
51+
Event processors added to a local scope using `withScope` only apply to events captured inside that scope.
52+
53+
```javascript
4054
Sentry.withScope(function(scope) {
4155
scope.addEventProcessor(function(event, hint) {
4256
// Add anything to the event here
43-
// returning null will drop the event
57+
// returning `null` will drop the event
4458
return event;
4559
});
60+
// The event processor will apply to this event
4661
Sentry.captureMessage("Test");
4762
});
63+
64+
// The event processor will NOT apply to this event
65+
Sentry.captureMessage("Test2");
4866
```

0 commit comments

Comments
 (0)