@sentry/node 9.34.0-alpha.1 → 9.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/cron/common.js +56 -0
- package/build/cjs/cron/common.js.map +1 -0
- package/build/cjs/cron/cron.js +112 -0
- package/build/cjs/cron/cron.js.map +1 -0
- package/build/cjs/cron/index.js +15 -0
- package/build/cjs/cron/index.js.map +1 -0
- package/build/cjs/cron/node-cron.js +71 -0
- package/build/cjs/cron/node-cron.js.map +1 -0
- package/build/cjs/cron/node-schedule.js +65 -0
- package/build/cjs/cron/node-schedule.js.map +1 -0
- package/build/cjs/index.js +56 -38
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/anr/index.js +238 -0
- package/build/cjs/integrations/anr/index.js.map +1 -0
- package/build/cjs/integrations/childProcess.js +100 -0
- package/build/cjs/integrations/childProcess.js.map +1 -0
- package/build/cjs/integrations/context.js +457 -0
- package/build/cjs/integrations/context.js.map +1 -0
- package/build/cjs/integrations/contextlines.js +405 -0
- package/build/cjs/integrations/contextlines.js.map +1 -0
- package/build/cjs/integrations/fs.js +2 -2
- package/build/cjs/integrations/fs.js.map +1 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js +558 -0
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +1 -0
- package/build/cjs/integrations/http/index.js +11 -7
- package/build/cjs/integrations/http/index.js.map +1 -1
- package/build/cjs/integrations/local-variables/common.js +69 -0
- package/build/cjs/integrations/local-variables/common.js.map +1 -0
- package/build/cjs/integrations/local-variables/index.js +12 -0
- package/build/cjs/integrations/local-variables/index.js.map +1 -0
- package/build/cjs/integrations/local-variables/local-variables-async.js +143 -0
- package/build/cjs/integrations/local-variables/local-variables-async.js.map +1 -0
- package/build/cjs/integrations/local-variables/local-variables-sync.js +410 -0
- package/build/cjs/integrations/local-variables/local-variables-sync.js.map +1 -0
- package/build/cjs/integrations/modules.js +135 -0
- package/build/cjs/integrations/modules.js.map +1 -0
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js +291 -0
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -0
- package/build/cjs/integrations/node-fetch/index.js +5 -4
- package/build/cjs/integrations/node-fetch/index.js.map +1 -1
- package/build/cjs/integrations/onuncaughtexception.js +134 -0
- package/build/cjs/integrations/onuncaughtexception.js.map +1 -0
- package/build/cjs/integrations/onunhandledrejection.js +89 -0
- package/build/cjs/integrations/onunhandledrejection.js.map +1 -0
- package/build/cjs/integrations/processSession.js +36 -0
- package/build/cjs/integrations/processSession.js.map +1 -0
- package/build/cjs/integrations/spotlight.js +101 -0
- package/build/cjs/integrations/spotlight.js.map +1 -0
- package/build/cjs/integrations/tracing/amqplib.js +5 -4
- package/build/cjs/integrations/tracing/amqplib.js.map +1 -1
- package/build/cjs/integrations/tracing/connect.js +4 -3
- package/build/cjs/integrations/tracing/connect.js.map +1 -1
- package/build/cjs/integrations/tracing/dataloader.js +3 -3
- package/build/cjs/integrations/tracing/dataloader.js.map +1 -1
- package/build/cjs/integrations/tracing/express.js +7 -5
- package/build/cjs/integrations/tracing/express.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/fastify-otel/index.js +3 -3
- package/build/cjs/integrations/tracing/fastify/fastify-otel/index.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/index.js +6 -6
- package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
- package/build/cjs/integrations/tracing/genericPool.js +3 -3
- package/build/cjs/integrations/tracing/genericPool.js.map +1 -1
- package/build/cjs/integrations/tracing/graphql.js +4 -3
- package/build/cjs/integrations/tracing/graphql.js.map +1 -1
- package/build/cjs/integrations/tracing/hapi/index.js +4 -3
- package/build/cjs/integrations/tracing/hapi/index.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka.js +5 -4
- package/build/cjs/integrations/tracing/kafka.js.map +1 -1
- package/build/cjs/integrations/tracing/knex.js +3 -3
- package/build/cjs/integrations/tracing/knex.js.map +1 -1
- package/build/cjs/integrations/tracing/koa.js +6 -4
- package/build/cjs/integrations/tracing/koa.js.map +1 -1
- package/build/cjs/integrations/tracing/lrumemoizer.js +2 -2
- package/build/cjs/integrations/tracing/lrumemoizer.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo.js +4 -3
- package/build/cjs/integrations/tracing/mongo.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose.js +4 -3
- package/build/cjs/integrations/tracing/mongoose.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql.js +2 -2
- package/build/cjs/integrations/tracing/mysql.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2.js +4 -3
- package/build/cjs/integrations/tracing/mysql2.js.map +1 -1
- package/build/cjs/integrations/tracing/postgres.js +4 -3
- package/build/cjs/integrations/tracing/postgres.js.map +1 -1
- package/build/cjs/integrations/tracing/postgresjs.js +4 -3
- package/build/cjs/integrations/tracing/postgresjs.js.map +1 -1
- package/build/cjs/integrations/tracing/prisma.js +2 -2
- package/build/cjs/integrations/tracing/prisma.js.map +1 -1
- package/build/cjs/integrations/tracing/redis.js +3 -3
- package/build/cjs/integrations/tracing/redis.js.map +1 -1
- package/build/cjs/integrations/tracing/tedious.js +3 -3
- package/build/cjs/integrations/tracing/tedious.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai/index.js +2 -2
- package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -1
- package/build/cjs/integrations/winston.js +151 -0
- package/build/cjs/integrations/winston.js.map +1 -0
- package/build/cjs/logs/capture.js +29 -0
- package/build/cjs/logs/capture.js.map +1 -0
- package/build/cjs/logs/exports.js +178 -0
- package/build/cjs/logs/exports.js.map +1 -0
- package/build/cjs/nodeVersion.js +12 -0
- package/build/cjs/nodeVersion.js.map +1 -0
- package/build/cjs/otel/contextManager.js +16 -0
- package/build/cjs/otel/contextManager.js.map +1 -0
- package/build/cjs/otel/instrument.js +139 -0
- package/build/cjs/otel/instrument.js.map +1 -0
- package/build/cjs/preload.js +2 -2
- package/build/cjs/preload.js.map +1 -1
- package/build/cjs/proxy/base.js +122 -0
- package/build/cjs/proxy/base.js.map +1 -0
- package/build/cjs/proxy/index.js +173 -0
- package/build/cjs/proxy/index.js.map +1 -0
- package/build/cjs/proxy/parse-proxy-response.js +104 -0
- package/build/cjs/proxy/parse-proxy-response.js.map +1 -0
- package/build/cjs/sdk/api.js +117 -0
- package/build/cjs/sdk/api.js.map +1 -0
- package/build/cjs/sdk/client.js +156 -0
- package/build/cjs/sdk/client.js.map +1 -0
- package/build/cjs/sdk/index.js +203 -22
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +22 -4
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/cjs/transports/http.js +158 -0
- package/build/cjs/transports/http.js.map +1 -0
- package/build/cjs/utils/addOriginToSpan.js +11 -0
- package/build/cjs/utils/addOriginToSpan.js.map +1 -0
- package/build/cjs/utils/baggage.js +36 -0
- package/build/cjs/utils/baggage.js.map +1 -0
- package/build/cjs/utils/commonjs.js +13 -0
- package/build/cjs/utils/commonjs.js.map +1 -0
- package/build/cjs/utils/createMissingInstrumentationContext.js +11 -0
- package/build/cjs/utils/createMissingInstrumentationContext.js.map +1 -0
- package/build/cjs/utils/debug.js +23 -0
- package/build/cjs/utils/debug.js.map +1 -0
- package/build/cjs/utils/ensureIsWrapped.js +41 -0
- package/build/cjs/utils/ensureIsWrapped.js.map +1 -0
- package/build/cjs/utils/envToBool.js +32 -0
- package/build/cjs/utils/envToBool.js.map +1 -0
- package/build/cjs/utils/errorhandling.js +42 -0
- package/build/cjs/utils/errorhandling.js.map +1 -0
- package/build/cjs/utils/getRequestUrl.js +18 -0
- package/build/cjs/utils/getRequestUrl.js.map +1 -0
- package/build/cjs/utils/module.js +60 -0
- package/build/cjs/utils/module.js.map +1 -0
- package/build/esm/cron/common.js +54 -0
- package/build/esm/cron/common.js.map +1 -0
- package/build/esm/cron/cron.js +110 -0
- package/build/esm/cron/cron.js.map +1 -0
- package/build/esm/cron/index.js +13 -0
- package/build/esm/cron/index.js.map +1 -0
- package/build/esm/cron/node-cron.js +69 -0
- package/build/esm/cron/node-cron.js.map +1 -0
- package/build/esm/cron/node-schedule.js +63 -0
- package/build/esm/cron/node-schedule.js.map +1 -0
- package/build/esm/index.js +21 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/anr/index.js +234 -0
- package/build/esm/integrations/anr/index.js.map +1 -0
- package/build/esm/integrations/anr/worker-script.js +2 -0
- package/build/esm/integrations/childProcess.js +98 -0
- package/build/esm/integrations/childProcess.js.map +1 -0
- package/build/esm/integrations/context.js +451 -0
- package/build/esm/integrations/context.js.map +1 -0
- package/build/esm/integrations/contextlines.js +399 -0
- package/build/esm/integrations/contextlines.js.map +1 -0
- package/build/esm/integrations/fs.js +1 -1
- package/build/esm/integrations/fs.js.map +1 -1
- package/build/esm/integrations/http/SentryHttpInstrumentation.js +555 -0
- package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +1 -0
- package/build/esm/integrations/http/index.js +5 -1
- package/build/esm/integrations/http/index.js.map +1 -1
- package/build/esm/integrations/local-variables/common.js +64 -0
- package/build/esm/integrations/local-variables/common.js.map +1 -0
- package/build/esm/integrations/local-variables/index.js +10 -0
- package/build/esm/integrations/local-variables/index.js.map +1 -0
- package/build/esm/integrations/local-variables/local-variables-async.js +140 -0
- package/build/esm/integrations/local-variables/local-variables-async.js.map +1 -0
- package/build/esm/integrations/local-variables/local-variables-sync.js +405 -0
- package/build/esm/integrations/local-variables/local-variables-sync.js.map +1 -0
- package/build/esm/integrations/local-variables/worker-script.js +2 -0
- package/build/esm/integrations/modules.js +133 -0
- package/build/esm/integrations/modules.js.map +1 -0
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js +289 -0
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +1 -0
- package/build/esm/integrations/node-fetch/index.js +3 -2
- package/build/esm/integrations/node-fetch/index.js.map +1 -1
- package/build/esm/integrations/onuncaughtexception.js +131 -0
- package/build/esm/integrations/onuncaughtexception.js.map +1 -0
- package/build/esm/integrations/onunhandledrejection.js +86 -0
- package/build/esm/integrations/onunhandledrejection.js.map +1 -0
- package/build/esm/integrations/processSession.js +34 -0
- package/build/esm/integrations/processSession.js.map +1 -0
- package/build/esm/integrations/spotlight.js +98 -0
- package/build/esm/integrations/spotlight.js.map +1 -0
- package/build/esm/integrations/tracing/amqplib.js +2 -1
- package/build/esm/integrations/tracing/amqplib.js.map +1 -1
- package/build/esm/integrations/tracing/connect.js +2 -1
- package/build/esm/integrations/tracing/connect.js.map +1 -1
- package/build/esm/integrations/tracing/dataloader.js +1 -1
- package/build/esm/integrations/tracing/dataloader.js.map +1 -1
- package/build/esm/integrations/tracing/express.js +4 -2
- package/build/esm/integrations/tracing/express.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/fastify-otel/index.js +3 -3
- package/build/esm/integrations/tracing/fastify/fastify-otel/index.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/index.js +5 -5
- package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
- package/build/esm/integrations/tracing/genericPool.js +1 -1
- package/build/esm/integrations/tracing/genericPool.js.map +1 -1
- package/build/esm/integrations/tracing/graphql.js +3 -2
- package/build/esm/integrations/tracing/graphql.js.map +1 -1
- package/build/esm/integrations/tracing/hapi/index.js +2 -1
- package/build/esm/integrations/tracing/hapi/index.js.map +1 -1
- package/build/esm/integrations/tracing/kafka.js +2 -1
- package/build/esm/integrations/tracing/kafka.js.map +1 -1
- package/build/esm/integrations/tracing/knex.js +1 -1
- package/build/esm/integrations/tracing/knex.js.map +1 -1
- package/build/esm/integrations/tracing/koa.js +4 -2
- package/build/esm/integrations/tracing/koa.js.map +1 -1
- package/build/esm/integrations/tracing/lrumemoizer.js +1 -1
- package/build/esm/integrations/tracing/lrumemoizer.js.map +1 -1
- package/build/esm/integrations/tracing/mongo.js +2 -1
- package/build/esm/integrations/tracing/mongo.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose.js +2 -1
- package/build/esm/integrations/tracing/mongoose.js.map +1 -1
- package/build/esm/integrations/tracing/mysql.js +1 -1
- package/build/esm/integrations/tracing/mysql.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2.js +2 -1
- package/build/esm/integrations/tracing/mysql2.js.map +1 -1
- package/build/esm/integrations/tracing/postgres.js +2 -1
- package/build/esm/integrations/tracing/postgres.js.map +1 -1
- package/build/esm/integrations/tracing/postgresjs.js +3 -2
- package/build/esm/integrations/tracing/postgresjs.js.map +1 -1
- package/build/esm/integrations/tracing/prisma.js +1 -1
- package/build/esm/integrations/tracing/prisma.js.map +1 -1
- package/build/esm/integrations/tracing/redis.js +1 -1
- package/build/esm/integrations/tracing/redis.js.map +1 -1
- package/build/esm/integrations/tracing/tedious.js +1 -1
- package/build/esm/integrations/tracing/tedious.js.map +1 -1
- package/build/esm/integrations/tracing/vercelai/index.js +1 -1
- package/build/esm/integrations/tracing/vercelai/index.js.map +1 -1
- package/build/esm/integrations/winston.js +149 -0
- package/build/esm/integrations/winston.js.map +1 -0
- package/build/esm/logs/capture.js +27 -0
- package/build/esm/logs/capture.js.map +1 -0
- package/build/esm/logs/exports.js +170 -0
- package/build/esm/logs/exports.js.map +1 -0
- package/build/esm/nodeVersion.js +8 -0
- package/build/esm/nodeVersion.js.map +1 -0
- package/build/esm/otel/contextManager.js +14 -0
- package/build/esm/otel/contextManager.js.map +1 -0
- package/build/esm/otel/instrument.js +135 -0
- package/build/esm/otel/instrument.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/preload.js +1 -1
- package/build/esm/preload.js.map +1 -1
- package/build/esm/proxy/base.js +120 -0
- package/build/esm/proxy/base.js.map +1 -0
- package/build/esm/proxy/index.js +171 -0
- package/build/esm/proxy/index.js.map +1 -0
- package/build/esm/proxy/parse-proxy-response.js +102 -0
- package/build/esm/proxy/parse-proxy-response.js.map +1 -0
- package/build/esm/sdk/api.js +114 -0
- package/build/esm/sdk/api.js.map +1 -0
- package/build/esm/sdk/client.js +154 -0
- package/build/esm/sdk/client.js.map +1 -0
- package/build/esm/sdk/index.js +202 -22
- package/build/esm/sdk/index.js.map +1 -1
- package/build/esm/sdk/initOtel.js +21 -3
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/esm/transports/http.js +156 -0
- package/build/esm/transports/http.js.map +1 -0
- package/build/esm/utils/addOriginToSpan.js +9 -0
- package/build/esm/utils/addOriginToSpan.js.map +1 -0
- package/build/esm/utils/baggage.js +34 -0
- package/build/esm/utils/baggage.js.map +1 -0
- package/build/esm/utils/commonjs.js +11 -0
- package/build/esm/utils/commonjs.js.map +1 -0
- package/build/esm/utils/createMissingInstrumentationContext.js +9 -0
- package/build/esm/utils/createMissingInstrumentationContext.js.map +1 -0
- package/build/esm/utils/debug.js +21 -0
- package/build/esm/utils/debug.js.map +1 -0
- package/build/esm/utils/ensureIsWrapped.js +39 -0
- package/build/esm/utils/ensureIsWrapped.js.map +1 -0
- package/build/esm/utils/envToBool.js +28 -0
- package/build/esm/utils/envToBool.js.map +1 -0
- package/build/esm/utils/errorhandling.js +40 -0
- package/build/esm/utils/errorhandling.js.map +1 -0
- package/build/esm/utils/getRequestUrl.js +16 -0
- package/build/esm/utils/getRequestUrl.js.map +1 -0
- package/build/esm/utils/module.js +58 -0
- package/build/esm/utils/module.js.map +1 -0
- package/build/types/cron/common.d.ts +5 -0
- package/build/types/cron/common.d.ts.map +1 -0
- package/build/types/cron/cron.d.ts +43 -0
- package/build/types/cron/cron.d.ts.map +1 -0
- package/build/types/cron/index.d.ts +10 -0
- package/build/types/cron/index.d.ts.map +1 -0
- package/build/types/cron/node-cron.d.ts +27 -0
- package/build/types/cron/node-cron.d.ts.map +1 -0
- package/build/types/cron/node-schedule.d.ts +19 -0
- package/build/types/cron/node-schedule.d.ts.map +1 -0
- package/build/types/index.d.ts +21 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/anr/common.d.ts +52 -0
- package/build/types/integrations/anr/common.d.ts.map +1 -0
- package/build/types/integrations/anr/index.d.ts +13 -0
- package/build/types/integrations/anr/index.d.ts.map +1 -0
- package/build/types/integrations/anr/worker.d.ts +2 -0
- package/build/types/integrations/anr/worker.d.ts.map +1 -0
- package/build/types/integrations/childProcess.d.ts +20 -0
- package/build/types/integrations/childProcess.d.ts.map +1 -0
- package/build/types/integrations/context.d.ts +30 -0
- package/build/types/integrations/context.d.ts.map +1 -0
- package/build/types/integrations/contextlines.d.ts +31 -0
- package/build/types/integrations/contextlines.d.ts.map +1 -0
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +131 -0
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +1 -0
- package/build/types/integrations/http/index.d.ts +1 -1
- package/build/types/integrations/http/index.d.ts.map +1 -1
- package/build/types/integrations/local-variables/common.d.ts +66 -0
- package/build/types/integrations/local-variables/common.d.ts.map +1 -0
- package/build/types/integrations/local-variables/index.d.ts +4 -0
- package/build/types/integrations/local-variables/index.d.ts.map +1 -0
- package/build/types/integrations/local-variables/local-variables-async.d.ts +7 -0
- package/build/types/integrations/local-variables/local-variables-async.d.ts.map +1 -0
- package/build/types/integrations/local-variables/local-variables-sync.d.ts +34 -0
- package/build/types/integrations/local-variables/local-variables-sync.d.ts.map +1 -0
- package/build/types/integrations/local-variables/worker.d.ts +2 -0
- package/build/types/integrations/local-variables/worker.d.ts.map +1 -0
- package/build/types/integrations/modules.d.ts +17 -0
- package/build/types/integrations/modules.d.ts.map +1 -0
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +56 -0
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts.map +1 -0
- package/build/types/integrations/node-fetch/index.d.ts.map +1 -1
- package/build/types/integrations/onuncaughtexception.d.ts +31 -0
- package/build/types/integrations/onuncaughtexception.d.ts.map +1 -0
- package/build/types/integrations/onunhandledrejection.d.ts +23 -0
- package/build/types/integrations/onunhandledrejection.d.ts.map +1 -0
- package/build/types/integrations/processSession.d.ts +5 -0
- package/build/types/integrations/processSession.d.ts.map +1 -0
- package/build/types/integrations/spotlight.d.ts +18 -0
- package/build/types/integrations/spotlight.d.ts.map +1 -0
- package/build/types/integrations/tracing/amqplib.d.ts.map +1 -1
- package/build/types/integrations/tracing/connect.d.ts.map +1 -1
- package/build/types/integrations/tracing/express.d.ts.map +1 -1
- package/build/types/integrations/tracing/graphql.d.ts.map +1 -1
- package/build/types/integrations/tracing/hapi/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/kafka.d.ts.map +1 -1
- package/build/types/integrations/tracing/koa.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgres.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -1
- package/build/types/integrations/winston.d.ts +44 -0
- package/build/types/integrations/winston.d.ts.map +1 -0
- package/build/types/logs/capture.d.ts +11 -0
- package/build/types/logs/capture.d.ts.map +1 -0
- package/build/types/logs/exports.d.ts +150 -0
- package/build/types/logs/exports.d.ts.map +1 -0
- package/build/types/nodeVersion.d.ts +8 -0
- package/build/types/nodeVersion.d.ts.map +1 -0
- package/build/types/otel/contextManager.d.ts +10 -0
- package/build/types/otel/contextManager.d.ts.map +1 -0
- package/build/types/otel/instrument.d.ts +23 -0
- package/build/types/otel/instrument.d.ts.map +1 -0
- package/build/types/proxy/base.d.ts +65 -0
- package/build/types/proxy/base.d.ts.map +1 -0
- package/build/types/proxy/helpers.d.ts +42 -0
- package/build/types/proxy/helpers.d.ts.map +1 -0
- package/build/types/proxy/index.d.ts +73 -0
- package/build/types/proxy/index.d.ts.map +1 -0
- package/build/types/proxy/parse-proxy-response.d.ts +43 -0
- package/build/types/proxy/parse-proxy-response.d.ts.map +1 -0
- package/build/types/sdk/api.d.ts +8 -0
- package/build/types/sdk/api.d.ts.map +1 -0
- package/build/types/sdk/client.d.ts +29 -0
- package/build/types/sdk/client.d.ts.map +1 -0
- package/build/types/sdk/index.d.ts +6 -2
- package/build/types/sdk/index.d.ts.map +1 -1
- package/build/types/sdk/initOtel.d.ts +1 -1
- package/build/types/sdk/initOtel.d.ts.map +1 -1
- package/build/types/sdk/scope.d.ts +7 -0
- package/build/types/sdk/scope.d.ts.map +1 -0
- package/build/types/transports/http-module.d.ts +31 -0
- package/build/types/transports/http-module.d.ts.map +1 -0
- package/build/types/transports/http.d.ts +21 -0
- package/build/types/transports/http.d.ts.map +1 -0
- package/build/types/transports/index.d.ts +3 -0
- package/build/types/transports/index.d.ts.map +1 -0
- package/build/types/types.d.ts +1 -1
- package/build/types/types.d.ts.map +1 -1
- package/build/types/utils/addOriginToSpan.d.ts +5 -0
- package/build/types/utils/addOriginToSpan.d.ts.map +1 -0
- package/build/types/utils/baggage.d.ts +6 -0
- package/build/types/utils/baggage.d.ts.map +1 -0
- package/build/types/utils/commonjs.d.ts +3 -0
- package/build/types/utils/commonjs.d.ts.map +1 -0
- package/build/types/utils/createMissingInstrumentationContext.d.ts +3 -0
- package/build/types/utils/createMissingInstrumentationContext.d.ts.map +1 -0
- package/build/types/utils/debug.d.ts +5 -0
- package/build/types/utils/debug.d.ts.map +1 -0
- package/build/types/utils/ensureIsWrapped.d.ts +5 -0
- package/build/types/utils/ensureIsWrapped.d.ts.map +1 -0
- package/build/types/utils/entry-point.d.ts +24 -0
- package/build/types/utils/entry-point.d.ts.map +1 -0
- package/build/types/utils/envToBool.d.ts +13 -0
- package/build/types/utils/envToBool.d.ts.map +1 -0
- package/build/types/utils/errorhandling.d.ts +5 -0
- package/build/types/utils/errorhandling.d.ts.map +1 -0
- package/build/types/utils/getRequestUrl.d.ts +5 -0
- package/build/types/utils/getRequestUrl.d.ts.map +1 -0
- package/build/types/utils/module.d.ts +3 -0
- package/build/types/utils/module.d.ts.map +1 -0
- package/build/types/utils/prepareEvent.d.ts +17 -0
- package/build/types/utils/prepareEvent.d.ts.map +1 -0
- package/build/types-ts3.8/cron/common.d.ts +5 -0
- package/build/types-ts3.8/cron/cron.d.ts +43 -0
- package/build/types-ts3.8/cron/index.d.ts +10 -0
- package/build/types-ts3.8/cron/node-cron.d.ts +27 -0
- package/build/types-ts3.8/cron/node-schedule.d.ts +19 -0
- package/build/types-ts3.8/index.d.ts +21 -2
- package/build/types-ts3.8/integrations/anr/common.d.ts +52 -0
- package/build/types-ts3.8/integrations/anr/index.d.ts +13 -0
- package/build/types-ts3.8/integrations/anr/worker.d.ts +2 -0
- package/build/types-ts3.8/integrations/childProcess.d.ts +20 -0
- package/build/types-ts3.8/integrations/context.d.ts +30 -0
- package/build/types-ts3.8/integrations/contextlines.d.ts +31 -0
- package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +133 -0
- package/build/types-ts3.8/integrations/http/index.d.ts +1 -1
- package/build/types-ts3.8/integrations/local-variables/common.d.ts +66 -0
- package/build/types-ts3.8/integrations/local-variables/index.d.ts +4 -0
- package/build/types-ts3.8/integrations/local-variables/local-variables-async.d.ts +7 -0
- package/build/types-ts3.8/integrations/local-variables/local-variables-sync.d.ts +34 -0
- package/build/types-ts3.8/integrations/local-variables/worker.d.ts +2 -0
- package/build/types-ts3.8/integrations/modules.d.ts +17 -0
- package/build/types-ts3.8/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +56 -0
- package/build/types-ts3.8/integrations/onuncaughtexception.d.ts +31 -0
- package/build/types-ts3.8/integrations/onunhandledrejection.d.ts +23 -0
- package/build/types-ts3.8/integrations/processSession.d.ts +5 -0
- package/build/types-ts3.8/integrations/spotlight.d.ts +18 -0
- package/build/types-ts3.8/integrations/winston.d.ts +44 -0
- package/build/types-ts3.8/logs/capture.d.ts +18 -0
- package/build/types-ts3.8/logs/exports.d.ts +150 -0
- package/build/types-ts3.8/nodeVersion.d.ts +8 -0
- package/build/types-ts3.8/otel/contextManager.d.ts +10 -0
- package/build/types-ts3.8/otel/instrument.d.ts +23 -0
- package/build/types-ts3.8/proxy/base.d.ts +60 -0
- package/build/types-ts3.8/proxy/helpers.d.ts +38 -0
- package/build/types-ts3.8/proxy/index.d.ts +74 -0
- package/build/types-ts3.8/proxy/parse-proxy-response.d.ts +40 -0
- package/build/types-ts3.8/sdk/api.d.ts +8 -0
- package/build/types-ts3.8/sdk/client.d.ts +32 -0
- package/build/types-ts3.8/sdk/index.d.ts +6 -2
- package/build/types-ts3.8/sdk/initOtel.d.ts +1 -1
- package/build/types-ts3.8/sdk/scope.d.ts +7 -0
- package/build/types-ts3.8/transports/http-module.d.ts +28 -0
- package/build/types-ts3.8/transports/http.d.ts +20 -0
- package/build/types-ts3.8/transports/index.d.ts +3 -0
- package/build/types-ts3.8/types.d.ts +1 -1
- package/build/types-ts3.8/utils/addOriginToSpan.d.ts +5 -0
- package/build/types-ts3.8/utils/baggage.d.ts +6 -0
- package/build/types-ts3.8/utils/commonjs.d.ts +3 -0
- package/build/types-ts3.8/utils/createMissingInstrumentationContext.d.ts +3 -0
- package/build/types-ts3.8/utils/debug.d.ts +5 -0
- package/build/types-ts3.8/utils/ensureIsWrapped.d.ts +5 -0
- package/build/types-ts3.8/utils/entry-point.d.ts +24 -0
- package/build/types-ts3.8/utils/envToBool.d.ts +13 -0
- package/build/types-ts3.8/utils/errorhandling.d.ts +5 -0
- package/build/types-ts3.8/utils/getRequestUrl.d.ts +5 -0
- package/build/types-ts3.8/utils/module.d.ts +3 -0
- package/build/types-ts3.8/utils/prepareEvent.d.ts +17 -0
- package/package.json +3 -4
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { context } from '@opentelemetry/api';
|
|
2
|
+
import { VERSION, isTracingSuppressed } from '@opentelemetry/core';
|
|
3
|
+
import { InstrumentationBase } from '@opentelemetry/instrumentation';
|
|
4
|
+
import { LRUMap, getClient, getTraceData, getBreadcrumbLogLevelFromHttpStatusCode, addBreadcrumb, parseUrl, getSanitizedUrlString } from '@sentry/core';
|
|
5
|
+
import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';
|
|
6
|
+
import * as diagch from 'diagnostics_channel';
|
|
7
|
+
import { NODE_MAJOR, NODE_MINOR } from '../../nodeVersion.js';
|
|
8
|
+
import { mergeBaggageHeaders } from '../../utils/baggage.js';
|
|
9
|
+
|
|
10
|
+
const SENTRY_TRACE_HEADER = 'sentry-trace';
|
|
11
|
+
const SENTRY_BAGGAGE_HEADER = 'baggage';
|
|
12
|
+
|
|
13
|
+
// For baggage, we make sure to merge this into a possibly existing header
|
|
14
|
+
const BAGGAGE_HEADER_REGEX = /baggage: (.*)\r\n/;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This custom node-fetch instrumentation is used to instrument outgoing fetch requests.
|
|
18
|
+
* It does not emit any spans.
|
|
19
|
+
*
|
|
20
|
+
* The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,
|
|
21
|
+
* which would lead to Sentry not working as expected.
|
|
22
|
+
*
|
|
23
|
+
* This is heavily inspired & adapted from:
|
|
24
|
+
* https://github.com/open-telemetry/opentelemetry-js-contrib/blob/28e209a9da36bc4e1f8c2b0db7360170ed46cb80/plugins/node/instrumentation-undici/src/undici.ts
|
|
25
|
+
*/
|
|
26
|
+
class SentryNodeFetchInstrumentation extends InstrumentationBase {
|
|
27
|
+
// Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for
|
|
28
|
+
// unsubscribing.
|
|
29
|
+
|
|
30
|
+
constructor(config = {}) {
|
|
31
|
+
super('@sentry/instrumentation-node-fetch', VERSION, config);
|
|
32
|
+
this._channelSubs = [];
|
|
33
|
+
this._propagationDecisionMap = new LRUMap(100);
|
|
34
|
+
this._ignoreOutgoingRequestsMap = new WeakMap();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** No need to instrument files/modules. */
|
|
38
|
+
init() {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Disable the instrumentation. */
|
|
43
|
+
disable() {
|
|
44
|
+
super.disable();
|
|
45
|
+
this._channelSubs.forEach(sub => sub.unsubscribe());
|
|
46
|
+
this._channelSubs = [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Enable the instrumentation. */
|
|
50
|
+
enable() {
|
|
51
|
+
// "enabled" handling is currently a bit messy with InstrumentationBase.
|
|
52
|
+
// If constructed with `{enabled: false}`, this `.enable()` is still called,
|
|
53
|
+
// and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.
|
|
54
|
+
//
|
|
55
|
+
// For now, this class will setup for instrumenting if `.enable()` is
|
|
56
|
+
// called, but use `this.getConfig().enabled` to determine if
|
|
57
|
+
// instrumentation should be generated. This covers the more likely common
|
|
58
|
+
// case of config being given a construction time, rather than later via
|
|
59
|
+
// `instance.enable()`, `.disable()`, or `.setConfig()` calls.
|
|
60
|
+
super.enable();
|
|
61
|
+
|
|
62
|
+
// This method is called by the super-class constructor before ours is
|
|
63
|
+
// called. So we need to ensure the property is initalized.
|
|
64
|
+
this._channelSubs = this._channelSubs || [];
|
|
65
|
+
|
|
66
|
+
// Avoid to duplicate subscriptions
|
|
67
|
+
if (this._channelSubs.length > 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this._subscribeToChannel('undici:request:create', this._onRequestCreated.bind(this));
|
|
72
|
+
this._subscribeToChannel('undici:request:headers', this._onResponseHeaders.bind(this));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* This method is called when a request is created.
|
|
77
|
+
* You can still mutate the request here before it is sent.
|
|
78
|
+
*/
|
|
79
|
+
_onRequestCreated({ request }) {
|
|
80
|
+
const config = this.getConfig();
|
|
81
|
+
const enabled = config.enabled !== false;
|
|
82
|
+
|
|
83
|
+
if (!enabled) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const shouldIgnore = this._shouldIgnoreOutgoingRequest(request);
|
|
88
|
+
// We store this decisision for later so we do not need to re-evaluate it
|
|
89
|
+
// Additionally, the active context is not correct in _onResponseHeaders, so we need to make sure it is evaluated here
|
|
90
|
+
this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);
|
|
91
|
+
|
|
92
|
+
if (shouldIgnore) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const url = getAbsoluteUrl(request.origin, request.path);
|
|
97
|
+
|
|
98
|
+
// Manually add the trace headers, if it applies
|
|
99
|
+
// Note: We do not use `propagation.inject()` here, because our propagator relies on an active span
|
|
100
|
+
// Which we do not have in this case
|
|
101
|
+
// The propagator _may_ overwrite this, but this should be fine as it is the same data
|
|
102
|
+
const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;
|
|
103
|
+
const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)
|
|
104
|
+
? getTraceData()
|
|
105
|
+
: undefined;
|
|
106
|
+
|
|
107
|
+
if (!addedHeaders) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;
|
|
112
|
+
|
|
113
|
+
// We do not want to overwrite existing headers here
|
|
114
|
+
// If the core UndiciInstrumentation is registered, it will already have set the headers
|
|
115
|
+
// We do not want to add any then
|
|
116
|
+
if (Array.isArray(request.headers)) {
|
|
117
|
+
const requestHeaders = request.headers;
|
|
118
|
+
|
|
119
|
+
// We do not want to overwrite existing header here, if it was already set
|
|
120
|
+
if (sentryTrace && !requestHeaders.includes(SENTRY_TRACE_HEADER)) {
|
|
121
|
+
requestHeaders.push(SENTRY_TRACE_HEADER, sentryTrace);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// For baggage, we make sure to merge this into a possibly existing header
|
|
125
|
+
const existingBaggagePos = requestHeaders.findIndex(header => header === SENTRY_BAGGAGE_HEADER);
|
|
126
|
+
if (baggage && existingBaggagePos === -1) {
|
|
127
|
+
requestHeaders.push(SENTRY_BAGGAGE_HEADER, baggage);
|
|
128
|
+
} else if (baggage) {
|
|
129
|
+
const existingBaggage = requestHeaders[existingBaggagePos + 1];
|
|
130
|
+
const merged = mergeBaggageHeaders(existingBaggage, baggage);
|
|
131
|
+
if (merged) {
|
|
132
|
+
requestHeaders[existingBaggagePos + 1] = merged;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const requestHeaders = request.headers;
|
|
137
|
+
// We do not want to overwrite existing header here, if it was already set
|
|
138
|
+
if (sentryTrace && !requestHeaders.includes(`${SENTRY_TRACE_HEADER}:`)) {
|
|
139
|
+
request.headers += `${SENTRY_TRACE_HEADER}: ${sentryTrace}\r\n`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const existingBaggage = request.headers.match(BAGGAGE_HEADER_REGEX)?.[1];
|
|
143
|
+
if (baggage && !existingBaggage) {
|
|
144
|
+
request.headers += `${SENTRY_BAGGAGE_HEADER}: ${baggage}\r\n`;
|
|
145
|
+
} else if (baggage) {
|
|
146
|
+
const merged = mergeBaggageHeaders(existingBaggage, baggage);
|
|
147
|
+
if (merged) {
|
|
148
|
+
request.headers = request.headers.replace(BAGGAGE_HEADER_REGEX, `baggage: ${merged}\r\n`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* This method is called when a response is received.
|
|
156
|
+
*/
|
|
157
|
+
_onResponseHeaders({ request, response }) {
|
|
158
|
+
const config = this.getConfig();
|
|
159
|
+
const enabled = config.enabled !== false;
|
|
160
|
+
|
|
161
|
+
if (!enabled) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const _breadcrumbs = config.breadcrumbs;
|
|
166
|
+
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
|
|
167
|
+
|
|
168
|
+
const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request);
|
|
169
|
+
|
|
170
|
+
if (breadCrumbsEnabled && !shouldIgnore) {
|
|
171
|
+
addRequestBreadcrumb(request, response);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Subscribe to a diagnostics channel. */
|
|
176
|
+
_subscribeToChannel(
|
|
177
|
+
diagnosticChannel,
|
|
178
|
+
onMessage,
|
|
179
|
+
) {
|
|
180
|
+
// `diagnostics_channel` had a ref counting bug until v18.19.0.
|
|
181
|
+
// https://github.com/nodejs/node/pull/47520
|
|
182
|
+
const useNewSubscribe = NODE_MAJOR > 18 || (NODE_MAJOR === 18 && NODE_MINOR >= 19);
|
|
183
|
+
|
|
184
|
+
let unsubscribe;
|
|
185
|
+
if (useNewSubscribe) {
|
|
186
|
+
diagch.subscribe?.(diagnosticChannel, onMessage);
|
|
187
|
+
unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);
|
|
188
|
+
} else {
|
|
189
|
+
const channel = diagch.channel(diagnosticChannel);
|
|
190
|
+
channel.subscribe(onMessage);
|
|
191
|
+
unsubscribe = () => channel.unsubscribe(onMessage);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this._channelSubs.push({
|
|
195
|
+
name: diagnosticChannel,
|
|
196
|
+
unsubscribe,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check if the given outgoing request should be ignored.
|
|
202
|
+
*/
|
|
203
|
+
_shouldIgnoreOutgoingRequest(request) {
|
|
204
|
+
if (isTracingSuppressed(context.active())) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Add trace propagation headers
|
|
209
|
+
const url = getAbsoluteUrl(request.origin, request.path);
|
|
210
|
+
const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;
|
|
211
|
+
|
|
212
|
+
if (typeof ignoreOutgoingRequests !== 'function' || !url) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return ignoreOutgoingRequests(url);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Add a breadcrumb for outgoing requests. */
|
|
221
|
+
function addRequestBreadcrumb(request, response) {
|
|
222
|
+
const data = getBreadcrumbData(request);
|
|
223
|
+
|
|
224
|
+
const statusCode = response.statusCode;
|
|
225
|
+
const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
|
|
226
|
+
|
|
227
|
+
addBreadcrumb(
|
|
228
|
+
{
|
|
229
|
+
category: 'http',
|
|
230
|
+
data: {
|
|
231
|
+
status_code: statusCode,
|
|
232
|
+
...data,
|
|
233
|
+
},
|
|
234
|
+
type: 'http',
|
|
235
|
+
level,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
event: 'response',
|
|
239
|
+
request,
|
|
240
|
+
response,
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function getBreadcrumbData(request) {
|
|
246
|
+
try {
|
|
247
|
+
const url = getAbsoluteUrl(request.origin, request.path);
|
|
248
|
+
const parsedUrl = parseUrl(url);
|
|
249
|
+
|
|
250
|
+
const data = {
|
|
251
|
+
url: getSanitizedUrlString(parsedUrl),
|
|
252
|
+
'http.method': request.method || 'GET',
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
if (parsedUrl.search) {
|
|
256
|
+
data['http.query'] = parsedUrl.search;
|
|
257
|
+
}
|
|
258
|
+
if (parsedUrl.hash) {
|
|
259
|
+
data['http.fragment'] = parsedUrl.hash;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return data;
|
|
263
|
+
} catch {
|
|
264
|
+
return {};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getAbsoluteUrl(origin, path = '/') {
|
|
269
|
+
try {
|
|
270
|
+
const url = new URL(path, origin);
|
|
271
|
+
return url.toString();
|
|
272
|
+
} catch {
|
|
273
|
+
// fallback: Construct it on our own
|
|
274
|
+
const url = `${origin}`;
|
|
275
|
+
|
|
276
|
+
if (url.endsWith('/') && path.startsWith('/')) {
|
|
277
|
+
return `${url}${path.slice(1)}`;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (!url.endsWith('/') && !path.startsWith('/')) {
|
|
281
|
+
return `${url}/${path.slice(1)}`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return `${url}${path}`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { SentryNodeFetchInstrumentation };
|
|
289
|
+
//# sourceMappingURL=SentryNodeFetchInstrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SentryNodeFetchInstrumentation.js","sources":["../../../../src/integrations/node-fetch/SentryNodeFetchInstrumentation.ts"],"sourcesContent":["import { context } from '@opentelemetry/api';\nimport { isTracingSuppressed, VERSION } from '@opentelemetry/core';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport type { SanitizedRequestData } from '@sentry/core';\nimport {\n addBreadcrumb,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n getSanitizedUrlString,\n getTraceData,\n LRUMap,\n parseUrl,\n} from '@sentry/core';\nimport { shouldPropagateTraceForUrl } from '@sentry/opentelemetry';\nimport * as diagch from 'diagnostics_channel';\nimport { NODE_MAJOR, NODE_MINOR } from '../../nodeVersion';\nimport { mergeBaggageHeaders } from '../../utils/baggage';\nimport type { UndiciRequest, UndiciResponse } from './types';\n\nconst SENTRY_TRACE_HEADER = 'sentry-trace';\nconst SENTRY_BAGGAGE_HEADER = 'baggage';\n\n// For baggage, we make sure to merge this into a possibly existing header\nconst BAGGAGE_HEADER_REGEX = /baggage: (.*)\\r\\n/;\n\nexport type SentryNodeFetchInstrumentationOptions = InstrumentationConfig & {\n /**\n * Whether breadcrumbs should be recorded for requests.\n *\n * @default `true`\n */\n breadcrumbs?: boolean;\n\n /**\n * Do not capture breadcrumbs or inject headers for outgoing fetch requests to URLs where the given callback returns `true`.\n * The same option can be passed to the top-level httpIntegration where it controls both, breadcrumb and\n * span creation.\n *\n * @param url Contains the entire URL, including query string (if any), protocol, host, etc. of the outgoing request.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n};\n\ninterface ListenerRecord {\n name: string;\n unsubscribe: () => void;\n}\n\n/**\n * This custom node-fetch instrumentation is used to instrument outgoing fetch requests.\n * It does not emit any spans.\n *\n * The reason this is isolated from the OpenTelemetry instrumentation is that users may overwrite this,\n * which would lead to Sentry not working as expected.\n *\n * This is heavily inspired & adapted from:\n * https://github.com/open-telemetry/opentelemetry-js-contrib/blob/28e209a9da36bc4e1f8c2b0db7360170ed46cb80/plugins/node/instrumentation-undici/src/undici.ts\n */\nexport class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNodeFetchInstrumentationOptions> {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for\n // unsubscribing.\n private _channelSubs: Array<ListenerRecord>;\n private _propagationDecisionMap: LRUMap<string, boolean>;\n private _ignoreOutgoingRequestsMap: WeakMap<UndiciRequest, boolean>;\n\n public constructor(config: SentryNodeFetchInstrumentationOptions = {}) {\n super('@sentry/instrumentation-node-fetch', VERSION, config);\n this._channelSubs = [];\n this._propagationDecisionMap = new LRUMap<string, boolean>(100);\n this._ignoreOutgoingRequestsMap = new WeakMap<UndiciRequest, boolean>();\n }\n\n /** No need to instrument files/modules. */\n public init(): void {\n return undefined;\n }\n\n /** Disable the instrumentation. */\n public disable(): void {\n super.disable();\n this._channelSubs.forEach(sub => sub.unsubscribe());\n this._channelSubs = [];\n }\n\n /** Enable the instrumentation. */\n public enable(): void {\n // \"enabled\" handling is currently a bit messy with InstrumentationBase.\n // If constructed with `{enabled: false}`, this `.enable()` is still called,\n // and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.\n //\n // For now, this class will setup for instrumenting if `.enable()` is\n // called, but use `this.getConfig().enabled` to determine if\n // instrumentation should be generated. This covers the more likely common\n // case of config being given a construction time, rather than later via\n // `instance.enable()`, `.disable()`, or `.setConfig()` calls.\n super.enable();\n\n // This method is called by the super-class constructor before ours is\n // called. So we need to ensure the property is initalized.\n this._channelSubs = this._channelSubs || [];\n\n // Avoid to duplicate subscriptions\n if (this._channelSubs.length > 0) {\n return;\n }\n\n this._subscribeToChannel('undici:request:create', this._onRequestCreated.bind(this));\n this._subscribeToChannel('undici:request:headers', this._onResponseHeaders.bind(this));\n }\n\n /**\n * This method is called when a request is created.\n * You can still mutate the request here before it is sent.\n */\n private _onRequestCreated({ request }: { request: UndiciRequest }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n const shouldIgnore = this._shouldIgnoreOutgoingRequest(request);\n // We store this decisision for later so we do not need to re-evaluate it\n // Additionally, the active context is not correct in _onResponseHeaders, so we need to make sure it is evaluated here\n this._ignoreOutgoingRequestsMap.set(request, shouldIgnore);\n\n if (shouldIgnore) {\n return;\n }\n\n const url = getAbsoluteUrl(request.origin, request.path);\n\n // Manually add the trace headers, if it applies\n // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span\n // Which we do not have in this case\n // The propagator _may_ overwrite this, but this should be fine as it is the same data\n const tracePropagationTargets = getClient()?.getOptions().tracePropagationTargets;\n const addedHeaders = shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)\n ? getTraceData()\n : undefined;\n\n if (!addedHeaders) {\n return;\n }\n\n const { 'sentry-trace': sentryTrace, baggage } = addedHeaders;\n\n // We do not want to overwrite existing headers here\n // If the core UndiciInstrumentation is registered, it will already have set the headers\n // We do not want to add any then\n if (Array.isArray(request.headers)) {\n const requestHeaders = request.headers;\n\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(SENTRY_TRACE_HEADER)) {\n requestHeaders.push(SENTRY_TRACE_HEADER, sentryTrace);\n }\n\n // For baggage, we make sure to merge this into a possibly existing header\n const existingBaggagePos = requestHeaders.findIndex(header => header === SENTRY_BAGGAGE_HEADER);\n if (baggage && existingBaggagePos === -1) {\n requestHeaders.push(SENTRY_BAGGAGE_HEADER, baggage);\n } else if (baggage) {\n const existingBaggage = requestHeaders[existingBaggagePos + 1];\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n requestHeaders[existingBaggagePos + 1] = merged;\n }\n }\n } else {\n const requestHeaders = request.headers;\n // We do not want to overwrite existing header here, if it was already set\n if (sentryTrace && !requestHeaders.includes(`${SENTRY_TRACE_HEADER}:`)) {\n request.headers += `${SENTRY_TRACE_HEADER}: ${sentryTrace}\\r\\n`;\n }\n\n const existingBaggage = request.headers.match(BAGGAGE_HEADER_REGEX)?.[1];\n if (baggage && !existingBaggage) {\n request.headers += `${SENTRY_BAGGAGE_HEADER}: ${baggage}\\r\\n`;\n } else if (baggage) {\n const merged = mergeBaggageHeaders(existingBaggage, baggage);\n if (merged) {\n request.headers = request.headers.replace(BAGGAGE_HEADER_REGEX, `baggage: ${merged}\\r\\n`);\n }\n }\n }\n }\n\n /**\n * This method is called when a response is received.\n */\n private _onResponseHeaders({ request, response }: { request: UndiciRequest; response: UndiciResponse }): void {\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n\n if (!enabled) {\n return;\n }\n\n const _breadcrumbs = config.breadcrumbs;\n const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;\n\n const shouldIgnore = this._ignoreOutgoingRequestsMap.get(request);\n\n if (breadCrumbsEnabled && !shouldIgnore) {\n addRequestBreadcrumb(request, response);\n }\n }\n\n /** Subscribe to a diagnostics channel. */\n private _subscribeToChannel(\n diagnosticChannel: string,\n onMessage: (message: unknown, name: string | symbol) => void,\n ): void {\n // `diagnostics_channel` had a ref counting bug until v18.19.0.\n // https://github.com/nodejs/node/pull/47520\n const useNewSubscribe = NODE_MAJOR > 18 || (NODE_MAJOR === 18 && NODE_MINOR >= 19);\n\n let unsubscribe: () => void;\n if (useNewSubscribe) {\n diagch.subscribe?.(diagnosticChannel, onMessage);\n unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);\n } else {\n const channel = diagch.channel(diagnosticChannel);\n channel.subscribe(onMessage);\n unsubscribe = () => channel.unsubscribe(onMessage);\n }\n\n this._channelSubs.push({\n name: diagnosticChannel,\n unsubscribe,\n });\n }\n\n /**\n * Check if the given outgoing request should be ignored.\n */\n private _shouldIgnoreOutgoingRequest(request: UndiciRequest): boolean {\n if (isTracingSuppressed(context.active())) {\n return true;\n }\n\n // Add trace propagation headers\n const url = getAbsoluteUrl(request.origin, request.path);\n const ignoreOutgoingRequests = this.getConfig().ignoreOutgoingRequests;\n\n if (typeof ignoreOutgoingRequests !== 'function' || !url) {\n return false;\n }\n\n return ignoreOutgoingRequests(url);\n }\n}\n\n/** Add a breadcrumb for outgoing requests. */\nfunction addRequestBreadcrumb(request: UndiciRequest, response: UndiciResponse): void {\n const data = getBreadcrumbData(request);\n\n const statusCode = response.statusCode;\n const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);\n\n addBreadcrumb(\n {\n category: 'http',\n data: {\n status_code: statusCode,\n ...data,\n },\n type: 'http',\n level,\n },\n {\n event: 'response',\n request,\n response,\n },\n );\n}\n\nfunction getBreadcrumbData(request: UndiciRequest): Partial<SanitizedRequestData> {\n try {\n const url = getAbsoluteUrl(request.origin, request.path);\n const parsedUrl = parseUrl(url);\n\n const data: Partial<SanitizedRequestData> = {\n url: getSanitizedUrlString(parsedUrl),\n 'http.method': request.method || 'GET',\n };\n\n if (parsedUrl.search) {\n data['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n data['http.fragment'] = parsedUrl.hash;\n }\n\n return data;\n } catch {\n return {};\n }\n}\n\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n try {\n const url = new URL(path, origin);\n return url.toString();\n } catch {\n // fallback: Construct it on our own\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path.slice(1)}`;\n }\n\n return `${url}${path}`;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAoBA,MAAM,mBAAA,GAAsB,cAAc;AAC1C,MAAM,qBAAA,GAAwB,SAAS;;AAEvC;AACA,MAAM,oBAAA,GAAuB,mBAAmB;;AAyBhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,8BAAA,SAAuC,mBAAmB,CAAwC;AAC/G;AACA;;AAKA,GAAS,WAAW,CAAC,MAAM,GAA0C,EAAE,EAAE;AACzE,IAAI,KAAK,CAAC,oCAAoC,EAAE,OAAO,EAAE,MAAM,CAAC;AAChE,IAAI,IAAI,CAAC,YAAa,GAAE,EAAE;AAC1B,IAAI,IAAI,CAAC,uBAAwB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AACnE,IAAI,IAAI,CAAC,0BAAA,GAA6B,IAAI,OAAO,EAA0B;AAC3E;;AAEA;AACA,GAAS,IAAI,GAAS;AACtB,IAAI,OAAO,SAAS;AACpB;;AAEA;AACA,GAAS,OAAO,GAAS;AACzB,IAAI,KAAK,CAAC,OAAO,EAAE;AACnB,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAI,IAAG,GAAG,CAAC,WAAW,EAAE,CAAC;AACvD,IAAI,IAAI,CAAC,YAAa,GAAE,EAAE;AAC1B;;AAEA;AACA,GAAS,MAAM,GAAS;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,KAAK,CAAC,MAAM,EAAE;;AAElB;AACA;AACA,IAAI,IAAI,CAAC,YAAa,GAAE,IAAI,CAAC,YAAA,IAAgB,EAAE;;AAE/C;AACA,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,MAAA,GAAS,CAAC,EAAE;AACtC,MAAM;AACN;;AAE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A,MAAA,OAAA,CAAA,EAAA,GAAA,CAAA,CAAA,EAAA,IAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACA;;AAEA,IAAA,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,IAAA,CAAA,CAAA;AACA;AACA;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
|
|
2
|
-
import { defineIntegration,
|
|
3
|
-
import { generateInstrumentOnce
|
|
2
|
+
import { defineIntegration, getClient, hasSpansEnabled, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
3
|
+
import { generateInstrumentOnce } from '../../otel/instrument.js';
|
|
4
|
+
import { SentryNodeFetchInstrumentation } from './SentryNodeFetchInstrumentation.js';
|
|
4
5
|
|
|
5
6
|
const INTEGRATION_NAME = 'NodeFetch';
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/integrations/node-fetch/index.ts"],"sourcesContent":["import type { UndiciInstrumentationConfig } from '@opentelemetry/instrumentation-undici';\nimport { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getClient, hasSpansEnabled, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/integrations/node-fetch/index.ts"],"sourcesContent":["import type { UndiciInstrumentationConfig } from '@opentelemetry/instrumentation-undici';\nimport { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getClient, hasSpansEnabled, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../otel/instrument';\nimport type { NodeClient } from '../../sdk/client';\nimport type { NodeClientOptions } from '../../types';\nimport { SentryNodeFetchInstrumentation } from './SentryNodeFetchInstrumentation';\n\nconst INTEGRATION_NAME = 'NodeFetch';\n\ninterface NodeFetchOptions {\n /**\n * Whether breadcrumbs should be recorded for requests.\n * Defaults to true\n */\n breadcrumbs?: boolean;\n\n /**\n * If set to false, do not emit any spans.\n * This will ensure that the default UndiciInstrumentation from OpenTelemetry is not setup,\n * only the Sentry-specific instrumentation for breadcrumbs & trace propagation is applied.\n *\n * If `skipOpenTelemetrySetup: true` is configured, this defaults to `false`, otherwise it defaults to `true`.\n */\n spans?: boolean;\n\n /**\n * Do not capture spans or breadcrumbs for outgoing fetch requests to URLs where the given callback returns `true`.\n * This controls both span & breadcrumb creation - spans will be non recording if tracing is disabled.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n}\n\nconst instrumentOtelNodeFetch = generateInstrumentOnce(\n INTEGRATION_NAME,\n UndiciInstrumentation,\n (options: NodeFetchOptions) => {\n return getConfigWithDefaults(options);\n },\n);\n\nconst instrumentSentryNodeFetch = generateInstrumentOnce(\n `${INTEGRATION_NAME}.sentry`,\n SentryNodeFetchInstrumentation,\n (options: NodeFetchOptions) => {\n return options;\n },\n);\n\nconst _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {\n return {\n name: 'NodeFetch',\n setupOnce() {\n const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());\n\n // This is the \"regular\" OTEL instrumentation that emits spans\n if (instrumentSpans) {\n instrumentOtelNodeFetch(options);\n }\n\n // This is the Sentry-specific instrumentation that creates breadcrumbs & propagates traces\n // This must be registered after the OTEL one, to ensure that the core trace propagation logic takes presedence\n // Otherwise, the sentry-trace header may be set multiple times\n instrumentSentryNodeFetch(options);\n },\n };\n}) satisfies IntegrationFn;\n\nexport const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration);\n\n// Matching the behavior of the base instrumentation\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path.slice(1)}`;\n }\n\n return `${url}${path}`;\n}\n\nfunction _shouldInstrumentSpans(options: NodeFetchOptions, clientOptions: Partial<NodeClientOptions> = {}): boolean {\n // If `spans` is passed in, it takes precedence\n // Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled\n return typeof options.spans === 'boolean'\n ? options.spans\n : !clientOptions.skipOpenTelemetrySetup && hasSpansEnabled(clientOptions);\n}\n\nfunction getConfigWithDefaults(options: Partial<NodeFetchOptions> = {}): UndiciInstrumentationConfig {\n const instrumentationConfig = {\n requireParentforSpans: false,\n ignoreRequestHook: request => {\n const url = getAbsoluteUrl(request.origin, request.path);\n const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;\n const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);\n\n return !!shouldIgnore;\n },\n startSpanHook: () => {\n return {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch',\n };\n },\n } satisfies UndiciInstrumentationConfig;\n\n return instrumentationConfig;\n}\n"],"names":[],"mappings":";;;;;AASA,MAAM,gBAAA,GAAmB,WAAW;;AAyBpC,MAAM,uBAAA,GAA0B,sBAAsB;AACtD,EAAE,gBAAgB;AAClB,EAAE,qBAAqB;AACvB,EAAE,CAAC,OAAO,KAAuB;AACjC,IAAI,OAAO,qBAAqB,CAAC,OAAO,CAAC;AACzC,GAAG;AACH,CAAC;;AAED,MAAM,yBAAA,GAA4B,sBAAsB;AACxD,EAAE,CAAC,EAAA,gBAAA,CAAA,OAAA,CAAA;AACA,EAAA,8BAAA;AACA,EAAA,CAAA,OAAA,KAAA;AACA,IAAA,OAAA,OAAA;AACA,GAAA;AACA,CAAA;;AAEA,MAAA,2BAAA,IAAA,CAAA,OAAA,GAAA,EAAA,KAAA;AACA,EAAA,OAAA;AACA,IAAA,IAAA,EAAA,W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AA,qBAAA,GAAA;AACA,IAAA,qBAAA,EAAA,KAAA;AACA,IAAA,iBAAA,EAAA,OAAA,IAAA;AACA,MAAA,MAAA,GAAA,GAAA,cAAA,CAAA,OAAA,CAAA,MAAA,EAAA,OAAA,CAAA,IAAA,CAAA;AACA,MAAA,MAAA,uBAAA,GAAA,OAAA,CAAA,sBAAA;AACA,MAAA,MAAA,YAAA,GAAA,uBAAA,IAAA,GAAA,IAAA,uBAAA,CAAA,GAAA,CAAA;;AAEA,MAAA,OAAA,CAAA,CAAA,YAAA;AACA,KAAA;AACA,IAAA,aAAA,EAAA,MAAA;AACA,MAAA,OAAA;AACA,QAAA,CAAA,gCAAA,GAAA,2BAAA;AACA,OAAA;AACA,KAAA;AACA,GAAA;;AAEA,EAAA,OAAA,qBAAA;AACA;;;;"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { defineIntegration, getClient, captureException, logger } from '@sentry/core';
|
|
2
|
+
import { DEBUG_BUILD } from '../debug-build.js';
|
|
3
|
+
import { logAndExitProcess } from '../utils/errorhandling.js';
|
|
4
|
+
|
|
5
|
+
const INTEGRATION_NAME = 'OnUncaughtException';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a global exception handler.
|
|
9
|
+
*/
|
|
10
|
+
const onUncaughtExceptionIntegration = defineIntegration((options = {}) => {
|
|
11
|
+
const optionsWithDefaults = {
|
|
12
|
+
exitEvenIfOtherHandlersAreRegistered: false,
|
|
13
|
+
...options,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
name: INTEGRATION_NAME,
|
|
18
|
+
setup(client) {
|
|
19
|
+
global.process.on('uncaughtException', makeErrorHandler(client, optionsWithDefaults));
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** Exported only for tests */
|
|
25
|
+
function makeErrorHandler(client, options) {
|
|
26
|
+
const timeout = 2000;
|
|
27
|
+
let caughtFirstError = false;
|
|
28
|
+
let caughtSecondError = false;
|
|
29
|
+
let calledFatalError = false;
|
|
30
|
+
let firstError;
|
|
31
|
+
|
|
32
|
+
const clientOptions = client.getOptions();
|
|
33
|
+
|
|
34
|
+
return Object.assign(
|
|
35
|
+
(error) => {
|
|
36
|
+
let onFatalError = logAndExitProcess;
|
|
37
|
+
|
|
38
|
+
if (options.onFatalError) {
|
|
39
|
+
onFatalError = options.onFatalError;
|
|
40
|
+
} else if (clientOptions.onFatalError) {
|
|
41
|
+
onFatalError = clientOptions.onFatalError ;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Attaching a listener to `uncaughtException` will prevent the node process from exiting. We generally do not
|
|
45
|
+
// want to alter this behaviour so we check for other listeners that users may have attached themselves and adjust
|
|
46
|
+
// exit behaviour of the SDK accordingly:
|
|
47
|
+
// - If other listeners are attached, do not exit.
|
|
48
|
+
// - If the only listener attached is ours, exit.
|
|
49
|
+
const userProvidedListenersCount = (global.process.listeners('uncaughtException') ).filter(
|
|
50
|
+
listener => {
|
|
51
|
+
// There are 3 listeners we ignore:
|
|
52
|
+
return (
|
|
53
|
+
// as soon as we're using domains this listener is attached by node itself
|
|
54
|
+
listener.name !== 'domainUncaughtExceptionClear' &&
|
|
55
|
+
// the handler we register for tracing
|
|
56
|
+
listener.tag !== 'sentry_tracingErrorCallback' &&
|
|
57
|
+
// the handler we register in this integration
|
|
58
|
+
(listener )._errorHandler !== true
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
).length;
|
|
62
|
+
|
|
63
|
+
const processWouldExit = userProvidedListenersCount === 0;
|
|
64
|
+
const shouldApplyFatalHandlingLogic = options.exitEvenIfOtherHandlersAreRegistered || processWouldExit;
|
|
65
|
+
|
|
66
|
+
if (!caughtFirstError) {
|
|
67
|
+
// this is the first uncaught error and the ultimate reason for shutting down
|
|
68
|
+
// we want to do absolutely everything possible to ensure it gets captured
|
|
69
|
+
// also we want to make sure we don't go recursion crazy if more errors happen after this one
|
|
70
|
+
firstError = error;
|
|
71
|
+
caughtFirstError = true;
|
|
72
|
+
|
|
73
|
+
if (getClient() === client) {
|
|
74
|
+
captureException(error, {
|
|
75
|
+
originalException: error,
|
|
76
|
+
captureContext: {
|
|
77
|
+
level: 'fatal',
|
|
78
|
+
},
|
|
79
|
+
mechanism: {
|
|
80
|
+
handled: false,
|
|
81
|
+
type: 'onuncaughtexception',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!calledFatalError && shouldApplyFatalHandlingLogic) {
|
|
87
|
+
calledFatalError = true;
|
|
88
|
+
onFatalError(error);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
if (shouldApplyFatalHandlingLogic) {
|
|
92
|
+
if (calledFatalError) {
|
|
93
|
+
// we hit an error *after* calling onFatalError - pretty boned at this point, just shut it down
|
|
94
|
+
DEBUG_BUILD &&
|
|
95
|
+
logger.warn(
|
|
96
|
+
'uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown',
|
|
97
|
+
);
|
|
98
|
+
logAndExitProcess(error);
|
|
99
|
+
} else if (!caughtSecondError) {
|
|
100
|
+
// two cases for how we can hit this branch:
|
|
101
|
+
// - capturing of first error blew up and we just caught the exception from that
|
|
102
|
+
// - quit trying to capture, proceed with shutdown
|
|
103
|
+
// - a second independent error happened while waiting for first error to capture
|
|
104
|
+
// - want to avoid causing premature shutdown before first error capture finishes
|
|
105
|
+
// it's hard to immediately tell case 1 from case 2 without doing some fancy/questionable domain stuff
|
|
106
|
+
// so let's instead just delay a bit before we proceed with our action here
|
|
107
|
+
// in case 1, we just wait a bit unnecessarily but ultimately do the same thing
|
|
108
|
+
// in case 2, the delay hopefully made us wait long enough for the capture to finish
|
|
109
|
+
// two potential nonideal outcomes:
|
|
110
|
+
// nonideal case 1: capturing fails fast, we sit around for a few seconds unnecessarily before proceeding correctly by calling onFatalError
|
|
111
|
+
// nonideal case 2: case 2 happens, 1st error is captured but slowly, timeout completes before capture and we treat second error as the sendErr of (nonexistent) failure from trying to capture first error
|
|
112
|
+
// note that after hitting this branch, we might catch more errors where (caughtSecondError && !calledFatalError)
|
|
113
|
+
// we ignore them - they don't matter to us, we're just waiting for the second error timeout to finish
|
|
114
|
+
caughtSecondError = true;
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
if (!calledFatalError) {
|
|
117
|
+
// it was probably case 1, let's treat err as the sendErr and call onFatalError
|
|
118
|
+
calledFatalError = true;
|
|
119
|
+
onFatalError(firstError, error);
|
|
120
|
+
}
|
|
121
|
+
}, timeout); // capturing could take at least sendTimeout to fail, plus an arbitrary second for how long it takes to collect surrounding source etc
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{ _errorHandler: true },
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { makeErrorHandler, onUncaughtExceptionIntegration };
|
|
131
|
+
//# sourceMappingURL=onuncaughtexception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onuncaughtexception.js","sources":["../../../src/integrations/onuncaughtexception.ts"],"sourcesContent":["import { captureException, defineIntegration, getClient, logger } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { NodeClient } from '../sdk/client';\nimport { logAndExitProcess } from '../utils/errorhandling';\n\ntype OnFatalErrorHandler = (firstError: Error, secondError?: Error) => void;\n\ntype TaggedListener = NodeJS.UncaughtExceptionListener & {\n tag?: string;\n};\n\ninterface OnUncaughtExceptionOptions {\n /**\n * Controls if the SDK should register a handler to exit the process on uncaught errors:\n * - `true`: The SDK will exit the process on all uncaught errors.\n * - `false`: The SDK will only exit the process when there are no other `uncaughtException` handlers attached.\n *\n * Default: `false`\n */\n exitEvenIfOtherHandlersAreRegistered: boolean;\n\n /**\n * This is called when an uncaught error would cause the process to exit.\n *\n * @param firstError Uncaught error causing the process to exit\n * @param secondError Will be set if the handler was called multiple times. This can happen either because\n * `onFatalError` itself threw, or because an independent error happened somewhere else while `onFatalError`\n * was running.\n */\n onFatalError?(this: void, firstError: Error, secondError?: Error): void;\n}\n\nconst INTEGRATION_NAME = 'OnUncaughtException';\n\n/**\n * Add a global exception handler.\n */\nexport const onUncaughtExceptionIntegration = defineIntegration((options: Partial<OnUncaughtExceptionOptions> = {}) => {\n const optionsWithDefaults = {\n exitEvenIfOtherHandlersAreRegistered: false,\n ...options,\n };\n\n return {\n name: INTEGRATION_NAME,\n setup(client: NodeClient) {\n global.process.on('uncaughtException', makeErrorHandler(client, optionsWithDefaults));\n },\n };\n});\n\ntype ErrorHandler = { _errorHandler: boolean } & ((error: Error) => void);\n\n/** Exported only for tests */\nexport function makeErrorHandler(client: NodeClient, options: OnUncaughtExceptionOptions): ErrorHandler {\n const timeout = 2000;\n let caughtFirstError: boolean = false;\n let caughtSecondError: boolean = false;\n let calledFatalError: boolean = false;\n let firstError: Error;\n\n const clientOptions = client.getOptions();\n\n return Object.assign(\n (error: Error): void => {\n let onFatalError: OnFatalErrorHandler = logAndExitProcess;\n\n if (options.onFatalError) {\n onFatalError = options.onFatalError;\n } else if (clientOptions.onFatalError) {\n onFatalError = clientOptions.onFatalError as OnFatalErrorHandler;\n }\n\n // Attaching a listener to `uncaughtException` will prevent the node process from exiting. We generally do not\n // want to alter this behaviour so we check for other listeners that users may have attached themselves and adjust\n // exit behaviour of the SDK accordingly:\n // - If other listeners are attached, do not exit.\n // - If the only listener attached is ours, exit.\n const userProvidedListenersCount = (global.process.listeners('uncaughtException') as TaggedListener[]).filter(\n listener => {\n // There are 3 listeners we ignore:\n return (\n // as soon as we're using domains this listener is attached by node itself\n listener.name !== 'domainUncaughtExceptionClear' &&\n // the handler we register for tracing\n listener.tag !== 'sentry_tracingErrorCallback' &&\n // the handler we register in this integration\n (listener as ErrorHandler)._errorHandler !== true\n );\n },\n ).length;\n\n const processWouldExit = userProvidedListenersCount === 0;\n const shouldApplyFatalHandlingLogic = options.exitEvenIfOtherHandlersAreRegistered || processWouldExit;\n\n if (!caughtFirstError) {\n // this is the first uncaught error and the ultimate reason for shutting down\n // we want to do absolutely everything possible to ensure it gets captured\n // also we want to make sure we don't go recursion crazy if more errors happen after this one\n firstError = error;\n caughtFirstError = true;\n\n if (getClient() === client) {\n captureException(error, {\n originalException: error,\n captureContext: {\n level: 'fatal',\n },\n mechanism: {\n handled: false,\n type: 'onuncaughtexception',\n },\n });\n }\n\n if (!calledFatalError && shouldApplyFatalHandlingLogic) {\n calledFatalError = true;\n onFatalError(error);\n }\n } else {\n if (shouldApplyFatalHandlingLogic) {\n if (calledFatalError) {\n // we hit an error *after* calling onFatalError - pretty boned at this point, just shut it down\n DEBUG_BUILD &&\n logger.warn(\n 'uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown',\n );\n logAndExitProcess(error);\n } else if (!caughtSecondError) {\n // two cases for how we can hit this branch:\n // - capturing of first error blew up and we just caught the exception from that\n // - quit trying to capture, proceed with shutdown\n // - a second independent error happened while waiting for first error to capture\n // - want to avoid causing premature shutdown before first error capture finishes\n // it's hard to immediately tell case 1 from case 2 without doing some fancy/questionable domain stuff\n // so let's instead just delay a bit before we proceed with our action here\n // in case 1, we just wait a bit unnecessarily but ultimately do the same thing\n // in case 2, the delay hopefully made us wait long enough for the capture to finish\n // two potential nonideal outcomes:\n // nonideal case 1: capturing fails fast, we sit around for a few seconds unnecessarily before proceeding correctly by calling onFatalError\n // nonideal case 2: case 2 happens, 1st error is captured but slowly, timeout completes before capture and we treat second error as the sendErr of (nonexistent) failure from trying to capture first error\n // note that after hitting this branch, we might catch more errors where (caughtSecondError && !calledFatalError)\n // we ignore them - they don't matter to us, we're just waiting for the second error timeout to finish\n caughtSecondError = true;\n setTimeout(() => {\n if (!calledFatalError) {\n // it was probably case 1, let's treat err as the sendErr and call onFatalError\n calledFatalError = true;\n onFatalError(firstError, error);\n } else {\n // it was probably case 2, our first error finished capturing while we waited, cool, do nothing\n }\n }, timeout); // capturing could take at least sendTimeout to fail, plus an arbitrary second for how long it takes to collect surrounding source etc\n }\n }\n }\n },\n { _errorHandler: true },\n );\n}\n"],"names":[],"mappings":";;;;AAgCA,MAAM,gBAAA,GAAmB,qBAAqB;;AAE9C;AACA;AACA;AACa,MAAA,8BAAA,GAAiC,iBAAiB,CAAC,CAAC,OAAO,GAAwC,EAAE,KAAK;AACvH,EAAE,MAAM,sBAAsB;AAC9B,IAAI,oCAAoC,EAAE,KAAK;AAC/C,IAAI,GAAG,OAAO;AACd,GAAG;;AAEH,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAc;AAC9B,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAC3F,KAAK;AACL,GAAG;AACH,CAAC;;AAID;AACO,SAAS,gBAAgB,CAAC,MAAM,EAAc,OAAO,EAA4C;AACxG,EAAE,MAAM,OAAQ,GAAE,IAAI;AACtB,EAAE,IAAI,gBAAgB,GAAY,KAAK;AACvC,EAAE,IAAI,iBAAiB,GAAY,KAAK;AACxC,EAAE,IAAI,gBAAgB,GAAY,KAAK;AACvC,EAAE,IAAI,UAAU;;AAEhB,EAAE,MAAM,aAAc,GAAE,MAAM,CAAC,UAAU,EAAE;;AAE3C,EAAE,OAAO,MAAM,CAAC,MAAM;AACtB,IAAI,CAAC,KAAK,KAAkB;AAC5B,MAAM,IAAI,YAAY,GAAwB,iBAAiB;;AAE/D,MAAM,IAAI,OAAO,CAAC,YAAY,EAAE;AAChC,QAAQ,YAAa,GAAE,OAAO,CAAC,YAAY;AAC3C,aAAa,IAAI,aAAa,CAAC,YAAY,EAAE;AAC7C,QAAQ,YAAa,GAAE,aAAa,CAAC,YAAa;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,0BAAA,GAA6B,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAE,G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ACA;AACA,YAAY,iBAAA,GAAoB,IAAI;AACpC,YAAY,UAAU,CAAC,MAAM;AAC7B,cAAc,IAAI,CAAC,gBAAgB,EAAE;AACrC;AACA,gBAAgB,gBAAA,GAAmB,IAAI;AACvC,gBAAgB,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC;AAC/C;AAGA,aAAa,EAAE,OAAO,CAAC,CAAA;AACvB;AACA;AACA;AACA,KAAK;AACL,IAAI,EAAE,aAAa,EAAE,IAAA,EAAM;AAC3B,GAAG;AACH;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { defineIntegration, getClient, captureException, consoleSandbox } from '@sentry/core';
|
|
2
|
+
import { logAndExitProcess } from '../utils/errorhandling.js';
|
|
3
|
+
|
|
4
|
+
const INTEGRATION_NAME = 'OnUnhandledRejection';
|
|
5
|
+
|
|
6
|
+
const _onUnhandledRejectionIntegration = ((options = {}) => {
|
|
7
|
+
const opts = {
|
|
8
|
+
mode: 'warn',
|
|
9
|
+
...options,
|
|
10
|
+
} ;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
name: INTEGRATION_NAME,
|
|
14
|
+
setup(client) {
|
|
15
|
+
global.process.on('unhandledRejection', makeUnhandledPromiseHandler(client, opts));
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}) ;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add a global promise rejection handler.
|
|
22
|
+
*/
|
|
23
|
+
const onUnhandledRejectionIntegration = defineIntegration(_onUnhandledRejectionIntegration);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Send an exception with reason
|
|
27
|
+
* @param reason string
|
|
28
|
+
* @param promise promise
|
|
29
|
+
*
|
|
30
|
+
* Exported only for tests.
|
|
31
|
+
*/
|
|
32
|
+
function makeUnhandledPromiseHandler(
|
|
33
|
+
client,
|
|
34
|
+
options,
|
|
35
|
+
) {
|
|
36
|
+
return function sendUnhandledPromise(reason, promise) {
|
|
37
|
+
if (getClient() !== client) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const level = options.mode === 'strict' ? 'fatal' : 'error';
|
|
42
|
+
|
|
43
|
+
captureException(reason, {
|
|
44
|
+
originalException: promise,
|
|
45
|
+
captureContext: {
|
|
46
|
+
extra: { unhandledPromiseRejection: true },
|
|
47
|
+
level,
|
|
48
|
+
},
|
|
49
|
+
mechanism: {
|
|
50
|
+
handled: false,
|
|
51
|
+
type: 'onunhandledrejection',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
handleRejection(reason, options.mode);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Handler for `mode` option
|
|
61
|
+
*/
|
|
62
|
+
function handleRejection(reason, mode) {
|
|
63
|
+
// https://github.com/nodejs/node/blob/7cf6f9e964aa00772965391c23acda6d71972a9a/lib/internal/process/promises.js#L234-L240
|
|
64
|
+
const rejectionWarning =
|
|
65
|
+
'This error originated either by ' +
|
|
66
|
+
'throwing inside of an async function without a catch block, ' +
|
|
67
|
+
'or by rejecting a promise which was not handled with .catch().' +
|
|
68
|
+
' The promise rejected with the reason:';
|
|
69
|
+
|
|
70
|
+
/* eslint-disable no-console */
|
|
71
|
+
if (mode === 'warn') {
|
|
72
|
+
consoleSandbox(() => {
|
|
73
|
+
console.warn(rejectionWarning);
|
|
74
|
+
console.error(reason && typeof reason === 'object' && 'stack' in reason ? reason.stack : reason);
|
|
75
|
+
});
|
|
76
|
+
} else if (mode === 'strict') {
|
|
77
|
+
consoleSandbox(() => {
|
|
78
|
+
console.warn(rejectionWarning);
|
|
79
|
+
});
|
|
80
|
+
logAndExitProcess(reason);
|
|
81
|
+
}
|
|
82
|
+
/* eslint-enable no-console */
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { makeUnhandledPromiseHandler, onUnhandledRejectionIntegration };
|
|
86
|
+
//# sourceMappingURL=onunhandledrejection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onunhandledrejection.js","sources":["../../../src/integrations/onunhandledrejection.ts"],"sourcesContent":["import type { Client, IntegrationFn, SeverityLevel } from '@sentry/core';\nimport { captureException, consoleSandbox, defineIntegration, getClient } from '@sentry/core';\nimport { logAndExitProcess } from '../utils/errorhandling';\n\ntype UnhandledRejectionMode = 'none' | 'warn' | 'strict';\n\ninterface OnUnhandledRejectionOptions {\n /**\n * Option deciding what to do after capturing unhandledRejection,\n * that mimicks behavior of node's --unhandled-rejection flag.\n */\n mode: UnhandledRejectionMode;\n}\n\nconst INTEGRATION_NAME = 'OnUnhandledRejection';\n\nconst _onUnhandledRejectionIntegration = ((options: Partial<OnUnhandledRejectionOptions> = {}) => {\n const opts = {\n mode: 'warn',\n ...options,\n } satisfies OnUnhandledRejectionOptions;\n\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n global.process.on('unhandledRejection', makeUnhandledPromiseHandler(client, opts));\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Add a global promise rejection handler.\n */\nexport const onUnhandledRejectionIntegration = defineIntegration(_onUnhandledRejectionIntegration);\n\n/**\n * Send an exception with reason\n * @param reason string\n * @param promise promise\n *\n * Exported only for tests.\n */\nexport function makeUnhandledPromiseHandler(\n client: Client,\n options: OnUnhandledRejectionOptions,\n): (reason: unknown, promise: unknown) => void {\n return function sendUnhandledPromise(reason: unknown, promise: unknown): void {\n if (getClient() !== client) {\n return;\n }\n\n const level: SeverityLevel = options.mode === 'strict' ? 'fatal' : 'error';\n\n captureException(reason, {\n originalException: promise,\n captureContext: {\n extra: { unhandledPromiseRejection: true },\n level,\n },\n mechanism: {\n handled: false,\n type: 'onunhandledrejection',\n },\n });\n\n handleRejection(reason, options.mode);\n };\n}\n\n/**\n * Handler for `mode` option\n */\nfunction handleRejection(reason: unknown, mode: UnhandledRejectionMode): void {\n // https://github.com/nodejs/node/blob/7cf6f9e964aa00772965391c23acda6d71972a9a/lib/internal/process/promises.js#L234-L240\n const rejectionWarning =\n 'This error originated either by ' +\n 'throwing inside of an async function without a catch block, ' +\n 'or by rejecting a promise which was not handled with .catch().' +\n ' The promise rejected with the reason:';\n\n /* eslint-disable no-console */\n if (mode === 'warn') {\n consoleSandbox(() => {\n console.warn(rejectionWarning);\n console.error(reason && typeof reason === 'object' && 'stack' in reason ? reason.stack : reason);\n });\n } else if (mode === 'strict') {\n consoleSandbox(() => {\n console.warn(rejectionWarning);\n });\n logAndExitProcess(reason);\n }\n /* eslint-enable no-console */\n}\n"],"names":[],"mappings":";;;AAcA,MAAM,gBAAA,GAAmB,sBAAsB;;AAE/C,MAAM,gCAAA,IAAoC,CAAC,OAAO,GAAyC,EAAE,KAAK;AAClG,EAAE,MAAM,OAAO;AACf,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,GAAG,OAAO;AACd,GAAI;;AAEJ,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,2BAA2B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxF,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;MACa,+BAAgC,GAAE,iBAAiB,CAAC,gCAAgC;;AAEjG;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,2BAA2B;AAC3C,EAAE,MAAM;AACR,EAAE,OAAO;AACT,EAA+C;AAC/C,EAAE,OAAO,SAAS,oBAAoB,CAAC,MAAM,EAAW,OAAO,EAAiB;AAChF,IAAI,IAAI,SAAS,EAAG,KAAI,MAAM,EAAE;AAChC,MAAM;AACN;;AAEA,IAAI,MAAM,KAAK,GAAkB,OAAO,CAAC,IAAK,KAAI,QAAS,GAAE,OAAQ,GAAE,OAAO;;AAE9E,IAAI,gBAAgB,CAAC,MAAM,EAAE;AAC7B,MAAM,iBAAiB,EAAE,OAAO;AA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