Skip to main content

Can I set different sample rates for different errors?

Updated over a month ago

Issue

Similarly to the tracesSampler for transactions, can I choose a different sample rate for different errors?

Applies To

  • All SaaS Customers and Self-Hosted Users

  • Error Monitoring

  • Filtering/Sampling

Resolution

The sample rate applies equally to all error events coming in. It is a random filter. For every event the SDK tries to send, we generate a random number and if it is smaller than your sample rate, the event is sent, and if it is higher the event is dropped.

We do not have a specific option to set a sample rate for different error events, but this can be accomplished with beforeSend and switch(or the equivalent in the coding language of your choice). Here is a short example that uses the event level:

function beforeSend(event) {
    try {
        switch (event.level) {
            case "error":
                if (Math.random()  0.5) {
                    return null;
                }
                break;
            case "warning":
                if (Math.random()  0.1) {
                    return null;
                }
                break;
        }
        return event;
    } catch (e) {
        return event;
    }
}
Did this answer your question?