Skip to content

Commit 127444d

Browse files
committed
document beforeSendMetric
1 parent b8b8e30 commit 127444d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

platform-includes/metrics/options/javascript.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
The Sentry JavaScript SDK provides several options to configure how metrics are captured and sent to Sentry.
22

3+
### Filtering and Modifying Metrics
4+
5+
Use the `beforeSendMetric` callback to filter or modify metrics before they're sent to Sentry. This is useful for:
6+
7+
- Removing sensitive data from metric attributes
8+
- Dropping metrics you don't want to send
9+
- Adding or modifying attributes
10+
11+
The callback receives a metric object and must return either a modified metric or `null` to drop it.
12+
13+
```javascript
14+
Sentry.init({
15+
// ...
16+
beforeSendMetric: (metric) => {
17+
// Drop metrics with specific attributes
18+
if (metric.attributes?.dropMe === true) {
19+
return null;
20+
}
21+
22+
// Modify metric attributes
23+
metric.tags = {
24+
...metric.tags,
25+
processed: true,
26+
};
27+
28+
return metric;
29+
},
30+
});
31+
```
32+
333
### Disabling Metrics
434
535
If you want to disable metrics collection entirely, you can do so by disabling the `_experimental.enableMetrics` flag:

0 commit comments

Comments
 (0)