SDK Fingerprinting

In supported SDKs, you can override Sentry's default grouping that passes the fingerprint attribute as an array of strings. The length of a fingerprint's array is not restricted. This works similarly to the fingerprint rules functionality, which is always available and can achieve similar results.

Basic Example

In the most basic case, values are passed directly:

Copied
import io.sentry.Sentry;
import java.sql.SQLException;
import java.util.Arrays;

Sentry.init(options -> {
    options.setBeforeSend((event, hint) -> {
        if (event.getThrowable() instanceof SQLException) {
            event.setFingerprints(Arrays.asList("database-connection-error"));
        }
        return event;
    });
});

You can use variable substitution to fill dynamic values into the fingerprint generally computed on the server. For instance, the value {{ default }} can be added to add the entire normally generated grouping hash into the fingerprint. These values are the same as for server-side fingerprinting. See Variables for more information.

Group Errors With Greater Granularity

Your application queries a Remote Procedure Call Model (RPC) interface or external Application Programming Interface (API) service, so the stack trace is generally the same (even if the outgoing request is very different).

The following example will split up the default group Sentry would create (represented by {{ default }}) further, taking some attributes on the error object into account:

Copied
import io.sentry.Sentry;
import java.util.Arrays;
import java.lang.Exception;

class MyRpcException extends Exception {
    private final String function;
    private final int httpStatusCode;

    public MyRpcException(String function, int httpStatusCode) {
        this.function = function;
        this.httpStatusCode = httpStatusCode;
    }

    public String getFunction() {
        return function;
    }

    public int getHttpStatusCode() {
        return httpStatusCode;
    }
}

Sentry.init(options -> {
    options.setBeforeSend((event, hint) -> {
        if (event.getThrowable() instanceof MyRpcException) {
            MyRpcException exception = (MyRpcException) event.getThrowable();
            event.setFingerprints(
                    Arrays.asList(
                            "{{ default }}",
                            exception.getFunction(),
                            String.valueOf(exception.getHttpStatusCode())
                    ));
        }
        return event;
    });
});

Group Errors More Aggressively

A generic error, such as a database connection error, has many different stack traces and never groups together.

The following example will completely overwrite Sentry's grouping by omitting {{ default }} from the array:

Copied
import io.sentry.Sentry;
import java.sql.SQLException;
import java.util.Arrays;

Sentry.init(options -> {
    options.setBeforeSend((event, hint) -> {
        if (event.getThrowable() instanceof SQLException) {
            event.setFingerprints(Arrays.asList("database-connection-error"));
        }
        return event;
    });
});
You can edit this page on GitHub.