SDK Fingerprinting

In supported SDKs, you can override the Sentry default grouping passing the fingerprint attribute an array of strings. This works similar to the server side functionality which is always available and can achieve similar results.

Basic Example

In the most basic of cases, values are passed directly:

Copied
function makeRequest(method, path, options) {
  return fetch(method, path, options).catch(function(err) {
    Sentry.withScope(function(scope) {
      // group errors together based on their request and response
      scope.setFingerprint([method, path, String(err.statusCode)]);
      Sentry.captureException(err);
    });
  });
}

You can use variable substitution to fill dynamic values into the fingerprint that are normally 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 an RPC interface or external 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
class MyRPCError extends Error {
  constructor(message, functionName, errorCode) {
    super(message);

    // The name of the RPC function that was called (e.g. "getAllBlogArticles")
    this.functionName = functionName;

    // For example a HTTP status code returned by the server.
    this.errorCode = errorCode;
  }
}

Sentry.init({
  ...,
  beforeSend: function(event, hint) {
    const exception = hint.originalException;

    if (exception instanceof MyRPCError) {
      event.fingerprint = [
        '{{ default }}',
        String(exception.functionName),
        String(exception.errorCode)
      ];
    }

    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 just completely overwrite Sentry's grouping by omitting {{ default }} from the array:

Copied
class DatabaseConnectionError extends Error {}

Sentry.init({
  ...,
  beforeSend: function(event, hint) {
    const exception = hint.originalException;

    if (exception instanceof DatabaseConnectionError) {
      event.fingerprint = ['database-connection-error'];
    }

    return event;
  }
});
You can edit this page on GitHub.