Pluggable Integrations

Pluggable integrations are integrations that can be additionally enabled to provide specific features. They're documented so you can understand what they do and enable them, if needed.

Install

To enable pluggable integrations, install the package @sentry/integrations.

Copied
npm install --save @sentry/integrations

Configure

After installation, you can import the integration and provide a new instance with your config to the integrations option.

Copied
import { CaptureConsole } from "@sentry/integrations";

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

Core

CaptureConsole

Import name: CaptureConsole

This integration captures all Console API calls and redirects them to Sentry using captureMessage call. It then re-triggers to preserve default native behavior.

Available options:

Copied
{
  levels: string[]; // an array of methods that should be captured, defaults to ['log', 'info', 'warn', 'error', 'debug', 'assert']
}

Dedupe

Import name: Dedupe

This integration deduplicates certain events. It can be helpful if you're receiving many duplicate errors. Be aware that we will only compare stack traces and fingerprints.

Debug

Import name: Debug

This integration allows you to inspect the contents of the processed event and hint object that will be passed to beforeSend or beforeSendTransaction. It will always run as the last integration, no matter when it was registered.

Note that this is different than setting debug: true in your Sentry.init options, which will enable debug logging in the console.

Available options:

Copied
{
  debugger: boolean; // trigger DevTools debugger instead of using console.log
  // stringify event before passing it to console.log
  stringify: boolean;
}

ExtraErrorData

Import name: ExtraErrorData

This integration extracts all non-native attributes from the error object and attaches them to the event as the extra data.

Available options:

Copied
{
  // limit of how deep the object serializer should go. Anything deeper than limit will
  // be replaced with standard Node.js REPL notation of [Object], [Array], [Function] or
  // a primitive value. Defaults to 3.
  depth: number;
}

RewriteFrames

Import name: 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 make it work. For example, C:\\Program Files\\Apache\\www won't work, however, /Program Files/Apache/www will.

Copied
import * as Sentry from "@sentry/node";
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;
    }
  )],
});

Usage Examples

For example, if the full path to your file is /www/src/app/file.js:

UsagePath in Stack TraceDescription
RewriteFrames()app:///file.jsThe default behavior is to replace the absolute path, except the filename, and prefix it with the default prefix (app:///).
RewriteFrames({prefix: 'foo/'})foo/file.jsPrefix foo/ is used instead of the default prefix app:///.
RewriteFrames({root: '/www'})app:///src/app/file.jsroot is defined as /www, so only that part is trimmed from beginning of the path.

Node-specific

Undici

(New in version 7.46.0)

Import name: Sentry.Integrations.Undici

Instruments outgoing HTTP requests made with undici and Node 18's Node Fetch by adding breadcrumbs and spans.

Supports Undici v4.7.0 or higher and requires Node v16.7.0 or higher. There have been reported issues with Node.js v19 and the Undici integration so we recommend you use an LTS version of Node.js with this integration.

Available options:

Copied
{
  /**
   * If breadcrumbs should be created for outgoing requests.
   * Defaults to true.
   */
  breadcrumbs?: boolean;
  /**
   * Function determining whether or not to create spans to track outgoing requests to the given URL.
   * By default, spans will be created for all outgoing requests.
   */
  shouldCreateSpanForRequest?: (url: string) => boolean;
}

To change what requests get the sentry-trace and baggage headers attached (for use in distributed tracing), use the top level tracePropagationTargets option.

Copied
Sentry.init({
  tracePropagationTargets: ["my-site-url.com"],
});

Frameworks

tRPC Middleware

(New in version 7.48.0)

The Sentry tRPC middleware helps make sure your transactions related to RPCs are well-named. Additionally, it can attach RPC input via the attachRpcInput option.

Copied
import { initTRPC } from "@trpc/server";
import * as Sentry from "@sentry/node";

const t = initTRPC.context().create();
const sentryMiddleware = t.middleware(
  Sentry.Handlers.trpcMiddleware({
    attachRpcInput: true,
  })
);

const sentrifiedProcedure = t.procedure.use(sentryMiddleware);
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").