Pluggable Integrations

Learn more about pluggable integrations: HttpClient and RewriteFrames, which are snippets of code that augment functionality for specific applications and/or frameworks.

The below pluggable integrations are snippets of code that augment functionality for specific applications and/or frameworks. Read on to understand what they do and how to enable them.

Install the @sentry/integrations package and provide a new instance with your config to the integrations option. Include the plugin after the SDK has been loaded.

For example:

Copied
import * as Sentry from '@sentry/react-native';
import {Dedupe as DedupeIntegration} from '@sentry/integrations';

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [new DedupeIntegration()],
});

Alternatively, you can add integrations lazily via Sentry.addIntegration(). This is useful if you only want to enable an integration in a specific environment or if you want to lazy-load an integration. For all other cases, we recommend you use the integrations option.

Copied
import * as Sentry from '@sentry/react-native';
import {Dedupe as DedupeIntegration} from '@sentry/integrations';

Sentry.init({
  integrations: [],
});

Sentry.addIntegration(new DedupeIntegration());

(New in version 5.3.0)

Import name: Sentry.Integrations.HttpClient

This integration captures errors on failed requests from Fetch and XHR and attaches request and response information.

By default, error events don't contain header or cookie data. You can change this behavior by setting the sendDefaultPii option to true.

Available options:

Copied
import * as Sentry from '@sentry/react-native';
import {HttpClient as HttpClientIntegration} from '@sentry/integrations';

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [
    new HttpClientIntegration({
      // This array can contain tuples of `[begin, end]` (both inclusive),
      // single status codes, or a combination of both.
      // default: [[500, 599]]
      failedRequestStatusCodes: [[500, 505], 507],

      // This array can contain Regexes, strings, or a combination of both.
      // default: [/.*/]
      failedRequestTargets: ['http://example.com/api/test', /(staging\.)?mypage\.com/],
    }),
  ],

  // This option is required for capturing headers and cookies.
  sendDefaultPii: true,
});

Import name: Sentry.Integrations.RewriteFrames

This integration allows you to apply a transformation to each frame of the stack trace. In the streamlined scenario, it can be used to change the name of the file frame it originates from, or it can be fed with an iterated function to apply any arbitrary transformation.

On Windows machines, you have to use Unix paths and skip the volume letter in the root option to enable it. For example, C:\\Program Files\\Apache\\www won’t work, however, /Program Files/Apache/www will.

Available options:

Copied
import * as Sentry from "@sentry/react-native";
import { RewriteFrames as RewriteFramesIntegration } from "@sentry/integrations";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [new RewriteFramesIntegration(
    {
      // root path that will be stripped from the current frame's filename by the default iteratee if the filename is an absolute path
      root: string;

      // a custom prefix that will be used by the default iteratee (default: `app://`)
      prefix: string;

      // function that takes the frame, applies a transformation, and returns it
      iteratee: (frame) => frame;
    }
  )],
});

For example, if the full path to your file is bundles/bundle1.js:

UsagePath in Stack TraceDescription
RewriteFrames()app:///bundle1.jsThe default behavior is to replace the absolute path, minus the filename, and add the default prefix (app:///).
RewriteFrames({root: '/bundles'})app:///bundle1.jsThe root is defined as /bundles. Only that part is trimmed from the beginning of the path.
RewriteFrames({iteratee: () => {} })app:///bundle.jsThe number at the end of a bundle can be a file hash. This is common in Expo apps. You can remove it in the iteratee callback.

Import name: Sentry.Integrations.ContextLines

This integration adds source code from inline JavaScript of the current page's HTML (e.g. JS in <script> tags) to stack traces of captured errors. It can't collect source code from assets referenced by your HTML (e.g. <script src="..." />).

The ContextLines integration is useful when you have inline JS code in HTML pages that can't be accessed by Sentry's backend, for example, due to a login-protected page.

Copied
import * as Sentry from '@sentry/browser';

Sentry.init({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  integrations: [Sentry.contextLinesIntegration()],
});
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").