Skip to content

Commit abb8582

Browse files
committed
reorganize filtering page and add transaction sampling
1 parent 0ae4b8f commit abb8582

File tree

2 files changed

+56
-26
lines changed

2 files changed

+56
-26
lines changed

src/platforms/common/configuration/filtering.mdx

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
2-
title: Filtering Events
2+
title: Filtering and Sampling Events
33
sidebar_order: 5
4-
description: "Learn more about how to filter events reported to Sentry, using either the SDK, product filtering options, or both."
4+
description: "Learn more about how to configure your SDK to filter and sample events reported to Sentry."
55
notSupported:
66
- perl
77
---
88

9-
While sending all application errors to Sentry ensures you’ll be notified in real-time when errors occur in your code, often applications generate many errors, thus many notifications. The Sentry SDKs have several configuration options you can use to filter unwanted errors from leaving your application’s runtime. In addition, sentry.io also [offers methods to filter events](/product/error-monitoring/filtering/).
9+
There are many reasons you might want to send every possible event to Sentry. While sending all errors ensures you’ll be notified in real-time when problems occur in your code, often applications generate many errors, and thus many notifications. Similarly, while transaction events give you a detailed look into every user's experience (not just those with problems), they also get sent by **every user**, and thus can pile up and eat through your quota very quickly.
1010

11-
## Configure your SDK to Filter Events
11+
To help with those problems, the Sentry SDKs have several configuration options you can use to prevent unwanted events from getting sent to Sentry, as well as ways to send only a representative sample of those you do want.. (The Sentry UI also offers methods to filter events, which you can read more about [here](/product/error-monitoring/filtering/).)
1212

13-
Configure your SDK to filter events by using the `beforeSend` callback method and configuring, enabling, or disabling integrations.
13+
## Filtering Error Events
1414

15-
### Using `before-send`
15+
Configure your SDK to filter error events by using the `beforeSend` callback method and configuring, enabling, or disabling integrations.
1616

17-
All Sentry SDKs support the `beforeSend` callback method. `before-send` is called immediately before the event is sent to the server, so it’s the final place where you can edit its data. It receives the event object as a parameter, so you can use that to modify the event’s data or drop it completely (by returning `null`) based on custom logic and the data available on the event.
17+
### Using `beforeSend`
18+
19+
All Sentry SDKs support the `beforeSend` callback method. `beforeSend` is called immediately before the event is sent to the server, so it’s the final place where you can edit its data. It receives the event object as a parameter, so you can use that to modify the event’s data or drop it completely (by returning `null`) based on custom logic and the data available on the event.
1820

1921
<PlatformContent includePath="configuration/before-send" />
2022

@@ -30,24 +32,6 @@ Typically a `hint` holds the original exception so that additional data can be e
3032

3133
When the SDK creates an event or breadcrumb for transmission, that transmission is typically created from some sort of source object. For instance, an error event is typically created from a log record or exception instance. For better customization, SDKs send these objects to certain callbacks (`before-send``before-breadcrumb` or the event processor system in the SDK).
3234

33-
#### Sampling
34-
35-
If a sample rate is defined for the SDK, the SDK evaluates whether this event should be sent as a representative fraction of events.
36-
37-
<Note><markdown>
38-
39-
The SDK sample rate is not dynamic; changing it requires re-deployment. In addition, setting an SDK sample rate limits visibility into the source of events. Setting a rate limit for your project may better suit your needs.
40-
41-
</markdown></Note>
42-
43-
When you enable sampling in your SDK, you choose a percentage of collected errors to send to Sentry. For example, to sample 25% of your events:
44-
45-
<PlatformContent includePath="configuration/sample-rate" />
46-
47-
For Sentry's Performance Monitoring, we recommend sampling your data for two reasons. First, though capturing a single trace involves minimal overhead, capturing traces for every single page load, or every single API request, has the potential to add an undesirable amount of load to your system. Second, by enabling sampling you’ll more easily prevent yourself from exceeding your organization’s [event quota](/product/accounts/quotas/).
48-
49-
When choosing a sampling rate, the goal is not to collect *too* much data, but to collect sufficient data so you can draw meaningful conclusions. If you’re not sure what rate to choose, start with a low value and gradually increase it as you learn more about your traffic patterns and volume, until you’ve found a rate that balances performance and cost concerns with data accuracy.
50-
5135
### Using Hints
5236

5337
Hints are available in two places:
@@ -98,3 +82,49 @@ In this example, the fingerprint is forced to a common value if an exception of
9882
: For breadcrumbs created from HTTP requests done via the legacy `XMLHttpRequest` API. This holds the original xhr object.
9983

10084
<PlatformContent includePath="configuration/decluttering" />
85+
86+
## Sampling Error Events
87+
88+
To send a representative sample of your errors to Sentry, set the `sampleRate` option in your SDK configuration to a number between `0` (0% of errors sent) and `1` (100% of errors sent). This is a static rate, which will apply equally to all errors. For example, to sample 25% of your errors:
89+
90+
<PlatformContent includePath="configuration/sample-rate" />
91+
92+
<Note><markdown>
93+
94+
The error sample rate is not dynamic; changing it requires re-deployment. In addition, setting an SDK sample rate limits visibility into the source of events. Setting a rate limit for your project (which only drops events when volume is high) may better suit your needs.
95+
96+
</markdown></Note>
97+
98+
<PlatformSection supported={["javascript", "node"]}><markdown>
99+
100+
## Filtering Transaction Events
101+
102+
To prevent certain transactions from being reported to Sentry, use the `tracesSampler` configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want. (It also allows you to sample different transactions at different rates.) In its simplest form, used just for filtering, it looks like this:
103+
104+
```javascript
105+
tracesSampler: samplingContext => {
106+
if ("...") {
107+
return 0; // Drop this transaction, by setting its sample rate to 0%
108+
} else {
109+
return 0.2; // Default sample rate for all others (replaces tracesSampleRate )
110+
}
111+
};
112+
```
113+
114+
<Note><markdown>
115+
116+
The `tracesSampler` and `tracesSampleRate` config options are mutually exclusive. If you define a `tracesSampler` in order to filter out certain transactions, you must also handle the case of non-filtered transactions, by returning the rate at which you'd like them sampled.
117+
118+
</markdown></Note>
119+
120+
To learn more about the `tracesSampler` option, please see [Sampling Transactions](/platforms/javascript/performance/sampling/).
121+
122+
</markdown></PlatformSection>
123+
124+
## Sampling Transaction Events
125+
126+
For Sentry's Performance Monitoring, we recommend sampling your data for two reasons. First, though capturing a single trace involves minimal overhead, capturing traces for every single page load, or every single API request, has the potential to add an undesirable amount of load to your system. Second, by enabling sampling you’ll more easily prevent yourself from exceeding your organization’s [event quota](/accounts/quotas/).
127+
128+
When choosing a sampling rate, the goal is not to collect *too* much data, but to collect sufficient data so you can draw meaningful conclusions. If you’re not sure what rate to choose, start with a low value and gradually increase it as you learn more about your traffic patterns and volume, until you’ve found a rate that balances performance and cost concerns with data accuracy.
129+
130+
To set a sample rate for your transactions, provide a number between `0` (0% of transactions sent) and `1` (100% of transactions sent) to the `tracesSampleRate` configuration option. For example, including `tracesSampleRate: 0.2` in your SDK config will cause the SDK to only send 20% of possible transaction events.

src/platforms/common/configuration/options.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ By default all types of errors are be reported (equivalent to `E_ALL`).
5353

5454
<ConfigKey name="sample-rate"><markdown>
5555

56-
Configures the sample rate as a percentage of events to be sent in the range of `0.0` to `1.0`. The default is `1.0` which means that 100% of events are sent. If set to `0.1` only 10% of events will be sent. Events are picked randomly.
56+
Configures the sample rate for error events, in the range of `0.0` to `1.0`. The default is `1.0` which means that 100% of error events are sent. If set to `0.1` only 10% of error events will be sent. Events are picked randomly.
5757

5858
</markdown></ConfigKey>
5959

0 commit comments

Comments
 (0)