@sentry/node 9.35.0 → 9.36.0-alpha.1
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/index.js +38 -56
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/fs.js +2 -2
- package/build/cjs/integrations/fs.js.map +1 -1
- package/build/cjs/integrations/http/index.js +7 -11
- package/build/cjs/integrations/http/index.js.map +1 -1
- package/build/cjs/integrations/node-fetch/index.js +4 -5
- package/build/cjs/integrations/node-fetch/index.js.map +1 -1
- package/build/cjs/integrations/tracing/amqplib.js +4 -5
- package/build/cjs/integrations/tracing/amqplib.js.map +1 -1
- package/build/cjs/integrations/tracing/connect.js +3 -4
- 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 +5 -7
- 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 +3 -4
- package/build/cjs/integrations/tracing/graphql.js.map +1 -1
- package/build/cjs/integrations/tracing/hapi/index.js +3 -4
- package/build/cjs/integrations/tracing/hapi/index.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka.js +4 -5
- 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 +4 -6
- 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 +3 -4
- package/build/cjs/integrations/tracing/mongo.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose.js +3 -4
- 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 +3 -4
- package/build/cjs/integrations/tracing/mysql2.js.map +1 -1
- package/build/cjs/integrations/tracing/postgres.js +3 -4
- package/build/cjs/integrations/tracing/postgres.js.map +1 -1
- package/build/cjs/integrations/tracing/postgresjs.js +3 -4
- 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/preload.js +2 -2
- package/build/cjs/preload.js.map +1 -1
- package/build/cjs/sdk/index.js +22 -203
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +4 -22
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/esm/index.js +2 -21
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/fs.js +1 -1
- package/build/esm/integrations/fs.js.map +1 -1
- package/build/esm/integrations/http/index.js +1 -5
- package/build/esm/integrations/http/index.js.map +1 -1
- package/build/esm/integrations/node-fetch/index.js +2 -3
- package/build/esm/integrations/node-fetch/index.js.map +1 -1
- package/build/esm/integrations/tracing/amqplib.js +1 -2
- package/build/esm/integrations/tracing/amqplib.js.map +1 -1
- package/build/esm/integrations/tracing/connect.js +1 -2
- 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 +2 -4
- 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 +2 -3
- package/build/esm/integrations/tracing/graphql.js.map +1 -1
- package/build/esm/integrations/tracing/hapi/index.js +1 -2
- package/build/esm/integrations/tracing/hapi/index.js.map +1 -1
- package/build/esm/integrations/tracing/kafka.js +1 -2
- 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 +2 -4
- 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 +1 -2
- package/build/esm/integrations/tracing/mongo.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose.js +1 -2
- 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 +1 -2
- package/build/esm/integrations/tracing/mysql2.js.map +1 -1
- package/build/esm/integrations/tracing/postgres.js +1 -2
- package/build/esm/integrations/tracing/postgres.js.map +1 -1
- package/build/esm/integrations/tracing/postgresjs.js +2 -3
- 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/package.json +1 -1
- package/build/esm/preload.js +1 -1
- package/build/esm/preload.js.map +1 -1
- package/build/esm/sdk/index.js +22 -202
- package/build/esm/sdk/index.js.map +1 -1
- package/build/esm/sdk/initOtel.js +3 -21
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/types/index.d.ts +2 -21
- package/build/types/index.d.ts.map +1 -1
- 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/node-fetch/index.d.ts.map +1 -1
- 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/sdk/index.d.ts +2 -6
- 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/types.d.ts +1 -1
- package/build/types/types.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +2 -21
- package/build/types-ts3.8/integrations/http/index.d.ts +1 -1
- package/build/types-ts3.8/sdk/index.d.ts +2 -6
- package/build/types-ts3.8/sdk/initOtel.d.ts +1 -1
- package/build/types-ts3.8/types.d.ts +1 -1
- package/package.json +4 -3
- package/build/cjs/cron/common.js +0 -56
- package/build/cjs/cron/common.js.map +0 -1
- package/build/cjs/cron/cron.js +0 -112
- package/build/cjs/cron/cron.js.map +0 -1
- package/build/cjs/cron/index.js +0 -15
- package/build/cjs/cron/index.js.map +0 -1
- package/build/cjs/cron/node-cron.js +0 -71
- package/build/cjs/cron/node-cron.js.map +0 -1
- package/build/cjs/cron/node-schedule.js +0 -65
- package/build/cjs/cron/node-schedule.js.map +0 -1
- package/build/cjs/integrations/anr/index.js +0 -238
- package/build/cjs/integrations/anr/index.js.map +0 -1
- package/build/cjs/integrations/childProcess.js +0 -100
- package/build/cjs/integrations/childProcess.js.map +0 -1
- package/build/cjs/integrations/context.js +0 -457
- package/build/cjs/integrations/context.js.map +0 -1
- package/build/cjs/integrations/contextlines.js +0 -405
- package/build/cjs/integrations/contextlines.js.map +0 -1
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js +0 -558
- package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +0 -1
- package/build/cjs/integrations/local-variables/common.js +0 -69
- package/build/cjs/integrations/local-variables/common.js.map +0 -1
- package/build/cjs/integrations/local-variables/index.js +0 -12
- package/build/cjs/integrations/local-variables/index.js.map +0 -1
- package/build/cjs/integrations/local-variables/local-variables-async.js +0 -143
- package/build/cjs/integrations/local-variables/local-variables-async.js.map +0 -1
- package/build/cjs/integrations/local-variables/local-variables-sync.js +0 -410
- package/build/cjs/integrations/local-variables/local-variables-sync.js.map +0 -1
- package/build/cjs/integrations/modules.js +0 -135
- package/build/cjs/integrations/modules.js.map +0 -1
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js +0 -291
- package/build/cjs/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +0 -1
- package/build/cjs/integrations/onuncaughtexception.js +0 -134
- package/build/cjs/integrations/onuncaughtexception.js.map +0 -1
- package/build/cjs/integrations/onunhandledrejection.js +0 -89
- package/build/cjs/integrations/onunhandledrejection.js.map +0 -1
- package/build/cjs/integrations/processSession.js +0 -36
- package/build/cjs/integrations/processSession.js.map +0 -1
- package/build/cjs/integrations/spotlight.js +0 -101
- package/build/cjs/integrations/spotlight.js.map +0 -1
- package/build/cjs/integrations/winston.js +0 -151
- package/build/cjs/integrations/winston.js.map +0 -1
- package/build/cjs/logs/capture.js +0 -29
- package/build/cjs/logs/capture.js.map +0 -1
- package/build/cjs/logs/exports.js +0 -178
- package/build/cjs/logs/exports.js.map +0 -1
- package/build/cjs/nodeVersion.js +0 -12
- package/build/cjs/nodeVersion.js.map +0 -1
- package/build/cjs/otel/contextManager.js +0 -16
- package/build/cjs/otel/contextManager.js.map +0 -1
- package/build/cjs/otel/instrument.js +0 -139
- package/build/cjs/otel/instrument.js.map +0 -1
- package/build/cjs/proxy/base.js +0 -122
- package/build/cjs/proxy/base.js.map +0 -1
- package/build/cjs/proxy/index.js +0 -173
- package/build/cjs/proxy/index.js.map +0 -1
- package/build/cjs/proxy/parse-proxy-response.js +0 -104
- package/build/cjs/proxy/parse-proxy-response.js.map +0 -1
- package/build/cjs/sdk/api.js +0 -117
- package/build/cjs/sdk/api.js.map +0 -1
- package/build/cjs/sdk/client.js +0 -156
- package/build/cjs/sdk/client.js.map +0 -1
- package/build/cjs/transports/http.js +0 -158
- package/build/cjs/transports/http.js.map +0 -1
- package/build/cjs/utils/addOriginToSpan.js +0 -11
- package/build/cjs/utils/addOriginToSpan.js.map +0 -1
- package/build/cjs/utils/baggage.js +0 -36
- package/build/cjs/utils/baggage.js.map +0 -1
- package/build/cjs/utils/commonjs.js +0 -13
- package/build/cjs/utils/commonjs.js.map +0 -1
- package/build/cjs/utils/createMissingInstrumentationContext.js +0 -11
- package/build/cjs/utils/createMissingInstrumentationContext.js.map +0 -1
- package/build/cjs/utils/debug.js +0 -23
- package/build/cjs/utils/debug.js.map +0 -1
- package/build/cjs/utils/ensureIsWrapped.js +0 -41
- package/build/cjs/utils/ensureIsWrapped.js.map +0 -1
- package/build/cjs/utils/envToBool.js +0 -32
- package/build/cjs/utils/envToBool.js.map +0 -1
- package/build/cjs/utils/errorhandling.js +0 -42
- package/build/cjs/utils/errorhandling.js.map +0 -1
- package/build/cjs/utils/getRequestUrl.js +0 -18
- package/build/cjs/utils/getRequestUrl.js.map +0 -1
- package/build/cjs/utils/module.js +0 -60
- package/build/cjs/utils/module.js.map +0 -1
- package/build/esm/cron/common.js +0 -54
- package/build/esm/cron/common.js.map +0 -1
- package/build/esm/cron/cron.js +0 -110
- package/build/esm/cron/cron.js.map +0 -1
- package/build/esm/cron/index.js +0 -13
- package/build/esm/cron/index.js.map +0 -1
- package/build/esm/cron/node-cron.js +0 -69
- package/build/esm/cron/node-cron.js.map +0 -1
- package/build/esm/cron/node-schedule.js +0 -63
- package/build/esm/cron/node-schedule.js.map +0 -1
- package/build/esm/integrations/anr/index.js +0 -234
- package/build/esm/integrations/anr/index.js.map +0 -1
- package/build/esm/integrations/anr/worker-script.js +0 -2
- package/build/esm/integrations/childProcess.js +0 -98
- package/build/esm/integrations/childProcess.js.map +0 -1
- package/build/esm/integrations/context.js +0 -451
- package/build/esm/integrations/context.js.map +0 -1
- package/build/esm/integrations/contextlines.js +0 -399
- package/build/esm/integrations/contextlines.js.map +0 -1
- package/build/esm/integrations/http/SentryHttpInstrumentation.js +0 -555
- package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +0 -1
- package/build/esm/integrations/local-variables/common.js +0 -64
- package/build/esm/integrations/local-variables/common.js.map +0 -1
- package/build/esm/integrations/local-variables/index.js +0 -10
- package/build/esm/integrations/local-variables/index.js.map +0 -1
- package/build/esm/integrations/local-variables/local-variables-async.js +0 -140
- package/build/esm/integrations/local-variables/local-variables-async.js.map +0 -1
- package/build/esm/integrations/local-variables/local-variables-sync.js +0 -405
- package/build/esm/integrations/local-variables/local-variables-sync.js.map +0 -1
- package/build/esm/integrations/local-variables/worker-script.js +0 -2
- package/build/esm/integrations/modules.js +0 -133
- package/build/esm/integrations/modules.js.map +0 -1
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js +0 -289
- package/build/esm/integrations/node-fetch/SentryNodeFetchInstrumentation.js.map +0 -1
- package/build/esm/integrations/onuncaughtexception.js +0 -131
- package/build/esm/integrations/onuncaughtexception.js.map +0 -1
- package/build/esm/integrations/onunhandledrejection.js +0 -86
- package/build/esm/integrations/onunhandledrejection.js.map +0 -1
- package/build/esm/integrations/processSession.js +0 -34
- package/build/esm/integrations/processSession.js.map +0 -1
- package/build/esm/integrations/spotlight.js +0 -98
- package/build/esm/integrations/spotlight.js.map +0 -1
- package/build/esm/integrations/winston.js +0 -149
- package/build/esm/integrations/winston.js.map +0 -1
- package/build/esm/logs/capture.js +0 -27
- package/build/esm/logs/capture.js.map +0 -1
- package/build/esm/logs/exports.js +0 -170
- package/build/esm/logs/exports.js.map +0 -1
- package/build/esm/nodeVersion.js +0 -8
- package/build/esm/nodeVersion.js.map +0 -1
- package/build/esm/otel/contextManager.js +0 -14
- package/build/esm/otel/contextManager.js.map +0 -1
- package/build/esm/otel/instrument.js +0 -135
- package/build/esm/otel/instrument.js.map +0 -1
- package/build/esm/proxy/base.js +0 -120
- package/build/esm/proxy/base.js.map +0 -1
- package/build/esm/proxy/index.js +0 -171
- package/build/esm/proxy/index.js.map +0 -1
- package/build/esm/proxy/parse-proxy-response.js +0 -102
- package/build/esm/proxy/parse-proxy-response.js.map +0 -1
- package/build/esm/sdk/api.js +0 -114
- package/build/esm/sdk/api.js.map +0 -1
- package/build/esm/sdk/client.js +0 -154
- package/build/esm/sdk/client.js.map +0 -1
- package/build/esm/transports/http.js +0 -156
- package/build/esm/transports/http.js.map +0 -1
- package/build/esm/utils/addOriginToSpan.js +0 -9
- package/build/esm/utils/addOriginToSpan.js.map +0 -1
- package/build/esm/utils/baggage.js +0 -34
- package/build/esm/utils/baggage.js.map +0 -1
- package/build/esm/utils/commonjs.js +0 -11
- package/build/esm/utils/commonjs.js.map +0 -1
- package/build/esm/utils/createMissingInstrumentationContext.js +0 -9
- package/build/esm/utils/createMissingInstrumentationContext.js.map +0 -1
- package/build/esm/utils/debug.js +0 -21
- package/build/esm/utils/debug.js.map +0 -1
- package/build/esm/utils/ensureIsWrapped.js +0 -39
- package/build/esm/utils/ensureIsWrapped.js.map +0 -1
- package/build/esm/utils/envToBool.js +0 -28
- package/build/esm/utils/envToBool.js.map +0 -1
- package/build/esm/utils/errorhandling.js +0 -40
- package/build/esm/utils/errorhandling.js.map +0 -1
- package/build/esm/utils/getRequestUrl.js +0 -16
- package/build/esm/utils/getRequestUrl.js.map +0 -1
- package/build/esm/utils/module.js +0 -58
- package/build/esm/utils/module.js.map +0 -1
- package/build/types/cron/common.d.ts +0 -5
- package/build/types/cron/common.d.ts.map +0 -1
- package/build/types/cron/cron.d.ts +0 -43
- package/build/types/cron/cron.d.ts.map +0 -1
- package/build/types/cron/index.d.ts +0 -10
- package/build/types/cron/index.d.ts.map +0 -1
- package/build/types/cron/node-cron.d.ts +0 -27
- package/build/types/cron/node-cron.d.ts.map +0 -1
- package/build/types/cron/node-schedule.d.ts +0 -19
- package/build/types/cron/node-schedule.d.ts.map +0 -1
- package/build/types/integrations/anr/common.d.ts +0 -52
- package/build/types/integrations/anr/common.d.ts.map +0 -1
- package/build/types/integrations/anr/index.d.ts +0 -13
- package/build/types/integrations/anr/index.d.ts.map +0 -1
- package/build/types/integrations/anr/worker.d.ts +0 -2
- package/build/types/integrations/anr/worker.d.ts.map +0 -1
- package/build/types/integrations/childProcess.d.ts +0 -20
- package/build/types/integrations/childProcess.d.ts.map +0 -1
- package/build/types/integrations/context.d.ts +0 -30
- package/build/types/integrations/context.d.ts.map +0 -1
- package/build/types/integrations/contextlines.d.ts +0 -31
- package/build/types/integrations/contextlines.d.ts.map +0 -1
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +0 -131
- package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +0 -1
- package/build/types/integrations/local-variables/common.d.ts +0 -66
- package/build/types/integrations/local-variables/common.d.ts.map +0 -1
- package/build/types/integrations/local-variables/index.d.ts +0 -4
- package/build/types/integrations/local-variables/index.d.ts.map +0 -1
- package/build/types/integrations/local-variables/local-variables-async.d.ts +0 -7
- package/build/types/integrations/local-variables/local-variables-async.d.ts.map +0 -1
- package/build/types/integrations/local-variables/local-variables-sync.d.ts +0 -34
- package/build/types/integrations/local-variables/local-variables-sync.d.ts.map +0 -1
- package/build/types/integrations/local-variables/worker.d.ts +0 -2
- package/build/types/integrations/local-variables/worker.d.ts.map +0 -1
- package/build/types/integrations/modules.d.ts +0 -17
- package/build/types/integrations/modules.d.ts.map +0 -1
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +0 -56
- package/build/types/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts.map +0 -1
- package/build/types/integrations/onuncaughtexception.d.ts +0 -31
- package/build/types/integrations/onuncaughtexception.d.ts.map +0 -1
- package/build/types/integrations/onunhandledrejection.d.ts +0 -23
- package/build/types/integrations/onunhandledrejection.d.ts.map +0 -1
- package/build/types/integrations/processSession.d.ts +0 -5
- package/build/types/integrations/processSession.d.ts.map +0 -1
- package/build/types/integrations/spotlight.d.ts +0 -18
- package/build/types/integrations/spotlight.d.ts.map +0 -1
- package/build/types/integrations/winston.d.ts +0 -44
- package/build/types/integrations/winston.d.ts.map +0 -1
- package/build/types/logs/capture.d.ts +0 -11
- package/build/types/logs/capture.d.ts.map +0 -1
- package/build/types/logs/exports.d.ts +0 -150
- package/build/types/logs/exports.d.ts.map +0 -1
- package/build/types/nodeVersion.d.ts +0 -8
- package/build/types/nodeVersion.d.ts.map +0 -1
- package/build/types/otel/contextManager.d.ts +0 -10
- package/build/types/otel/contextManager.d.ts.map +0 -1
- package/build/types/otel/instrument.d.ts +0 -23
- package/build/types/otel/instrument.d.ts.map +0 -1
- package/build/types/proxy/base.d.ts +0 -65
- package/build/types/proxy/base.d.ts.map +0 -1
- package/build/types/proxy/helpers.d.ts +0 -42
- package/build/types/proxy/helpers.d.ts.map +0 -1
- package/build/types/proxy/index.d.ts +0 -73
- package/build/types/proxy/index.d.ts.map +0 -1
- package/build/types/proxy/parse-proxy-response.d.ts +0 -43
- package/build/types/proxy/parse-proxy-response.d.ts.map +0 -1
- package/build/types/sdk/api.d.ts +0 -8
- package/build/types/sdk/api.d.ts.map +0 -1
- package/build/types/sdk/client.d.ts +0 -29
- package/build/types/sdk/client.d.ts.map +0 -1
- package/build/types/sdk/scope.d.ts +0 -7
- package/build/types/sdk/scope.d.ts.map +0 -1
- package/build/types/transports/http-module.d.ts +0 -31
- package/build/types/transports/http-module.d.ts.map +0 -1
- package/build/types/transports/http.d.ts +0 -21
- package/build/types/transports/http.d.ts.map +0 -1
- package/build/types/transports/index.d.ts +0 -3
- package/build/types/transports/index.d.ts.map +0 -1
- package/build/types/utils/addOriginToSpan.d.ts +0 -5
- package/build/types/utils/addOriginToSpan.d.ts.map +0 -1
- package/build/types/utils/baggage.d.ts +0 -6
- package/build/types/utils/baggage.d.ts.map +0 -1
- package/build/types/utils/commonjs.d.ts +0 -3
- package/build/types/utils/commonjs.d.ts.map +0 -1
- package/build/types/utils/createMissingInstrumentationContext.d.ts +0 -3
- package/build/types/utils/createMissingInstrumentationContext.d.ts.map +0 -1
- package/build/types/utils/debug.d.ts +0 -5
- package/build/types/utils/debug.d.ts.map +0 -1
- package/build/types/utils/ensureIsWrapped.d.ts +0 -5
- package/build/types/utils/ensureIsWrapped.d.ts.map +0 -1
- package/build/types/utils/entry-point.d.ts +0 -24
- package/build/types/utils/entry-point.d.ts.map +0 -1
- package/build/types/utils/envToBool.d.ts +0 -13
- package/build/types/utils/envToBool.d.ts.map +0 -1
- package/build/types/utils/errorhandling.d.ts +0 -5
- package/build/types/utils/errorhandling.d.ts.map +0 -1
- package/build/types/utils/getRequestUrl.d.ts +0 -5
- package/build/types/utils/getRequestUrl.d.ts.map +0 -1
- package/build/types/utils/module.d.ts +0 -3
- package/build/types/utils/module.d.ts.map +0 -1
- package/build/types/utils/prepareEvent.d.ts +0 -17
- package/build/types/utils/prepareEvent.d.ts.map +0 -1
- package/build/types-ts3.8/cron/common.d.ts +0 -5
- package/build/types-ts3.8/cron/cron.d.ts +0 -43
- package/build/types-ts3.8/cron/index.d.ts +0 -10
- package/build/types-ts3.8/cron/node-cron.d.ts +0 -27
- package/build/types-ts3.8/cron/node-schedule.d.ts +0 -19
- package/build/types-ts3.8/integrations/anr/common.d.ts +0 -52
- package/build/types-ts3.8/integrations/anr/index.d.ts +0 -13
- package/build/types-ts3.8/integrations/anr/worker.d.ts +0 -2
- package/build/types-ts3.8/integrations/childProcess.d.ts +0 -20
- package/build/types-ts3.8/integrations/context.d.ts +0 -30
- package/build/types-ts3.8/integrations/contextlines.d.ts +0 -31
- package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +0 -133
- package/build/types-ts3.8/integrations/local-variables/common.d.ts +0 -66
- package/build/types-ts3.8/integrations/local-variables/index.d.ts +0 -4
- package/build/types-ts3.8/integrations/local-variables/local-variables-async.d.ts +0 -7
- package/build/types-ts3.8/integrations/local-variables/local-variables-sync.d.ts +0 -34
- package/build/types-ts3.8/integrations/local-variables/worker.d.ts +0 -2
- package/build/types-ts3.8/integrations/modules.d.ts +0 -17
- package/build/types-ts3.8/integrations/node-fetch/SentryNodeFetchInstrumentation.d.ts +0 -56
- package/build/types-ts3.8/integrations/onuncaughtexception.d.ts +0 -31
- package/build/types-ts3.8/integrations/onunhandledrejection.d.ts +0 -23
- package/build/types-ts3.8/integrations/processSession.d.ts +0 -5
- package/build/types-ts3.8/integrations/spotlight.d.ts +0 -18
- package/build/types-ts3.8/integrations/winston.d.ts +0 -44
- package/build/types-ts3.8/logs/capture.d.ts +0 -18
- package/build/types-ts3.8/logs/exports.d.ts +0 -150
- package/build/types-ts3.8/nodeVersion.d.ts +0 -8
- package/build/types-ts3.8/otel/contextManager.d.ts +0 -10
- package/build/types-ts3.8/otel/instrument.d.ts +0 -23
- package/build/types-ts3.8/proxy/base.d.ts +0 -60
- package/build/types-ts3.8/proxy/helpers.d.ts +0 -38
- package/build/types-ts3.8/proxy/index.d.ts +0 -74
- package/build/types-ts3.8/proxy/parse-proxy-response.d.ts +0 -40
- package/build/types-ts3.8/sdk/api.d.ts +0 -8
- package/build/types-ts3.8/sdk/client.d.ts +0 -32
- package/build/types-ts3.8/sdk/scope.d.ts +0 -7
- package/build/types-ts3.8/transports/http-module.d.ts +0 -28
- package/build/types-ts3.8/transports/http.d.ts +0 -20
- package/build/types-ts3.8/transports/index.d.ts +0 -3
- package/build/types-ts3.8/utils/addOriginToSpan.d.ts +0 -5
- package/build/types-ts3.8/utils/baggage.d.ts +0 -6
- package/build/types-ts3.8/utils/commonjs.d.ts +0 -3
- package/build/types-ts3.8/utils/createMissingInstrumentationContext.d.ts +0 -3
- package/build/types-ts3.8/utils/debug.d.ts +0 -5
- package/build/types-ts3.8/utils/ensureIsWrapped.d.ts +0 -5
- package/build/types-ts3.8/utils/entry-point.d.ts +0 -24
- package/build/types-ts3.8/utils/envToBool.d.ts +0 -13
- package/build/types-ts3.8/utils/errorhandling.d.ts +0 -5
- package/build/types-ts3.8/utils/getRequestUrl.d.ts +0 -5
- package/build/types-ts3.8/utils/module.d.ts +0 -3
- package/build/types-ts3.8/utils/prepareEvent.d.ts +0 -17
|
@@ -2,17 +2,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const instrumentationExpress = require('@opentelemetry/instrumentation-express');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
|
+
const nodeCore = require('@sentry/node-core');
|
|
5
6
|
const debugBuild = require('../../debug-build.js');
|
|
6
|
-
const instrument = require('../../otel/instrument.js');
|
|
7
|
-
const addOriginToSpan = require('../../utils/addOriginToSpan.js');
|
|
8
|
-
const ensureIsWrapped = require('../../utils/ensureIsWrapped.js');
|
|
9
7
|
const instrumentation = require('./express-v5/instrumentation.js');
|
|
10
8
|
|
|
11
9
|
const INTEGRATION_NAME = 'Express';
|
|
12
10
|
const INTEGRATION_NAME_V5 = 'Express-V5';
|
|
13
11
|
|
|
14
12
|
function requestHook(span) {
|
|
15
|
-
|
|
13
|
+
nodeCore.addOriginToSpan(span, 'auto.http.otel.express');
|
|
16
14
|
|
|
17
15
|
const attributes = core.spanToJSON(span).data;
|
|
18
16
|
// this is one of: middleware, request_handler, router
|
|
@@ -43,7 +41,7 @@ function spanNameHook(info, defaultName) {
|
|
|
43
41
|
return defaultName;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
const instrumentExpress =
|
|
44
|
+
const instrumentExpress = nodeCore.generateInstrumentOnce(
|
|
47
45
|
INTEGRATION_NAME,
|
|
48
46
|
() =>
|
|
49
47
|
new instrumentationExpress.ExpressInstrumentation({
|
|
@@ -52,7 +50,7 @@ const instrumentExpress = instrument.generateInstrumentOnce(
|
|
|
52
50
|
}),
|
|
53
51
|
);
|
|
54
52
|
|
|
55
|
-
const instrumentExpressV5 =
|
|
53
|
+
const instrumentExpressV5 = nodeCore.generateInstrumentOnce(
|
|
56
54
|
INTEGRATION_NAME_V5,
|
|
57
55
|
() =>
|
|
58
56
|
new instrumentation.ExpressInstrumentationV5({
|
|
@@ -159,7 +157,7 @@ function setupExpressErrorHandler(
|
|
|
159
157
|
) {
|
|
160
158
|
app.use(expressRequestHandler());
|
|
161
159
|
app.use(expressErrorHandler(options));
|
|
162
|
-
|
|
160
|
+
nodeCore.ensureIsWrapped(app.use, 'express');
|
|
163
161
|
}
|
|
164
162
|
|
|
165
163
|
function getStatusCodeFromResponse(error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sources":["../../../../src/integrations/tracing/express.ts"],"sourcesContent":["import type * as http from 'node:http';\nimport type { Span } from '@opentelemetry/api';\nimport type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express';\nimport { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';\nimport type { IntegrationFn } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getDefaultIsolationScope,\n getIsolationScope,\n httpRequestToRequestData,\n logger,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { generateInstrumentOnce } from '../../otel/instrument';\nimport { addOriginToSpan } from '../../utils/addOriginToSpan';\nimport { ensureIsWrapped } from '../../utils/ensureIsWrapped';\nimport { ExpressInstrumentationV5 } from './express-v5/instrumentation';\n\nconst INTEGRATION_NAME = 'Express';\nconst INTEGRATION_NAME_V5 = 'Express-V5';\n\nfunction requestHook(span: Span): void {\n addOriginToSpan(span, 'auto.http.otel.express');\n\n const attributes = spanToJSON(span).data;\n // this is one of: middleware, request_handler, router\n const type = attributes['express.type'];\n\n if (type) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, `${type}.express`);\n }\n\n // Also update the name, we don't need to \"middleware - \" prefix\n const name = attributes['express.name'];\n if (typeof name === 'string') {\n span.updateName(name);\n }\n}\n\nfunction spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): string {\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && logger.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n return defaultName;\n }\n if (info.layerType === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const req = info.request as { method?: string };\n const method = req.method ? req.method.toUpperCase() : 'GET';\n getIsolationScope().setTransactionName(`${method} ${info.route}`);\n }\n return defaultName;\n}\n\nexport const instrumentExpress = generateInstrumentOnce(\n INTEGRATION_NAME,\n () =>\n new ExpressInstrumentation({\n requestHook: span => requestHook(span),\n spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),\n }),\n);\n\nexport const instrumentExpressV5 = generateInstrumentOnce(\n INTEGRATION_NAME_V5,\n () =>\n new ExpressInstrumentationV5({\n requestHook: span => requestHook(span),\n spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),\n }),\n);\n\nconst _expressIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentExpress();\n instrumentExpressV5();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).\n *\n * If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.\n *\n * For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.expressIntegration()],\n * })\n * ```\n */\nexport const expressIntegration = defineIntegration(_expressIntegration);\n\ninterface MiddlewareError extends Error {\n status?: number | string;\n statusCode?: number | string;\n status_code?: number | string;\n output?: {\n statusCode?: number | string;\n };\n}\n\ntype ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;\n\ntype ExpressErrorMiddleware = (\n error: MiddlewareError,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n) => void;\n\ninterface ExpressHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured middleware error\n */\n shouldHandleError?(this: void, error: MiddlewareError): boolean;\n}\n\n/**\n * An Express-compatible error handler.\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, { mechanism: { type: 'middleware', handled: false } });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(\n request: http.IncomingMessage,\n _res: http.ServerResponse,\n next: () => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n next();\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const express = require(\"express\");\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: { use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n ensureIsWrapped(app.use, 'express');\n}\n\nfunction getStatusCodeFromResponse(error: MiddlewareError): number {\n const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;\n return statusCode ? parseInt(statusCode as string, 10) : 500;\n}\n\n/** Returns true if response code is internal server error */\nfunction defaultShouldHandleError(error: MiddlewareError): boolean {\n const status = getStatusCodeFromResponse(error);\n return status >= 500;\n}\n"],"names":["addOriginToSpan","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","logger","generateInstrumentOnce","ExpressInstrumentation","ExpressInstrumentationV5","defineIntegration","httpRequestToRequestData","captureException","ensureI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;AACA;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"express.js","sources":["../../../../src/integrations/tracing/express.ts"],"sourcesContent":["import type * as http from 'node:http';\nimport type { Span } from '@opentelemetry/api';\nimport type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express';\nimport { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';\nimport type { IntegrationFn } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getDefaultIsolationScope,\n getIsolationScope,\n httpRequestToRequestData,\n logger,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n spanToJSON,\n} from '@sentry/core';\nimport { addOriginToSpan, ensureIsWrapped, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { ExpressInstrumentationV5 } from './express-v5/instrumentation';\n\nconst INTEGRATION_NAME = 'Express';\nconst INTEGRATION_NAME_V5 = 'Express-V5';\n\nfunction requestHook(span: Span): void {\n addOriginToSpan(span, 'auto.http.otel.express');\n\n const attributes = spanToJSON(span).data;\n // this is one of: middleware, request_handler, router\n const type = attributes['express.type'];\n\n if (type) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, `${type}.express`);\n }\n\n // Also update the name, we don't need to \"middleware - \" prefix\n const name = attributes['express.name'];\n if (typeof name === 'string') {\n span.updateName(name);\n }\n}\n\nfunction spanNameHook(info: ExpressRequestInfo<unknown>, defaultName: string): string {\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && logger.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n return defaultName;\n }\n if (info.layerType === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const req = info.request as { method?: string };\n const method = req.method ? req.method.toUpperCase() : 'GET';\n getIsolationScope().setTransactionName(`${method} ${info.route}`);\n }\n return defaultName;\n}\n\nexport const instrumentExpress = generateInstrumentOnce(\n INTEGRATION_NAME,\n () =>\n new ExpressInstrumentation({\n requestHook: span => requestHook(span),\n spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),\n }),\n);\n\nexport const instrumentExpressV5 = generateInstrumentOnce(\n INTEGRATION_NAME_V5,\n () =>\n new ExpressInstrumentationV5({\n requestHook: span => requestHook(span),\n spanNameHook: (info, defaultName) => spanNameHook(info, defaultName),\n }),\n);\n\nconst _expressIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentExpress();\n instrumentExpressV5();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).\n *\n * If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.\n *\n * For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.expressIntegration()],\n * })\n * ```\n */\nexport const expressIntegration = defineIntegration(_expressIntegration);\n\ninterface MiddlewareError extends Error {\n status?: number | string;\n statusCode?: number | string;\n status_code?: number | string;\n output?: {\n statusCode?: number | string;\n };\n}\n\ntype ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;\n\ntype ExpressErrorMiddleware = (\n error: MiddlewareError,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n) => void;\n\ninterface ExpressHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured middleware error\n */\n shouldHandleError?(this: void, error: MiddlewareError): boolean;\n}\n\n/**\n * An Express-compatible error handler.\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, { mechanism: { type: 'middleware', handled: false } });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(\n request: http.IncomingMessage,\n _res: http.ServerResponse,\n next: () => void,\n ): void {\n const normalizedRequest = httpRequestToRequestData(request);\n // Ensure we use the express-enhanced request here, instead of the plain HTTP one\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n\n next();\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const express = require(\"express\");\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: { use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n ensureIsWrapped(app.use, 'express');\n}\n\nfunction getStatusCodeFromResponse(error: MiddlewareError): number {\n const statusCode = error.status || error.statusCode || error.status_code || error.output?.statusCode;\n return statusCode ? parseInt(statusCode as string, 10) : 500;\n}\n\n/** Returns true if response code is internal server error */\nfunction defaultShouldHandleError(error: MiddlewareError): boolean {\n const status = getStatusCodeFromResponse(error);\n return status >= 500;\n}\n"],"names":["addOriginToSpan","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","logger","generateInstrumentOnce","ExpressInstrumentation","ExpressInstrumentationV5","defineIntegration","httpRequestToRequestData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AA,GAAA;AACA;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const dc = require('node:diagnostics_channel');
|
|
4
4
|
const api = require('@opentelemetry/api');
|
|
5
5
|
const core = require('@opentelemetry/core');
|
|
6
6
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
@@ -110,14 +110,14 @@ class FastifyOtelInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
110
110
|
this._handleInitialization = message => {
|
|
111
111
|
message.fastify.register(FastifyInstrumentationPlugin);
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
dc.default.subscribe('fastify.initialization', this._handleInitialization);
|
|
114
114
|
}
|
|
115
115
|
return super.enable();
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
disable() {
|
|
119
119
|
if (this._handleInitialization) {
|
|
120
|
-
|
|
120
|
+
dc.default.unsubscribe('fastify.initialization', this._handleInitialization);
|
|
121
121
|
this._handleInitialization = undefined;
|
|
122
122
|
}
|
|
123
123
|
return super.disable();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../src/integrations/tracing/fastify/fastify-otel/index.js"],"sourcesContent":["/*\nVendored in and modified from @fastify/otel version 0.8.0\nhttps://github.com/fastify/otel/releases/tag/v0.8.0\n\nTried not to modify the original code too much keeping it as a JavaScript CJS module to make it easier to update when required\n\nModifications include:\n- Removed reading of package.json to get the version and package name\n\nMIT License\n\nCopyright (c) 2024 Fastify\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\n\n/* eslint-disable jsdoc/require-jsdoc */\n/* eslint-disable max-lines */\n/* eslint-disable no-param-reassign */\nimport dc from 'node:diagnostics_channel';\nimport { context, diag, propagation, SpanStatusCode, trace } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport {\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_SERVICE_NAME,\n} from '@opentelemetry/semantic-conventions';\nimport * as minimatch from 'minimatch';\n\n// SENTRY VENDOR NOTE\n// Instead of using the package.json file, we hard code the package name and version here.\nconst PACKAGE_NAME = '@fastify/otel';\nconst PACKAGE_VERSION = '0.8.0';\n\n// Constants\nconst SUPPORTED_VERSIONS = '>=4.0.0 <6';\nconst FASTIFY_HOOKS = [\n 'onRequest',\n 'preParsing',\n 'preValidation',\n 'preHandler',\n 'preSerialization',\n 'onSend',\n 'onResponse',\n 'onError',\n];\nconst ATTRIBUTE_NAMES = {\n HOOK_NAME: 'hook.name',\n FASTIFY_TYPE: 'fastify.type',\n HOOK_CALLBACK_NAME: 'hook.callback.name',\n ROOT: 'fastify.root',\n};\nconst HOOK_TYPES = {\n ROUTE: 'route-hook',\n INSTANCE: 'hook',\n HANDLER: 'request-handler',\n};\nconst ANONYMOUS_FUNCTION_NAME = 'anonymous';\n\n// Symbols\nconst kInstrumentation = Symbol('fastify otel instance');\nconst kRequestSpan = Symbol('fastify otel request spans');\nconst kRequestContext = Symbol('fastify otel request context');\nconst kAddHookOriginal = Symbol('fastify otel addhook original');\nconst kSetNotFoundOriginal = Symbol('fastify otel setnotfound original');\nconst kIgnorePaths = Symbol('fastify otel ignore path');\n\nexport class FastifyOtelInstrumentation extends InstrumentationBase {\n constructor(config) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n this.servername = config?.servername ?? process.env.OTEL_SERVICE_NAME ?? 'fastify';\n this[kIgnorePaths] = null;\n this._logger = diag.createComponentLogger({ namespace: PACKAGE_NAME });\n\n if (config?.ignorePaths != null || process.env.OTEL_FASTIFY_IGNORE_PATHS != null) {\n const ignorePaths = config?.ignorePaths ?? process.env.OTEL_FASTIFY_IGNORE_PATHS;\n\n if ((typeof ignorePaths !== 'string' || ignorePaths.length === 0) && typeof ignorePaths !== 'function') {\n throw new TypeError('ignorePaths must be a string or a function');\n }\n\n const globMatcher = minimatch.minimatch;\n\n this[kIgnorePaths] = routeOptions => {\n if (typeof ignorePaths === 'function') {\n return ignorePaths(routeOptions);\n } else {\n return globMatcher(routeOptions.url, ignorePaths);\n }\n };\n }\n }\n\n enable() {\n if (this._handleInitialization === undefined && this.getConfig().registerOnInitialization) {\n const FastifyInstrumentationPlugin = this.plugin();\n this._handleInitialization = message => {\n message.fastify.register(FastifyInstrumentationPlugin);\n };\n dc.subscribe('fastify.initialization', this._handleInitialization);\n }\n return super.enable();\n }\n\n disable() {\n if (this._handleInitialization) {\n dc.unsubscribe('fastify.initialization', this._handleInitialization);\n this._handleInitialization = undefined;\n }\n return super.disable();\n }\n\n // We do not do patching in this instrumentation\n init() {\n return [];\n }\n\n plugin() {\n const instrumentation = this;\n\n FastifyInstrumentationPlugin[Symbol.for('skip-override')] = true;\n FastifyInstrumentationPlugin[Symbol.for('fastify.display-name')] = '@fastify/otel';\n FastifyInstrumentationPlugin[Symbol.for('plugin-meta')] = {\n fastify: SUPPORTED_VERSIONS,\n name: '@fastify/otel',\n };\n\n return FastifyInstrumentationPlugin;\n\n function FastifyInstrumentationPlugin(instance, opts, done) {\n instance.decorate(kInstrumentation, instrumentation);\n // addHook and notfoundHandler are essentially inherited from the prototype\n // what is important is to bound it to the right instance\n instance.decorate(kAddHookOriginal, instance.addHook);\n instance.decorate(kSetNotFoundOriginal, instance.setNotFoundHandler);\n instance.decorateRequest('opentelemetry', function openetelemetry() {\n const ctx = this[kRequestContext];\n const span = this[kRequestSpan];\n return {\n span,\n tracer: instrumentation.tracer,\n context: ctx,\n inject: (carrier, setter) => {\n return propagation.inject(ctx, carrier, setter);\n },\n extract: (carrier, getter) => {\n return propagation.extract(ctx, carrier, getter);\n },\n };\n });\n instance.decorateRequest(kRequestSpan, null);\n instance.decorateRequest(kRequestContext, null);\n\n instance.addHook('onRoute', function (routeOptions) {\n if (instrumentation[kIgnorePaths]?.(routeOptions) === true) {\n instrumentation._logger.debug(\n `Ignoring route instrumentation ${routeOptions.method} ${routeOptions.url} because it matches the ignore path`,\n );\n return;\n }\n\n for (const hook of FASTIFY_HOOKS) {\n if (routeOptions[hook] != null) {\n const handlerLike = routeOptions[hook];\n\n if (typeof handlerLike === 'function') {\n routeOptions[hook] = handlerWrapper(handlerLike, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route -> ${hook}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.ROUTE,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handlerLike.name?.length > 0 ? handlerLike.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n } else if (Array.isArray(handlerLike)) {\n const wrappedHandlers = [];\n\n for (const handler of handlerLike) {\n wrappedHandlers.push(\n handlerWrapper(handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route -> ${hook}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.ROUTE,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME,\n }),\n );\n }\n\n routeOptions[hook] = wrappedHandlers;\n }\n }\n }\n\n // We always want to add the onSend hook to the route to be executed last\n if (routeOptions.onSend != null) {\n routeOptions.onSend = Array.isArray(routeOptions.onSend)\n ? [...routeOptions.onSend, onSendHook]\n : [routeOptions.onSend, onSendHook];\n } else {\n routeOptions.onSend = onSendHook;\n }\n\n // We always want to add the onError hook to the route to be executed last\n if (routeOptions.onError != null) {\n routeOptions.onError = Array.isArray(routeOptions.onError)\n ? [...routeOptions.onError, onErrorHook]\n : [routeOptions.onError, onErrorHook];\n } else {\n routeOptions.onError = onErrorHook;\n }\n\n routeOptions.handler = handlerWrapper(routeOptions.handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.HANDLER,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n routeOptions.handler.name.length > 0 ? routeOptions.handler.name : ANONYMOUS_FUNCTION_NAME,\n });\n });\n\n instance.addHook('onRequest', function (request, _reply, hookDone) {\n if (this[kInstrumentation].isEnabled() === false) {\n return hookDone();\n } else if (\n this[kInstrumentation][kIgnorePaths]?.({\n url: request.url,\n method: request.method,\n }) === true\n ) {\n this[kInstrumentation]._logger.debug(\n `Ignoring request ${request.method} ${request.url} because it matches the ignore path`,\n );\n return hookDone();\n }\n\n let ctx = context.active();\n\n if (trace.getSpan(ctx) == null) {\n ctx = propagation.extract(ctx, request.headers);\n }\n\n const rpcMetadata = getRPCMetadata(ctx);\n\n if (request.routeOptions.url != null && rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = request.routeOptions.url;\n }\n\n /** @type {import('@opentelemetry/api').Span} */\n const span = this[kInstrumentation].tracer.startSpan(\n 'request',\n {\n attributes: {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.ROOT]: '@fastify/otel',\n [ATTR_HTTP_ROUTE]: request.url,\n [ATTR_HTTP_REQUEST_METHOD]: request.method,\n },\n },\n ctx,\n );\n\n request[kRequestContext] = trace.setSpan(ctx, span);\n request[kRequestSpan] = span;\n\n context.with(request[kRequestContext], () => {\n hookDone();\n });\n });\n\n // onResponse is the last hook to be executed, only added for 404 handlers\n instance.addHook('onResponse', function (request, reply, hookDone) {\n const span = request[kRequestSpan];\n\n if (span != null) {\n span.setStatus({\n code: SpanStatusCode.OK,\n message: 'OK',\n });\n span.setAttributes({\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: 404,\n });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone();\n });\n\n instance.addHook = addHookPatched;\n instance.setNotFoundHandler = setNotFoundHandlerPatched;\n\n done();\n\n function onSendHook(request, reply, payload, hookDone) {\n /** @type {import('@opentelemetry/api').Span} */\n const span = request[kRequestSpan];\n\n if (span != null) {\n if (reply.statusCode < 500) {\n span.setStatus({\n code: SpanStatusCode.OK,\n message: 'OK',\n });\n }\n\n span.setAttributes({\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: reply.statusCode,\n });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone(null, payload);\n }\n\n function onErrorHook(request, reply, error, hookDone) {\n /** @type {Span} */\n const span = request[kRequestSpan];\n\n if (span != null) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n }\n\n hookDone();\n }\n\n function addHookPatched(name, hook) {\n const addHookOriginal = this[kAddHookOriginal];\n\n if (FASTIFY_HOOKS.includes(name)) {\n return addHookOriginal.call(\n this,\n name,\n handlerWrapper(hook, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - ${name}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hook.name?.length > 0 ? hook.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n }),\n );\n } else {\n return addHookOriginal.call(this, name, hook);\n }\n }\n\n function setNotFoundHandlerPatched(hooks, handler) {\n const setNotFoundHandlerOriginal = this[kSetNotFoundOriginal];\n if (typeof hooks === 'function') {\n handler = handlerWrapper(hooks, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.name?.length > 0 ? hooks.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n setNotFoundHandlerOriginal.call(this, handler);\n } else {\n if (hooks.preValidation != null) {\n hooks.preValidation = handlerWrapper(hooks.preValidation, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler - preValidation`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.preValidation.name?.length > 0\n ? hooks.preValidation.name\n : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n }\n\n if (hooks.preHandler != null) {\n hooks.preHandler = handlerWrapper(hooks.preHandler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler - preHandler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.preHandler.name?.length > 0\n ? hooks.preHandler.name\n : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n }\n\n handler = handlerWrapper(handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n setNotFoundHandlerOriginal.call(this, hooks, handler);\n }\n }\n\n function handlerWrapper(handler, spanAttributes = {}) {\n return function handlerWrapped(...args) {\n /** @type {FastifyOtelInstrumentation} */\n const instrumentation = this[kInstrumentation];\n const [request] = args;\n\n if (instrumentation.isEnabled() === false) {\n return handler.call(this, ...args);\n }\n\n const ctx = request[kRequestContext] ?? context.active();\n const span = instrumentation.tracer.startSpan(\n `handler - ${\n handler.name?.length > 0\n ? handler.name\n : this.pluginName /* c8 ignore next */ ?? ANONYMOUS_FUNCTION_NAME /* c8 ignore next */\n }`,\n {\n attributes: spanAttributes,\n },\n ctx,\n );\n\n return context.with(\n trace.setSpan(ctx, span),\n function () {\n try {\n const res = handler.call(this, ...args);\n\n if (typeof res?.then === 'function') {\n return res.then(\n result => {\n span.end();\n return result;\n },\n error => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n return Promise.reject(error);\n },\n );\n }\n\n span.end();\n return res;\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n throw error;\n }\n },\n this,\n );\n };\n }\n }\n }\n}\n"],"names":["InstrumentationBase","diag","dc","propagation","ATTR_SERVICE_NAME","ATTR_HTTP_ROUTE","context","trace","getRPCMetadata","RPCType","ATTR_HTTP_REQUEST_METHOD","SpanStatusCode","ATTR_HTTP_RESPONSE_STATUS_CODE"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAiBA;AACA;AACA,MAAM,YAAA,GAAe,eAAe;AACpC,MAAM,eAAA,GAAkB,OAAO;;AAE/B;AACA,MAAM,kBAAA,GAAqB,YAAY;AACvC,MAAM,gBAAgB;AACtB,EAAE,WAAW;AACb,EAAE,YAAY;AACd,EAAE,eAAe;AACjB,EAAE,YAAY;AACd,EAAE,kBAAkB;AACpB,EAAE,QAAQ;AACV,EAAE,YAAY;AACd,EAAE,SAAS;AACX,CAAC;AACD,MAAM,kBAAkB;AACxB,EAAE,SAAS,EAAE,WAAW;AACxB,EAAE,YAAY,EAAE,cAAc;AAC9B,EAAE,kBAAkB,EAAE,oBAAoB;AAC1C,EAAE,IAAI,EAAE,cAAc;AACtB,CAAC;AACD,MAAM,aAAa;AACnB,EAAE,KAAK,EAAE,YAAY;AACrB,EAAE,QAAQ,EAAE,MAAM;AAClB,EAAE,OAAO,EAAE,iBAAiB;AAC5B,CAAC;AACD,MAAM,uBAAA,GAA0B,WAAW;;AAE3C;AACA,MAAM,gBAAiB,GAAE,MAAM,CAAC,uBAAuB,CAAC;AACxD,MAAM,YAAa,GAAE,MAAM,CAAC,4BAA4B,CAAC;AACzD,MAAM,eAAgB,GAAE,MAAM,CAAC,8BAA8B,CAAC;AAC9D,MAAM,gBAAiB,GAAE,MAAM,CAAC,+BAA+B,CAAC;AAChE,MAAM,oBAAqB,GAAE,MAAM,CAAC,mCAAmC,CAAC;AACxE,MAAM,YAA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A,kBAAA,OAAA,GAAA,CAAA,IAAA;AACA,oBAAA,MAAA,IAAA;AACA,sBAAA,IAAA,CAAA,GAAA,EAAA;AACA,sBAAA,OAAA,MAAA;AACA,qBAAA;AACA,oBAAA,KAAA,IAAA;AACA,sBAAA,IAAA,CAAA,SAAA,CAAA;AACA,wBAAA,IAAA,EAAAI,kBAAA,CAAA,KAAA;AACA,wBAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,uBAAA,CAAA;AACA,sBAAA,IAAA,CAAA,eAAA,CAAA,KAAA,CAAA;AACA,sBAAA,IAAA,CAAA,GAAA,EAAA;AACA,sBAAA,OAAA,OAAA,CAAA,MAAA,CAAA,KAAA,CAAA;AACA,qBAAA;AACA,mBAAA;AACA;;AAEA,gBAAA,IAAA,CAAA,GAAA,EAAA;AACA,gBAAA,OAAA,GAAA;AACA,eAAA,CAAA,OAAA,KAAA,EAAA;AACA,gBAAA,IAAA,CAAA,SAAA,CAAA;AACA,kBAAA,IAAA,EAAAA,kBAAA,CAAA,KAAA;AACA,kBAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,iBAAA,CAAA;AACA,gBAAA,IAAA,CAAA,eAAA,CAAA,KAAA,CAAA;AACA,gBAAA,IAAA,CAAA,GAAA,EAAA;AACA,gBAAA,MAAA,KAAA;AACA;AACA,aAAA;AACA,YAAA,IAAA;AACA,WAAA;AACA,SAAA;AACA;AACA;AACA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../src/integrations/tracing/fastify/fastify-otel/index.js"],"sourcesContent":["/*\nVendored in and modified from @fastify/otel version 0.8.0\nhttps://github.com/fastify/otel/releases/tag/v0.8.0\n\nTried not to modify the original code too much keeping it as a JavaScript CJS module to make it easier to update when required\n\nModifications include:\n- Removed reading of package.json to get the version and package name\n\nMIT License\n\nCopyright (c) 2024 Fastify\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\n\n/* eslint-disable jsdoc/require-jsdoc */\n/* eslint-disable max-lines */\n/* eslint-disable no-param-reassign */\nimport dc from 'node:diagnostics_channel';\nimport { context, diag, propagation, SpanStatusCode, trace } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport {\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_ROUTE,\n ATTR_SERVICE_NAME,\n} from '@opentelemetry/semantic-conventions';\nimport * as minimatch from 'minimatch';\n\n// SENTRY VENDOR NOTE\n// Instead of using the package.json file, we hard code the package name and version here.\nconst PACKAGE_NAME = '@fastify/otel';\nconst PACKAGE_VERSION = '0.8.0';\n\n// Constants\nconst SUPPORTED_VERSIONS = '>=4.0.0 <6';\nconst FASTIFY_HOOKS = [\n 'onRequest',\n 'preParsing',\n 'preValidation',\n 'preHandler',\n 'preSerialization',\n 'onSend',\n 'onResponse',\n 'onError',\n];\nconst ATTRIBUTE_NAMES = {\n HOOK_NAME: 'hook.name',\n FASTIFY_TYPE: 'fastify.type',\n HOOK_CALLBACK_NAME: 'hook.callback.name',\n ROOT: 'fastify.root',\n};\nconst HOOK_TYPES = {\n ROUTE: 'route-hook',\n INSTANCE: 'hook',\n HANDLER: 'request-handler',\n};\nconst ANONYMOUS_FUNCTION_NAME = 'anonymous';\n\n// Symbols\nconst kInstrumentation = Symbol('fastify otel instance');\nconst kRequestSpan = Symbol('fastify otel request spans');\nconst kRequestContext = Symbol('fastify otel request context');\nconst kAddHookOriginal = Symbol('fastify otel addhook original');\nconst kSetNotFoundOriginal = Symbol('fastify otel setnotfound original');\nconst kIgnorePaths = Symbol('fastify otel ignore path');\n\nexport class FastifyOtelInstrumentation extends InstrumentationBase {\n constructor(config) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n this.servername = config?.servername ?? process.env.OTEL_SERVICE_NAME ?? 'fastify';\n this[kIgnorePaths] = null;\n this._logger = diag.createComponentLogger({ namespace: PACKAGE_NAME });\n\n if (config?.ignorePaths != null || process.env.OTEL_FASTIFY_IGNORE_PATHS != null) {\n const ignorePaths = config?.ignorePaths ?? process.env.OTEL_FASTIFY_IGNORE_PATHS;\n\n if ((typeof ignorePaths !== 'string' || ignorePaths.length === 0) && typeof ignorePaths !== 'function') {\n throw new TypeError('ignorePaths must be a string or a function');\n }\n\n const globMatcher = minimatch.minimatch;\n\n this[kIgnorePaths] = routeOptions => {\n if (typeof ignorePaths === 'function') {\n return ignorePaths(routeOptions);\n } else {\n return globMatcher(routeOptions.url, ignorePaths);\n }\n };\n }\n }\n\n enable() {\n if (this._handleInitialization === undefined && this.getConfig().registerOnInitialization) {\n const FastifyInstrumentationPlugin = this.plugin();\n this._handleInitialization = message => {\n message.fastify.register(FastifyInstrumentationPlugin);\n };\n dc.subscribe('fastify.initialization', this._handleInitialization);\n }\n return super.enable();\n }\n\n disable() {\n if (this._handleInitialization) {\n dc.unsubscribe('fastify.initialization', this._handleInitialization);\n this._handleInitialization = undefined;\n }\n return super.disable();\n }\n\n // We do not do patching in this instrumentation\n init() {\n return [];\n }\n\n plugin() {\n const instrumentation = this;\n\n FastifyInstrumentationPlugin[Symbol.for('skip-override')] = true;\n FastifyInstrumentationPlugin[Symbol.for('fastify.display-name')] = '@fastify/otel';\n FastifyInstrumentationPlugin[Symbol.for('plugin-meta')] = {\n fastify: SUPPORTED_VERSIONS,\n name: '@fastify/otel',\n };\n\n return FastifyInstrumentationPlugin;\n\n function FastifyInstrumentationPlugin(instance, opts, done) {\n instance.decorate(kInstrumentation, instrumentation);\n // addHook and notfoundHandler are essentially inherited from the prototype\n // what is important is to bound it to the right instance\n instance.decorate(kAddHookOriginal, instance.addHook);\n instance.decorate(kSetNotFoundOriginal, instance.setNotFoundHandler);\n instance.decorateRequest('opentelemetry', function openetelemetry() {\n const ctx = this[kRequestContext];\n const span = this[kRequestSpan];\n return {\n span,\n tracer: instrumentation.tracer,\n context: ctx,\n inject: (carrier, setter) => {\n return propagation.inject(ctx, carrier, setter);\n },\n extract: (carrier, getter) => {\n return propagation.extract(ctx, carrier, getter);\n },\n };\n });\n instance.decorateRequest(kRequestSpan, null);\n instance.decorateRequest(kRequestContext, null);\n\n instance.addHook('onRoute', function (routeOptions) {\n if (instrumentation[kIgnorePaths]?.(routeOptions) === true) {\n instrumentation._logger.debug(\n `Ignoring route instrumentation ${routeOptions.method} ${routeOptions.url} because it matches the ignore path`,\n );\n return;\n }\n\n for (const hook of FASTIFY_HOOKS) {\n if (routeOptions[hook] != null) {\n const handlerLike = routeOptions[hook];\n\n if (typeof handlerLike === 'function') {\n routeOptions[hook] = handlerWrapper(handlerLike, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route -> ${hook}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.ROUTE,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handlerLike.name?.length > 0 ? handlerLike.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n } else if (Array.isArray(handlerLike)) {\n const wrappedHandlers = [];\n\n for (const handler of handlerLike) {\n wrappedHandlers.push(\n handlerWrapper(handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route -> ${hook}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.ROUTE,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME,\n }),\n );\n }\n\n routeOptions[hook] = wrappedHandlers;\n }\n }\n }\n\n // We always want to add the onSend hook to the route to be executed last\n if (routeOptions.onSend != null) {\n routeOptions.onSend = Array.isArray(routeOptions.onSend)\n ? [...routeOptions.onSend, onSendHook]\n : [routeOptions.onSend, onSendHook];\n } else {\n routeOptions.onSend = onSendHook;\n }\n\n // We always want to add the onError hook to the route to be executed last\n if (routeOptions.onError != null) {\n routeOptions.onError = Array.isArray(routeOptions.onError)\n ? [...routeOptions.onError, onErrorHook]\n : [routeOptions.onError, onErrorHook];\n } else {\n routeOptions.onError = onErrorHook;\n }\n\n routeOptions.handler = handlerWrapper(routeOptions.handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - route-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.HANDLER,\n [ATTR_HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n routeOptions.handler.name.length > 0 ? routeOptions.handler.name : ANONYMOUS_FUNCTION_NAME,\n });\n });\n\n instance.addHook('onRequest', function (request, _reply, hookDone) {\n if (this[kInstrumentation].isEnabled() === false) {\n return hookDone();\n } else if (\n this[kInstrumentation][kIgnorePaths]?.({\n url: request.url,\n method: request.method,\n }) === true\n ) {\n this[kInstrumentation]._logger.debug(\n `Ignoring request ${request.method} ${request.url} because it matches the ignore path`,\n );\n return hookDone();\n }\n\n let ctx = context.active();\n\n if (trace.getSpan(ctx) == null) {\n ctx = propagation.extract(ctx, request.headers);\n }\n\n const rpcMetadata = getRPCMetadata(ctx);\n\n if (request.routeOptions.url != null && rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = request.routeOptions.url;\n }\n\n /** @type {import('@opentelemetry/api').Span} */\n const span = this[kInstrumentation].tracer.startSpan(\n 'request',\n {\n attributes: {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.ROOT]: '@fastify/otel',\n [ATTR_HTTP_ROUTE]: request.url,\n [ATTR_HTTP_REQUEST_METHOD]: request.method,\n },\n },\n ctx,\n );\n\n request[kRequestContext] = trace.setSpan(ctx, span);\n request[kRequestSpan] = span;\n\n context.with(request[kRequestContext], () => {\n hookDone();\n });\n });\n\n // onResponse is the last hook to be executed, only added for 404 handlers\n instance.addHook('onResponse', function (request, reply, hookDone) {\n const span = request[kRequestSpan];\n\n if (span != null) {\n span.setStatus({\n code: SpanStatusCode.OK,\n message: 'OK',\n });\n span.setAttributes({\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: 404,\n });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone();\n });\n\n instance.addHook = addHookPatched;\n instance.setNotFoundHandler = setNotFoundHandlerPatched;\n\n done();\n\n function onSendHook(request, reply, payload, hookDone) {\n /** @type {import('@opentelemetry/api').Span} */\n const span = request[kRequestSpan];\n\n if (span != null) {\n if (reply.statusCode < 500) {\n span.setStatus({\n code: SpanStatusCode.OK,\n message: 'OK',\n });\n }\n\n span.setAttributes({\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: reply.statusCode,\n });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone(null, payload);\n }\n\n function onErrorHook(request, reply, error, hookDone) {\n /** @type {Span} */\n const span = request[kRequestSpan];\n\n if (span != null) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n }\n\n hookDone();\n }\n\n function addHookPatched(name, hook) {\n const addHookOriginal = this[kAddHookOriginal];\n\n if (FASTIFY_HOOKS.includes(name)) {\n return addHookOriginal.call(\n this,\n name,\n handlerWrapper(hook, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - ${name}`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hook.name?.length > 0 ? hook.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n }),\n );\n } else {\n return addHookOriginal.call(this, name, hook);\n }\n }\n\n function setNotFoundHandlerPatched(hooks, handler) {\n const setNotFoundHandlerOriginal = this[kSetNotFoundOriginal];\n if (typeof hooks === 'function') {\n handler = handlerWrapper(hooks, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.name?.length > 0 ? hooks.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n setNotFoundHandlerOriginal.call(this, handler);\n } else {\n if (hooks.preValidation != null) {\n hooks.preValidation = handlerWrapper(hooks.preValidation, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler - preValidation`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.preValidation.name?.length > 0\n ? hooks.preValidation.name\n : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n }\n\n if (hooks.preHandler != null) {\n hooks.preHandler = handlerWrapper(hooks.preHandler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler - preHandler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n hooks.preHandler.name?.length > 0\n ? hooks.preHandler.name\n : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n }\n\n handler = handlerWrapper(handler, {\n [ATTR_SERVICE_NAME]: instance[kInstrumentation].servername,\n [ATTRIBUTE_NAMES.HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_NAMES.FASTIFY_TYPE]: HOOK_TYPES.INSTANCE,\n [ATTRIBUTE_NAMES.HOOK_CALLBACK_NAME]:\n handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME /* c8 ignore next */,\n });\n setNotFoundHandlerOriginal.call(this, hooks, handler);\n }\n }\n\n function handlerWrapper(handler, spanAttributes = {}) {\n return function handlerWrapped(...args) {\n /** @type {FastifyOtelInstrumentation} */\n const instrumentation = this[kInstrumentation];\n const [request] = args;\n\n if (instrumentation.isEnabled() === false) {\n return handler.call(this, ...args);\n }\n\n const ctx = request[kRequestContext] ?? context.active();\n const span = instrumentation.tracer.startSpan(\n `handler - ${\n handler.name?.length > 0\n ? handler.name\n : this.pluginName /* c8 ignore next */ ?? ANONYMOUS_FUNCTION_NAME /* c8 ignore next */\n }`,\n {\n attributes: spanAttributes,\n },\n ctx,\n );\n\n return context.with(\n trace.setSpan(ctx, span),\n function () {\n try {\n const res = handler.call(this, ...args);\n\n if (typeof res?.then === 'function') {\n return res.then(\n result => {\n span.end();\n return result;\n },\n error => {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n return Promise.reject(error);\n },\n );\n }\n\n span.end();\n return res;\n } catch (error) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.recordException(error);\n span.end();\n throw error;\n }\n },\n this,\n );\n };\n }\n }\n }\n}\n"],"names":["InstrumentationBase","diag","dc","propagation","ATTR_SERVICE_NAME","ATTR_HTTP_ROUTE","context","trace","getRPCMetadata","RPCType","ATTR_HTTP_REQUEST_METHOD","SpanStatusCode","ATTR_HTTP_RESPONSE_STATUS_CODE"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAiBA;AACA;AACA,MAAM,YAAA,GAAe,eAAe;AACpC,MAAM,eAAA,GAAkB,OAAO;;AAE/B;AACA,MAAM,kBAAA,GAAqB,YAAY;AACvC,MAAM,gBAAgB;AACtB,EAAE,WAAW;AACb,EAAE,YAAY;AACd,EAAE,eAAe;AACjB,EAAE,YAAY;AACd,EAAE,kBAAkB;AACpB,EAAE,QAAQ;AACV,EAAE,YAAY;AACd,EAAE,SAAS;AACX,CAAC;AACD,MAAM,kBAAkB;AACxB,EAAE,SAAS,EAAE,WAAW;AACxB,EAAE,YAAY,EAAE,cAAc;AAC9B,EAAE,kBAAkB,EAAE,oBAAoB;AAC1C,EAAE,IAAI,EAAE,cAAc;AACtB,CAAC;AACD,MAAM,aAAa;AACnB,EAAE,KAAK,EAAE,YAAY;AACrB,EAAE,QAAQ,EAAE,MAAM;AAClB,EAAE,OAAO,EAAE,iBAAiB;AAC5B,CAAC;AACD,MAAM,uBAAA,GAA0B,WAAW;;AAE3C;AACA,MAAM,gBAAiB,GAAE,MAAM,CAAC,uBAAuB,CAAC;AACxD,MAAM,YAAa,GAAE,MAAM,CAAC,4BAA4B,CAAC;AACzD,MAAM,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AAA,IAAA;AACA,gBAAA,MAAA,GAAA,GAAA,OAAA,CAAA,IAAA,CAAA,IAAA,EAAA,GAAA,IAAA,CAAA;;AAEA,gBAAA,IAAA,OAAA,GAAA,EAAA,IAAA,KAAA,UAAA,EAAA;AACA,kBAAA,OAAA,GAAA,CAAA,IAAA;AACA,oBAAA,MAAA,IAAA;AACA,sBAAA,IAAA,CAAA,GAAA,EAAA;AACA,sBAAA,OAAA,MAAA;AACA,qBAAA;AACA,oBAAA,KAAA,IAAA;AACA,sBAAA,IAAA,CAAA,SAAA,CAAA;AACA,wBAAA,IAAA,EAAAI,kBAAA,CAAA,KAAA;AACA,wBAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,uBAAA,CAAA;AACA,sBAAA,IAAA,CAAA,eAAA,CAAA,KAAA,CAAA;AACA,sBAAA,IAAA,CAAA,GAAA,EAAA;AACA,sBAAA,OAAA,OAAA,CAAA,MAAA,CAAA,KAAA,CAAA;AACA,qBAAA;AACA,mBAAA;AACA;;AAEA,gBAAA,IAAA,CAAA,GAAA,EAAA;AACA,gBAAA,OAAA,GAAA;AACA,eAAA,CAAA,OAAA,KAAA,EAAA;AACA,gBAAA,IAAA,CAAA,SAAA,CAAA;AACA,kBAAA,IAAA,EAAAA,kBAAA,CAAA,KAAA;AACA,kBAAA,OAAA,EAAA,KAAA,CAAA,OAAA;AACA,iBAAA,CAAA;AACA,gBAAA,IAAA,CAAA,eAAA,CAAA,KAAA,CAAA;AACA,gBAAA,IAAA,CAAA,GAAA,EAAA;AACA,gBAAA,MAAA,KAAA;AACA;AACA,aAAA;AACA,YAAA,IAAA;AACA,WAAA;AACA,SAAA;AACA;AACA;AACA;AACA;;;;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const dc = require('node:diagnostics_channel');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
|
+
const nodeCore = require('@sentry/node-core');
|
|
5
6
|
const debugBuild = require('../../../debug-build.js');
|
|
6
|
-
const instrument = require('../../../otel/instrument.js');
|
|
7
7
|
const index = require('./fastify-otel/index.js');
|
|
8
8
|
const instrumentation = require('./v3/instrumentation.js');
|
|
9
9
|
|
|
10
10
|
const INTEGRATION_NAME = 'Fastify';
|
|
11
11
|
const INTEGRATION_NAME_V3 = 'Fastify-V3';
|
|
12
12
|
|
|
13
|
-
const instrumentFastifyV3 =
|
|
13
|
+
const instrumentFastifyV3 = nodeCore.generateInstrumentOnce(INTEGRATION_NAME_V3, () => new instrumentation.FastifyInstrumentationV3());
|
|
14
14
|
|
|
15
15
|
function handleFastifyError(
|
|
16
16
|
|
|
@@ -41,14 +41,14 @@ function handleFastifyError(
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const instrumentFastify =
|
|
44
|
+
const instrumentFastify = nodeCore.generateInstrumentOnce(INTEGRATION_NAME, () => {
|
|
45
45
|
const fastifyOtelInstrumentationInstance = new index.FastifyOtelInstrumentation();
|
|
46
46
|
const plugin = fastifyOtelInstrumentationInstance.plugin();
|
|
47
47
|
const options = fastifyOtelInstrumentationInstance.getConfig();
|
|
48
48
|
const shouldHandleError = (options )?.shouldHandleError || defaultShouldHandleError;
|
|
49
49
|
|
|
50
50
|
// This message handler works for Fastify versions 3, 4 and 5
|
|
51
|
-
|
|
51
|
+
dc.subscribe('fastify.initialization', message => {
|
|
52
52
|
const fastifyInstance = (message ).fastify;
|
|
53
53
|
|
|
54
54
|
fastifyInstance?.register(plugin).after(err => {
|
|
@@ -66,7 +66,7 @@ const instrumentFastify = instrument.generateInstrumentOnce(INTEGRATION_NAME, ()
|
|
|
66
66
|
|
|
67
67
|
// This diagnostics channel only works on Fastify version 5
|
|
68
68
|
// For versions 3 and 4, we use `setupFastifyErrorHandler` instead
|
|
69
|
-
|
|
69
|
+
dc.subscribe('tracing:fastify.request.handler:error', message => {
|
|
70
70
|
const { error, request, reply } = message
|
|
71
71
|
|
|
72
72
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getClient,\n getIsolationScope,\n logger,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { generateInstrumentOnce } from '../../../otel/instrument';\nimport { FastifyOtelInstrumentation } from './fastify-otel/index';\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from './types';\nimport { FastifyInstrumentationV3 } from './v3/instrumentation';\n\ninterface FastifyHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n *\n * @example\n *\n * ```javascript\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 400;\n * },\n * });\n * ```\n *\n * If using TypeScript, you can cast the request and reply to get full type safety.\n *\n * ```typescript\n * import type { FastifyRequest, FastifyReply } from 'fastify';\n *\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(error, minimalRequest, minimalReply) {\n * const request = minimalRequest as FastifyRequest;\n * const reply = minimalReply as FastifyReply;\n * return reply.statusCode >= 500;\n * },\n * });\n * ```\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\nconst INTEGRATION_NAME = 'Fastify';\nconst INTEGRATION_NAME_V3 = 'Fastify-V3';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());\n\nfunction handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } },\n reply: FastifyReply,\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered\n if (handlerOrigin === 'diagnostics-channel') {\n this.diagnosticsChannelExists = true;\n }\n\n if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {\n DEBUG_BUILD &&\n logger.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call.',\n );\n\n // If the diagnostics channel already exists, we don't need to handle the error again\n return;\n }\n\n if (shouldHandleError(error, request, reply)) {\n captureException(error);\n }\n}\n\nexport const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => {\n const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();\n const plugin = fastifyOtelInstrumentationInstance.plugin();\n const options = fastifyOtelInstrumentationInstance.getConfig();\n const shouldHandleError = (options as FastifyHandlerOptions)?.shouldHandleError || defaultShouldHandleError;\n\n // This message handler works for Fastify versions 3, 4 and 5\n diagnosticsChannel.subscribe('fastify.initialization', message => {\n const fastifyInstance = (message as { fastify?: FastifyInstance }).fastify;\n\n fastifyInstance?.register(plugin).after(err => {\n if (err) {\n DEBUG_BUILD && logger.error('Failed to setup Fastify instrumentation', err);\n } else {\n instrumentClient();\n\n if (fastifyInstance) {\n instrumentOnRequest(fastifyInstance);\n }\n }\n });\n });\n\n // This diagnostics channel only works on Fastify version 5\n // For versions 3 and 4, we use `setupFastifyErrorHandler` instead\n diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {\n const { error, request, reply } = message as {\n error: Error;\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } };\n reply: FastifyReply;\n };\n\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'diagnostics-channel');\n });\n\n // Returning this as unknown not to deal with the internal types of the FastifyOtelInstrumentation\n return fastifyOtelInstrumentationInstance as Instrumentation<InstrumentationConfig & FastifyHandlerOptions>;\n});\n\nconst _fastifyIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentFastifyV3();\n instrumentFastify();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).\n *\n * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.\n *\n * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.fastifyIntegration()],\n * })\n * ```\n */\nexport const fastifyIntegration = defineIntegration(_fastifyIntegration);\n\n/**\n * Default function to determine if an error should be sent to Sentry\n *\n * 3xx and 4xx errors are not sent by default.\n */\nfunction defaultShouldHandleError(_error: Error, _request: FastifyRequest, reply: FastifyReply): boolean {\n const statusCode = reply.statusCode;\n // 3xx and 4xx errors are not sent by default.\n return statusCode >= 500 || statusCode <= 299;\n}\n\n/**\n * Add an Fastify error handler to capture errors to Sentry.\n *\n * @param fastify The Fastify instance to which to add the error handler\n * @param options Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const Fastify = require(\"fastify\");\n *\n * const app = Fastify();\n *\n * Sentry.setupFastifyErrorHandler(app);\n *\n * // Add your routes, etc.\n *\n * app.listen({ port: 3000 });\n * ```\n */\nexport function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void {\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n const plugin = Object.assign(\n function (fastify: FastifyInstance, _options: unknown, done: () => void): void {\n fastify.addHook('onError', async (request, reply, error) => {\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'onError-hook');\n });\n done();\n },\n {\n [Symbol.for('skip-override')]: true,\n [Symbol.for('fastify.display-name')]: 'sentry-fastify-error-handler',\n },\n );\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fastify.register(plugin);\n}\n\nfunction addFastifySpanAttributes(span: Span): void {\n const spanJSON = spanToJSON(span);\n const spanName = spanJSON.description;\n const attributes = spanJSON.data;\n\n const type = attributes['fastify.type'];\n\n const isHook = type === 'hook';\n const isHandler = type === spanName?.startsWith('handler -');\n // In @fastify/otel `request-handler` is separated by dash, not underscore\n const isRequestHandler = spanName === 'request' || type === 'request-handler';\n\n // If this is already set, or we have no fastify span, no need to process again...\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || (!isHandler && !isRequestHandler && !isHook)) {\n return;\n }\n\n const opPrefix = isHook ? 'hook' : isHandler ? 'middleware' : isRequestHandler ? 'request-handler' : '<unknown>';\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${opPrefix}.fastify`,\n });\n\n const attrName = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];\n if (typeof attrName === 'string') {\n // Try removing `fastify -> ` and `@fastify/otel -> ` prefixes\n // This is a bit of a hack, and not always working for all spans\n // But it's the best we can do without a proper API\n const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\\/otel -> /, '');\n\n span.updateName(updatedName);\n }\n}\n\nfunction instrumentClient(): void {\n const client = getClient();\n if (client) {\n client.on('spanStart', (span: Span) => {\n addFastifySpanAttributes(span);\n });\n }\n}\n\nfunction instrumentOnRequest(fastify: FastifyInstance): void {\n fastify.addHook('onRequest', async (request: FastifyRequest & { opentelemetry?: () => { span?: Span } }, _reply) => {\n if (request.opentelemetry) {\n const { span } = request.opentelemetry();\n\n if (span) {\n addFastifySpanAttributes(span);\n }\n }\n\n const routeName = request.routeOptions?.url;\n const method = request.method || 'GET';\n\n getIsolationScope().setTransactionName(`${method} ${routeName}`);\n });\n}\n"],"names":["generateInstrumentOnce","FastifyInstrumentationV3","DEBUG_BUILD","logger","captureException","FastifyOtelInstrumentation","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getClient","getIsolationScope"],"mappings":";;;;;;;;;AAsDA,MAAM,gBAAA,GAAmB,SAAS;AAClC,MAAM,mBAAA,GAAsB,YAAY;;AAE3B,MAAA,mBAAA,GAAsBA,iCAAsB,CAAC,mBAAmB,EAAE,MAAM,IAAIC,wCAAwB,EAAE;;AAEnH,SAAS,kBAAkB;;AAI3B,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,KAAK;AACP,EAAE,iBAAiB;AACnB,EAAE,aAAa;AACf,EAAQ;AACR;AACA,EAAE,IAAI,aAAc,KAAI,qBAAqB,EAAE;AAC/C,IAAI,IAAI,CAAC,wBAAyB,GAAE,IAAI;AACxC;;AAEA,EAAE,IAAI,IAAI,CAAC,4BAA4B,aAAA,KAAkB,cAAc,EAAE;AACzE,IAAIC,sBAAY;AAChB,MAAMC,WAAM,CAAC,IAAI;AACjB,QAAQ,uEAAuE;AAC/E,QAAQ,wDAAwD;AAChE,OAAO;;AAEP;AACA,IAAI;AACJ;;AAEA,EAAE,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE;AAChD,IAAIC,qBAAgB,CAAC,KAAK,CAAC;AAC3B;AACA;;AAEO,MAAM,oBAAoBJ,iCAAsB,CAAC,gBAAgB,EAAE,MAAM;AAChF,EAAE,MAAM,kCAAmC,GAAE,IAAIK,gCAA0B,EAAE;AAC7E,EAAE,MAAM,MAAO,GAAE,kCAAkC,CAAC,MAAM,EAAE;AAC5D,EAAE,MAAM,OAAQ,GAAE,kCAAkC,CAAC,SAAS,EAAE;AAChE,EAAE,MAAM,oBAAoB,CAAC,WAAmC,iBAAkB,IAAG,wBAAwB;;AAE7G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,KAAA;AACA,IAAA,IAAA,OAAA,CAAA,aAAA,EAAA;AACA,MAAA,MAAA,EAAA,IAAA,EAAA,GAAA,OAAA,CAAA,aAAA,EAAA;;AAEA,MAAA,IAAA,IAAA,EAAA;AACA,QAAA,wBAAA,CAAA,IAAA,CAAA;AACA;AACA;;AAEA,IAAA,MAAA,SAAA,GAAA,OAAA,CAAA,YAAA,EAAA,GAAA;AACA,IAAA,MAAA,MAAA,GAAA,OAAA,CAAA,MAAA,IAAA,KAAA;;AAEA,IAAAC,sBAAA,EAAA,CAAA,kBAAA,CAAA,CAAA,EAAA,MAAA,CAAA,CAAA,EAAA,SAAA,CAAA,CAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getClient,\n getIsolationScope,\n logger,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { FastifyOtelInstrumentation } from './fastify-otel/index';\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from './types';\nimport { FastifyInstrumentationV3 } from './v3/instrumentation';\n\ninterface FastifyHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n *\n * @example\n *\n * ```javascript\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 400;\n * },\n * });\n * ```\n *\n * If using TypeScript, you can cast the request and reply to get full type safety.\n *\n * ```typescript\n * import type { FastifyRequest, FastifyReply } from 'fastify';\n *\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(error, minimalRequest, minimalReply) {\n * const request = minimalRequest as FastifyRequest;\n * const reply = minimalReply as FastifyReply;\n * return reply.statusCode >= 500;\n * },\n * });\n * ```\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\nconst INTEGRATION_NAME = 'Fastify';\nconst INTEGRATION_NAME_V3 = 'Fastify-V3';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());\n\nfunction handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } },\n reply: FastifyReply,\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered\n if (handlerOrigin === 'diagnostics-channel') {\n this.diagnosticsChannelExists = true;\n }\n\n if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {\n DEBUG_BUILD &&\n logger.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call.',\n );\n\n // If the diagnostics channel already exists, we don't need to handle the error again\n return;\n }\n\n if (shouldHandleError(error, request, reply)) {\n captureException(error);\n }\n}\n\nexport const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => {\n const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();\n const plugin = fastifyOtelInstrumentationInstance.plugin();\n const options = fastifyOtelInstrumentationInstance.getConfig();\n const shouldHandleError = (options as FastifyHandlerOptions)?.shouldHandleError || defaultShouldHandleError;\n\n // This message handler works for Fastify versions 3, 4 and 5\n diagnosticsChannel.subscribe('fastify.initialization', message => {\n const fastifyInstance = (message as { fastify?: FastifyInstance }).fastify;\n\n fastifyInstance?.register(plugin).after(err => {\n if (err) {\n DEBUG_BUILD && logger.error('Failed to setup Fastify instrumentation', err);\n } else {\n instrumentClient();\n\n if (fastifyInstance) {\n instrumentOnRequest(fastifyInstance);\n }\n }\n });\n });\n\n // This diagnostics channel only works on Fastify version 5\n // For versions 3 and 4, we use `setupFastifyErrorHandler` instead\n diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {\n const { error, request, reply } = message as {\n error: Error;\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } };\n reply: FastifyReply;\n };\n\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'diagnostics-channel');\n });\n\n // Returning this as unknown not to deal with the internal types of the FastifyOtelInstrumentation\n return fastifyOtelInstrumentationInstance as Instrumentation<InstrumentationConfig & FastifyHandlerOptions>;\n});\n\nconst _fastifyIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentFastifyV3();\n instrumentFastify();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).\n *\n * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.\n *\n * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.fastifyIntegration()],\n * })\n * ```\n */\nexport const fastifyIntegration = defineIntegration(_fastifyIntegration);\n\n/**\n * Default function to determine if an error should be sent to Sentry\n *\n * 3xx and 4xx errors are not sent by default.\n */\nfunction defaultShouldHandleError(_error: Error, _request: FastifyRequest, reply: FastifyReply): boolean {\n const statusCode = reply.statusCode;\n // 3xx and 4xx errors are not sent by default.\n return statusCode >= 500 || statusCode <= 299;\n}\n\n/**\n * Add an Fastify error handler to capture errors to Sentry.\n *\n * @param fastify The Fastify instance to which to add the error handler\n * @param options Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const Fastify = require(\"fastify\");\n *\n * const app = Fastify();\n *\n * Sentry.setupFastifyErrorHandler(app);\n *\n * // Add your routes, etc.\n *\n * app.listen({ port: 3000 });\n * ```\n */\nexport function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void {\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n const plugin = Object.assign(\n function (fastify: FastifyInstance, _options: unknown, done: () => void): void {\n fastify.addHook('onError', async (request, reply, error) => {\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'onError-hook');\n });\n done();\n },\n {\n [Symbol.for('skip-override')]: true,\n [Symbol.for('fastify.display-name')]: 'sentry-fastify-error-handler',\n },\n );\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fastify.register(plugin);\n}\n\nfunction addFastifySpanAttributes(span: Span): void {\n const spanJSON = spanToJSON(span);\n const spanName = spanJSON.description;\n const attributes = spanJSON.data;\n\n const type = attributes['fastify.type'];\n\n const isHook = type === 'hook';\n const isHandler = type === spanName?.startsWith('handler -');\n // In @fastify/otel `request-handler` is separated by dash, not underscore\n const isRequestHandler = spanName === 'request' || type === 'request-handler';\n\n // If this is already set, or we have no fastify span, no need to process again...\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || (!isHandler && !isRequestHandler && !isHook)) {\n return;\n }\n\n const opPrefix = isHook ? 'hook' : isHandler ? 'middleware' : isRequestHandler ? 'request-handler' : '<unknown>';\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${opPrefix}.fastify`,\n });\n\n const attrName = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];\n if (typeof attrName === 'string') {\n // Try removing `fastify -> ` and `@fastify/otel -> ` prefixes\n // This is a bit of a hack, and not always working for all spans\n // But it's the best we can do without a proper API\n const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\\/otel -> /, '');\n\n span.updateName(updatedName);\n }\n}\n\nfunction instrumentClient(): void {\n const client = getClient();\n if (client) {\n client.on('spanStart', (span: Span) => {\n addFastifySpanAttributes(span);\n });\n }\n}\n\nfunction instrumentOnRequest(fastify: FastifyInstance): void {\n fastify.addHook('onRequest', async (request: FastifyRequest & { opentelemetry?: () => { span?: Span } }, _reply) => {\n if (request.opentelemetry) {\n const { span } = request.opentelemetry();\n\n if (span) {\n addFastifySpanAttributes(span);\n }\n }\n\n const routeName = request.routeOptions?.url;\n const method = request.method || 'GET';\n\n getIsolationScope().setTransactionName(`${method} ${routeName}`);\n });\n}\n"],"names":["generateInstrumentOnce","FastifyInstrumentationV3","DEBUG_BUILD","logger","captureException","FastifyOtelInstrumentation","diagnosticsChannel","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getClient","getIsolationScope"],"mappings":";;;;;;;;;AAsDA,MAAM,gBAAA,GAAmB,SAAS;AAClC,MAAM,mBAAA,GAAsB,YAAY;;AAE3B,MAAA,mBAAA,GAAsBA,+BAAsB,CAAC,mBAAmB,EAAE,MAAM,IAAIC,wCAAwB,EAAE;;AAEnH,SAAS,kBAAkB;;AAI3B,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,KAAK;AACP,EAAE,iBAAiB;AACnB,EAAE,aAAa;AACf,EAAQ;AACR;AACA,EAAE,IAAI,aAAc,KAAI,qBAAqB,EAAE;AAC/C,IAAI,IAAI,CAAC,wBAAyB,GAAE,IAAI;AACxC;;AAEA,EAAE,IAAI,IAAI,CAAC,4BAA4B,aAAA,KAAkB,cAAc,EAAE;AACzE,IAAIC,sBAAY;AAChB,MAAMC,WAAM,CAAC,IAAI;AACjB,QAAQ,uEAAuE;AAC/E,QAAQ,wDAAwD;AAChE,OAAO;;AAEP;AACA,IAAI;AACJ;;AAEA,EAAE,IAAI,i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AA,EAAA,CAAA;;AAEA,IAAA,IAAA,CAAA,UAAA,CAAA,WAAA,CAAA;AACA;AACA;;AAEA,SAAA,gBAAA,GAAA;AACA,EAAA,MAAA,MAAA,GAAAE,cAAA,EAAA;AACA,EAAA,IAAA,MAAA,EAAA;AACA,IAAA,MAAA,CAAA,EAAA,CAAA,WAAA,EAAA,CAAA,IAAA,KAAA;AACA,MAAA,wBAAA,CAAA,IAAA,CAAA;AACA,KAAA,CAAA;AACA;AACA;;AAEA,SAAA,mBAAA,CAAA,OAAA,EAAA;AACA,EAAA,OAAA,CAAA,OAAA,CAAA,WAAA,EAAA,OAAA,OAAA,EAAA,MAAA,KAAA;AACA,IAAA,IAAA,OAAA,CAAA,aAAA,EAAA;AACA,MAAA,MAAA,EAAA,IAAA,EAAA,GAAA,OAAA,CAAA,aAAA,EAAA;;AAEA,MAAA,IAAA,IAAA,EAAA;AACA,QAAA,wBAAA,CAAA,IAAA,CAAA;AACA;AACA;;AAEA,IAAA,MAAA,SAAA,GAAA,OAAA,CAAA,YAAA,EAAA,GAAA;AACA,IAAA,MAAA,MAAA,GAAA,OAAA,CAAA,MAAA,IAAA,KAAA;;AAEA,IAAAC,sBAAA,EAAA,CAAA,kBAAA,CAAA,CAAA,EAAA,MAAA,CAAA,CAAA,EAAA,SAAA,CAAA,CAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
|
@@ -2,11 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const instrumentationGenericPool = require('@opentelemetry/instrumentation-generic-pool');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
|
-
const
|
|
5
|
+
const nodeCore = require('@sentry/node-core');
|
|
6
6
|
|
|
7
7
|
const INTEGRATION_NAME = 'GenericPool';
|
|
8
8
|
|
|
9
|
-
const instrumentGenericPool =
|
|
9
|
+
const instrumentGenericPool = nodeCore.generateInstrumentOnce(INTEGRATION_NAME, () => new instrumentationGenericPool.GenericPoolInstrumentation({}));
|
|
10
10
|
|
|
11
11
|
const _genericPoolIntegration = (() => {
|
|
12
12
|
let instrumentationWrappedCallback;
|
|
@@ -15,7 +15,7 @@ const _genericPoolIntegration = (() => {
|
|
|
15
15
|
name: INTEGRATION_NAME,
|
|
16
16
|
setupOnce() {
|
|
17
17
|
const instrumentation = instrumentGenericPool();
|
|
18
|
-
instrumentationWrappedCallback =
|
|
18
|
+
instrumentationWrappedCallback = nodeCore.instrumentWhenWrapped(instrumentation);
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
setup(client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genericPool.js","sources":["../../../../src/integrations/tracing/genericPool.ts"],"sourcesContent":["import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce, instrumentWhenWrapped } from '
|
|
1
|
+
{"version":3,"file":"genericPool.js","sources":["../../../../src/integrations/tracing/genericPool.ts"],"sourcesContent":["import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce, instrumentWhenWrapped } from '@sentry/node-core';\n\nconst INTEGRATION_NAME = 'GenericPool';\n\nexport const instrumentGenericPool = generateInstrumentOnce(INTEGRATION_NAME, () => new GenericPoolInstrumentation({}));\n\nconst _genericPoolIntegration = (() => {\n let instrumentationWrappedCallback: undefined | ((callback: () => void) => void);\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n const instrumentation = instrumentGenericPool();\n instrumentationWrappedCallback = instrumentWhenWrapped(instrumentation);\n },\n\n setup(client) {\n instrumentationWrappedCallback?.(() =>\n client.on('spanStart', span => {\n const spanJSON = spanToJSON(span);\n\n const spanDescription = spanJSON.description;\n\n // typo in emitted span for version <= 0.38.0 of @opentelemetry/instrumentation-generic-pool\n const isGenericPoolSpan =\n spanDescription === 'generic-pool.aquire' || spanDescription === 'generic-pool.acquire';\n\n if (isGenericPoolSpan) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.generic_pool');\n }\n }),\n );\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [generic-pool](https://www.npmjs.com/package/generic-pool) library.\n *\n * For more information, see the [`genericPoolIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/genericpool/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.genericPoolIntegration()],\n * });\n * ```\n */\nexport const genericPoolIntegration = defineIntegration(_genericPoolIntegration);\n"],"names":["generateInstrumentOnce","GenericPoolInstrumentation","instrumentWhenWrapped","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,aAAa;;MAEzB,qBAAsB,GAAEA,+BAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,qDAA0B,CAAC,EAAE,CAAC;;AAEtH,MAAM,uBAAwB,IAAG,MAAM;AACvC,EAAE,IAAI,8BAA8B;;AAEpC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,MAAM,eAAA,GAAkB,qBAAqB,EAAE;AACrD,MAAM,8BAA+B,GAAEC,8BAAqB,CAAC,eAAe,CAAC;AAC7E,KAAK;;AAEL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,8BAA8B,GAAG;AACvC,QAAQ,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACvC,UAAU,MAAM,QAAS,GAAEC,eAAU,CAAC,IAAI,CAAC;;AAE3C,UAAU,MAAM,eAAA,GAAkB,QAAQ,CAAC,WAAW;;AAEtD;AACA,UAAU,MAAM,iBAAkB;AAClC,YAAY,oBAAoB,qBAAA,IAAyB,eAAA,KAAoB,sBAAsB;;AAEnG,UAAU,IAAI,iBAAiB,EAAE;AACjC,YAAY,IAAI,CAAC,YAAY,CAACC,qCAAgC,EAAE,2BAA2B,CAAC;AAC5F;AACA,SAAS,CAAC;AACV,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,sBAAuB,GAAEC,sBAAiB,CAAC,uBAAuB;;;;;"}
|
|
@@ -3,13 +3,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const api = require('@opentelemetry/api');
|
|
4
4
|
const instrumentationGraphql = require('@opentelemetry/instrumentation-graphql');
|
|
5
5
|
const core = require('@sentry/core');
|
|
6
|
+
const nodeCore = require('@sentry/node-core');
|
|
6
7
|
const opentelemetry = require('@sentry/opentelemetry');
|
|
7
|
-
const instrument = require('../../otel/instrument.js');
|
|
8
|
-
const addOriginToSpan = require('../../utils/addOriginToSpan.js');
|
|
9
8
|
|
|
10
9
|
const INTEGRATION_NAME = 'Graphql';
|
|
11
10
|
|
|
12
|
-
const instrumentGraphql =
|
|
11
|
+
const instrumentGraphql = nodeCore.generateInstrumentOnce(
|
|
13
12
|
INTEGRATION_NAME,
|
|
14
13
|
instrumentationGraphql.GraphQLInstrumentation,
|
|
15
14
|
(_options) => {
|
|
@@ -18,7 +17,7 @@ const instrumentGraphql = instrument.generateInstrumentOnce(
|
|
|
18
17
|
return {
|
|
19
18
|
...options,
|
|
20
19
|
responseHook(span, result) {
|
|
21
|
-
|
|
20
|
+
nodeCore.addOriginToSpan(span, 'auto.graphql.otel.graphql');
|
|
22
21
|
|
|
23
22
|
// We want to ensure spans are marked as errored if there are errors in the result
|
|
24
23
|
// We only do that if the span is not already marked with a status
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sources":["../../../../src/integrations/tracing/graphql.ts"],"sourcesContent":["import type { AttributeValue } from '@opentelemetry/api';\nimport { SpanStatusCode } from '@opentelemetry/api';\nimport { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getRootSpan, spanToJSON } from '@sentry/core';\nimport {
|
|
1
|
+
{"version":3,"file":"graphql.js","sources":["../../../../src/integrations/tracing/graphql.ts"],"sourcesContent":["import type { AttributeValue } from '@opentelemetry/api';\nimport { SpanStatusCode } from '@opentelemetry/api';\nimport { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getRootSpan, spanToJSON } from '@sentry/core';\nimport { addOriginToSpan, generateInstrumentOnce } from '@sentry/node-core';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION } from '@sentry/opentelemetry';\n\ninterface GraphqlOptions {\n /**\n * Do not create spans for resolvers.\n *\n * Defaults to true.\n */\n ignoreResolveSpans?: boolean;\n\n /**\n * Don't create spans for the execution of the default resolver on object properties.\n *\n * When a resolver function is not defined on the schema for a field, graphql will\n * use the default resolver which just looks for a property with that name on the object.\n * If the property is not a function, it's not very interesting to trace.\n * This option can reduce noise and number of spans created.\n *\n * Defaults to true.\n */\n ignoreTrivialResolveSpans?: boolean;\n\n /**\n * If this is enabled, a http.server root span containing this span will automatically be renamed to include the operation name.\n * Set this to `false` if you do not want this behavior, and want to keep the default http.server span name.\n *\n * Defaults to true.\n */\n useOperationNameForRootSpan?: boolean;\n}\n\nconst INTEGRATION_NAME = 'Graphql';\n\nexport const instrumentGraphql = generateInstrumentOnce(\n INTEGRATION_NAME,\n GraphQLInstrumentation,\n (_options: GraphqlOptions) => {\n const options = getOptionsWithDefaults(_options);\n\n return {\n ...options,\n responseHook(span, result) {\n addOriginToSpan(span, 'auto.graphql.otel.graphql');\n\n // We want to ensure spans are marked as errored if there are errors in the result\n // We only do that if the span is not already marked with a status\n const resultWithMaybeError = result as { errors?: { message: string }[] };\n if (resultWithMaybeError.errors?.length && !spanToJSON(span).status) {\n span.setStatus({ code: SpanStatusCode.ERROR });\n }\n\n const attributes = spanToJSON(span).data;\n\n // If operation.name is not set, we fall back to use operation.type only\n const operationType = attributes['graphql.operation.type'];\n const operationName = attributes['graphql.operation.name'];\n\n if (options.useOperationNameForRootSpan && operationType) {\n const rootSpan = getRootSpan(span);\n const rootSpanAttributes = spanToJSON(rootSpan).data;\n\n const existingOperations = rootSpanAttributes[SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION] || [];\n\n const newOperation = operationName ? `${operationType} ${operationName}` : `${operationType}`;\n\n // We keep track of each operation on the root span\n // This can either be a string, or an array of strings (if there are multiple operations)\n if (Array.isArray(existingOperations)) {\n (existingOperations as string[]).push(newOperation);\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, existingOperations);\n } else if (typeof existingOperations === 'string') {\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, [existingOperations, newOperation]);\n } else {\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, newOperation);\n }\n\n if (!spanToJSON(rootSpan).data['original-description']) {\n rootSpan.setAttribute('original-description', spanToJSON(rootSpan).description);\n }\n // Important for e.g. @sentry/aws-serverless because this would otherwise overwrite the name again\n rootSpan.updateName(\n `${spanToJSON(rootSpan).data['original-description']} (${getGraphqlOperationNamesFromAttribute(\n existingOperations,\n )})`,\n );\n }\n },\n };\n },\n);\n\nconst _graphqlIntegration = ((options: GraphqlOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // We set defaults here, too, because otherwise we'd update the instrumentation config\n // to the config without defaults, as `generateInstrumentOnce` automatically calls `setConfig(options)`\n // when being called the second time\n instrumentGraphql(getOptionsWithDefaults(options));\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [graphql](https://www.npmjs.com/package/graphql) library.\n *\n * For more information, see the [`graphqlIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/graphql/).\n *\n * @param {GraphqlOptions} options Configuration options for the GraphQL integration.\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.graphqlIntegration()],\n * });\n */\nexport const graphqlIntegration = defineIntegration(_graphqlIntegration);\n\nfunction getOptionsWithDefaults(options?: GraphqlOptions): GraphqlOptions {\n return {\n ignoreResolveSpans: true,\n ignoreTrivialResolveSpans: true,\n useOperationNameForRootSpan: true,\n ...options,\n };\n}\n\n// copy from packages/opentelemetry/utils\nfunction getGraphqlOperationNamesFromAttribute(attr: AttributeValue): string {\n if (Array.isArray(attr)) {\n const sorted = attr.slice().sort();\n\n // Up to 5 items, we just add all of them\n if (sorted.length <= 5) {\n return sorted.join(', ');\n } else {\n // Else, we add the first 5 and the diff of other operations\n return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;\n }\n }\n\n return `${attr}`;\n}\n"],"names":["generateInstrumentOnce","GraphQLInstrumentation","addOriginToSpan","spanToJSON","SpanStatusCode","getRootSpan","SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION","defineIntegration"],"mappings":";;;;;;;;AAqCA,MAAM,gBAAA,GAAmB,SAAS;;AAE3B,MAAM,iBAAkB,GAAEA,+BAAsB;AACvD,EAAE,gBAAgB;AAClB,EAAEC,6CAAsB;AACxB,EAAE,CAAC,QAAQ,KAAqB;AAChC,IAAI,MAAM,OAAQ,GAAE,sBAAsB,CAAC,QAAQ,CAAC;;AAEpD,IAAI,OAAO;AACX,MAAM,GAAG,OAAO;AAChB,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE;AACj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IAAA,CAAA,EAAA;AACA,MAAA,OAAA,MAAA,CAAA,IAAA,CAAA,IAAA,CAAA;AACA,KAAA,MAAA;AACA;AACA,MAAA,OAAA,CAAA,EAAA,MAAA,CAAA,KAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,CAAA,GAAA,EAAA,MAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA;AACA;AACA;;AAEA,EAAA,OAAA,CAAA,EAAA,IAAA,CAAA,CAAA;AACA;;;;;"}
|
|
@@ -2,13 +2,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const instrumentationHapi = require('@opentelemetry/instrumentation-hapi');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
|
+
const nodeCore = require('@sentry/node-core');
|
|
5
6
|
const debugBuild = require('../../../debug-build.js');
|
|
6
|
-
const instrument = require('../../../otel/instrument.js');
|
|
7
|
-
const ensureIsWrapped = require('../../../utils/ensureIsWrapped.js');
|
|
8
7
|
|
|
9
8
|
const INTEGRATION_NAME = 'Hapi';
|
|
10
9
|
|
|
11
|
-
const instrumentHapi =
|
|
10
|
+
const instrumentHapi = nodeCore.generateInstrumentOnce(INTEGRATION_NAME, () => new instrumentationHapi.HapiInstrumentation());
|
|
12
11
|
|
|
13
12
|
const _hapiIntegration = (() => {
|
|
14
13
|
return {
|
|
@@ -113,7 +112,7 @@ async function setupHapiErrorHandler(server) {
|
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
116
|
-
|
|
115
|
+
nodeCore.ensureIsWrapped(server.register, 'hapi');
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
function addHapiSpanAttributes(span) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/hapi/index.ts"],"sourcesContent":["import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getClient,\n getDefaultIsolationScope,\n getIsolationScope,\n logger,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/hapi/index.ts"],"sourcesContent":["import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n defineIntegration,\n getClient,\n getDefaultIsolationScope,\n getIsolationScope,\n logger,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { ensureIsWrapped, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport type { Request, RequestEvent, Server } from './types';\n\nconst INTEGRATION_NAME = 'Hapi';\n\nexport const instrumentHapi = generateInstrumentOnce(INTEGRATION_NAME, () => new HapiInstrumentation());\n\nconst _hapiIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentHapi();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Hapi](https://hapi.dev/).\n *\n * If you also want to capture errors, you need to call `setupHapiErrorHandler(server)` after you set up your server.\n *\n * For more information, see the [hapi documentation](https://docs.sentry.io/platforms/javascript/guides/hapi/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.hapiIntegration()],\n * })\n * ```\n */\nexport const hapiIntegration = defineIntegration(_hapiIntegration);\n\nfunction isErrorEvent(event: unknown): event is RequestEvent {\n return !!(event && typeof event === 'object' && 'error' in event && event.error);\n}\n\nfunction sendErrorToSentry(errorData: object): void {\n captureException(errorData, {\n mechanism: {\n type: 'hapi',\n handled: false,\n data: {\n function: 'hapiErrorPlugin',\n },\n },\n });\n}\n\nexport const hapiErrorPlugin = {\n name: 'SentryHapiErrorPlugin',\n version: SDK_VERSION,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n register: async function (serverArg: Record<any, any>) {\n const server = serverArg as unknown as Server;\n\n server.events.on({ name: 'request', channels: ['error'] }, (request: Request, event: RequestEvent) => {\n if (getIsolationScope() !== getDefaultIsolationScope()) {\n const route = request.route;\n if (route.path) {\n getIsolationScope().setTransactionName(`${route.method.toUpperCase()} ${route.path}`);\n }\n } else {\n DEBUG_BUILD &&\n logger.warn('Isolation scope is still the default isolation scope - skipping setting transactionName');\n }\n\n if (isErrorEvent(event)) {\n sendErrorToSentry(event.error);\n }\n });\n },\n};\n\n/**\n * Add a Hapi plugin to capture errors to Sentry.\n *\n * @param server The Hapi server to attach the error handler to\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const Hapi = require('@hapi/hapi');\n *\n * const init = async () => {\n * const server = Hapi.server();\n *\n * // all your routes here\n *\n * await Sentry.setupHapiErrorHandler(server);\n *\n * await server.start();\n * };\n * ```\n */\nexport async function setupHapiErrorHandler(server: Server): Promise<void> {\n await server.register(hapiErrorPlugin);\n\n // Sadly, middleware spans do not go through `requestHook`, so we handle those here\n // We register this hook in this method, because if we register it in the integration `setup`,\n // it would always run even for users that are not even using hapi\n const client = getClient();\n if (client) {\n client.on('spanStart', span => {\n addHapiSpanAttributes(span);\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n ensureIsWrapped(server.register, 'hapi');\n}\n\nfunction addHapiSpanAttributes(span: Span): void {\n const attributes = spanToJSON(span).data;\n\n // this is one of: router, plugin, server.ext\n const type = attributes['hapi.type'];\n\n // If this is already set, or we have no Hapi span, no need to process again...\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) {\n return;\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.hapi',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.hapi`,\n });\n}\n"],"names":["generateInstrumentOnce","HapiInstrumentation","defineIntegration","captureException","SDK_VERSION","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","logger","getClient","ensureIsWrapped","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;;;;AAkBA,MAAM,gBAAA,GAAmB,MAAM;;AAElB,MAAA,cAAA,GAAiBA,+BAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,uCAAmB,EAAE;;AAEtG,MAAM,gBAAiB,IAAG,MAAM;AAChC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,cAAc,EAAE;AACtB,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,eAAgB,GAAEC,sBAAiB,CAAC,gBAAgB;;AAEjE,SAAS,YAAY,CAAC,KAAK,EAAkC;AAC7D,EAAE,OAAO,CAAC,EAAE,KAAM,IAAG,OAAO,KAAM,KAAI,QAAS,IAAG,WAAW,KAAA,IAAS,KAAK,CAAC,KAAK,CAAC;AAClF;;AAEA,SAAS,iBAAiB,CAAC,SAAS,EAAgB;AACpD,EAAEC,qBAAgB,CAAC,SAAS,EAAE;AAC9B,IAAI,SAAS,EAAE;AACf,MAAM,IAAI,EAAE,MAAM;AAClB,MAAM,OAAO,EAAE,KAAK;AACpB,MAAM,IAAI,EAAE;AACZ,QAAQ,QAAQ,EAAE,iBAAiB;AACnC,OAAO;AACP,KAAK;AACL,GAAG,CAAC;AACJ;;AAEO,MAAM,kBAAkB;AAC/B,EAAE,IAAI,EAAE,uBAAuB;AAC/B,EAAE,OA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