集成

了解更多关于集成如何扩展我们 SDK 的功能,以自动覆盖常见的库和环境。

Sentry SDK 使用集成来挂钩流行库的功能,以自动仪器化您的应用程序,并为您提供开箱即用的最佳数据。

集成会自动为您的应用程序添加错误仪器化、性能仪器化和/或额外的上下文信息。某些集成默认启用,但您可以禁用它们或修改其设置。

Auto EnabledErrorsTracingAdditional Context
amqplibIntegration
consoleIntegration
connectIntegration
contextLinesIntegration
dedupeIntegration
functionToStringIntegration
genericPoolIntegration
graphqlIntegration
httpIntegration
inboundFiltersIntegration
kafkaIntegration
linkedErrorsIntegration
lruMemoizerIntegration
modulesIntegration
mongoIntegration
mongooseIntegration
mysqlIntegration
mysql2Integration
nodeContextIntegration
nativeNodeFetchIntegration
onUncaughtExceptionIntegration
onUnhandledRejectionIntegration
postgresIntegration
redisIntegration
requestDataIntegration
tediousIntegration
childProcessIntegration
anrIntegration
captureConsoleIntegration
debugIntegration
dataloaderIntegration
extraErrorDataIntegration
fsIntegration
knexIntegration
localVariablesIntegration
nodeProfilingIntegration
prismaIntegration
rewriteFramesIntegration
sessionTimingIntegration
trpcMiddleware

要禁用系统集成,在调用 init() 时设置 defaultIntegrations: false

要覆盖它们的设置,请在 integrations 选项中提供带有您配置的新实例。例如,要关闭浏览器捕获控制台调用:

Copied
Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  integrations: [
    Sentry.linkedErrorsIntegration({
      limit: 7,
    }),
  ],
});

您可以在 init 调用中添加额外的集成:

Copied
import * as Sentry from "@sentry/node";

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

Sentry.addIntegration(Sentry.captureConsoleIntegration());

或者,您可以通过 Sentry.addIntegration() 添加集成。 这在您只想在特定环境中启用集成或稍后加载集成时非常有用。 对于所有其他情况,我们建议您使用 integrations 选项。

Copied
import * as Sentry from "@sentry/node";

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

如果您只想移除一个或部分默认集成,而不是通过 defaultIntegrations: false 禁用所有集成,您可以使用以下语法过滤掉不需要的集成。

此示例移除了默认启用的为事件添加面包屑的集成:

Copied
Sentry.init({
  // ...
  integrations: function (integrations) {
    // integrations will be all default integrations
    return integrations.filter(function (integration) {
      return integration.name !== "Breadcrumbs";
    });
  },
});

您也可以创建自定义集成