@depup/sentry__node 10.44.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/build/cjs/debug-build.js +11 -0
- package/build/cjs/debug-build.js.map +1 -0
- package/build/cjs/index.js +216 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/init.js +10 -0
- package/build/cjs/init.js.map +1 -0
- package/build/cjs/integrations/featureFlagShims/growthbook.js +12 -0
- package/build/cjs/integrations/featureFlagShims/growthbook.js.map +1 -0
- package/build/cjs/integrations/featureFlagShims/launchDarkly.js +43 -0
- package/build/cjs/integrations/featureFlagShims/launchDarkly.js.map +1 -0
- package/build/cjs/integrations/featureFlagShims/openFeature.js +55 -0
- package/build/cjs/integrations/featureFlagShims/openFeature.js.map +1 -0
- package/build/cjs/integrations/featureFlagShims/statsig.js +23 -0
- package/build/cjs/integrations/featureFlagShims/statsig.js.map +1 -0
- package/build/cjs/integrations/featureFlagShims/unleash.js +23 -0
- package/build/cjs/integrations/featureFlagShims/unleash.js.map +1 -0
- package/build/cjs/integrations/fs.js +142 -0
- package/build/cjs/integrations/fs.js.map +1 -0
- package/build/cjs/integrations/http.js +224 -0
- package/build/cjs/integrations/http.js.map +1 -0
- package/build/cjs/integrations/node-fetch.js +108 -0
- package/build/cjs/integrations/node-fetch.js.map +1 -0
- package/build/cjs/integrations/tracing/amqplib.js +47 -0
- package/build/cjs/integrations/tracing/amqplib.js.map +1 -0
- package/build/cjs/integrations/tracing/anthropic-ai/index.js +79 -0
- package/build/cjs/integrations/tracing/anthropic-ai/index.js.map +1 -0
- package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js +95 -0
- package/build/cjs/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/connect.js +110 -0
- package/build/cjs/integrations/tracing/connect.js.map +1 -0
- package/build/cjs/integrations/tracing/dataloader.js +72 -0
- package/build/cjs/integrations/tracing/dataloader.js.map +1 -0
- package/build/cjs/integrations/tracing/express.js +166 -0
- package/build/cjs/integrations/tracing/express.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/index.js +270 -0
- package/build/cjs/integrations/tracing/fastify/index.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/v3/constants.js +23 -0
- package/build/cjs/integrations/tracing/fastify/v3/constants.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
- package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +304 -0
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/fastify/v3/utils.js +135 -0
- package/build/cjs/integrations/tracing/fastify/v3/utils.js.map +1 -0
- package/build/cjs/integrations/tracing/firebase/firebase.js +50 -0
- package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -0
- package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js +44 -0
- package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +297 -0
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
- package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js +265 -0
- package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js.map +1 -0
- package/build/cjs/integrations/tracing/genericPool.js +59 -0
- package/build/cjs/integrations/tracing/genericPool.js.map +1 -0
- package/build/cjs/integrations/tracing/google-genai/index.js +78 -0
- package/build/cjs/integrations/tracing/google-genai/index.js.map +1 -0
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js +88 -0
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/graphql.js +127 -0
- package/build/cjs/integrations/tracing/graphql.js.map +1 -0
- package/build/cjs/integrations/tracing/hapi/index.js +135 -0
- package/build/cjs/integrations/tracing/hapi/index.js.map +1 -0
- package/build/cjs/integrations/tracing/hono/constants.js +15 -0
- package/build/cjs/integrations/tracing/hono/constants.js.map +1 -0
- package/build/cjs/integrations/tracing/hono/index.js +137 -0
- package/build/cjs/integrations/tracing/hono/index.js.map +1 -0
- package/build/cjs/integrations/tracing/hono/instrumentation.js +236 -0
- package/build/cjs/integrations/tracing/hono/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/index.js +110 -0
- package/build/cjs/integrations/tracing/index.js.map +1 -0
- package/build/cjs/integrations/tracing/kafka.js +48 -0
- package/build/cjs/integrations/tracing/kafka.js.map +1 -0
- package/build/cjs/integrations/tracing/knex.js +57 -0
- package/build/cjs/integrations/tracing/knex.js.map +1 -0
- package/build/cjs/integrations/tracing/koa.js +138 -0
- package/build/cjs/integrations/tracing/koa.js.map +1 -0
- package/build/cjs/integrations/tracing/langchain/index.js +116 -0
- package/build/cjs/integrations/tracing/langchain/index.js.map +1 -0
- package/build/cjs/integrations/tracing/langchain/instrumentation.js +220 -0
- package/build/cjs/integrations/tracing/langchain/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/langgraph/index.js +93 -0
- package/build/cjs/integrations/tracing/langgraph/index.js.map +1 -0
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js +60 -0
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/lrumemoizer.js +37 -0
- package/build/cjs/integrations/tracing/lrumemoizer.js.map +1 -0
- package/build/cjs/integrations/tracing/mongo.js +93 -0
- package/build/cjs/integrations/tracing/mongo.js.map +1 -0
- package/build/cjs/integrations/tracing/mongoose.js +46 -0
- package/build/cjs/integrations/tracing/mongoose.js.map +1 -0
- package/build/cjs/integrations/tracing/mysql.js +38 -0
- package/build/cjs/integrations/tracing/mysql.js.map +1 -0
- package/build/cjs/integrations/tracing/mysql2.js +46 -0
- package/build/cjs/integrations/tracing/mysql2.js.map +1 -0
- package/build/cjs/integrations/tracing/openai/index.js +78 -0
- package/build/cjs/integrations/tracing/openai/index.js.map +1 -0
- package/build/cjs/integrations/tracing/openai/instrumentation.js +104 -0
- package/build/cjs/integrations/tracing/openai/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing/postgres.js +48 -0
- package/build/cjs/integrations/tracing/postgres.js.map +1 -0
- package/build/cjs/integrations/tracing/postgresjs.js +378 -0
- package/build/cjs/integrations/tracing/postgresjs.js.map +1 -0
- package/build/cjs/integrations/tracing/prisma.js +203 -0
- package/build/cjs/integrations/tracing/prisma.js.map +1 -0
- package/build/cjs/integrations/tracing/redis.js +121 -0
- package/build/cjs/integrations/tracing/redis.js.map +1 -0
- package/build/cjs/integrations/tracing/tedious.js +67 -0
- package/build/cjs/integrations/tracing/tedious.js.map +1 -0
- package/build/cjs/integrations/tracing/vercelai/constants.js +6 -0
- package/build/cjs/integrations/tracing/vercelai/constants.js.map +1 -0
- package/build/cjs/integrations/tracing/vercelai/index.js +82 -0
- package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -0
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js +274 -0
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -0
- package/build/cjs/preload.js +21 -0
- package/build/cjs/preload.js.map +1 -0
- package/build/cjs/sdk/index.js +78 -0
- package/build/cjs/sdk/index.js.map +1 -0
- package/build/cjs/sdk/initOtel.js +126 -0
- package/build/cjs/sdk/initOtel.js.map +1 -0
- package/build/cjs/utils/redisCache.js +122 -0
- package/build/cjs/utils/redisCache.js.map +1 -0
- package/build/esm/debug-build.js +9 -0
- package/build/esm/debug-build.js.map +1 -0
- package/build/esm/index.js +44 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/init.js +10 -0
- package/build/esm/init.js.map +1 -0
- package/build/esm/integrations/featureFlagShims/growthbook.js +10 -0
- package/build/esm/integrations/featureFlagShims/growthbook.js.map +1 -0
- package/build/esm/integrations/featureFlagShims/launchDarkly.js +40 -0
- package/build/esm/integrations/featureFlagShims/launchDarkly.js.map +1 -0
- package/build/esm/integrations/featureFlagShims/openFeature.js +52 -0
- package/build/esm/integrations/featureFlagShims/openFeature.js.map +1 -0
- package/build/esm/integrations/featureFlagShims/statsig.js +21 -0
- package/build/esm/integrations/featureFlagShims/statsig.js.map +1 -0
- package/build/esm/integrations/featureFlagShims/unleash.js +21 -0
- package/build/esm/integrations/featureFlagShims/unleash.js.map +1 -0
- package/build/esm/integrations/fs.js +140 -0
- package/build/esm/integrations/fs.js.map +1 -0
- package/build/esm/integrations/http.js +219 -0
- package/build/esm/integrations/http.js.map +1 -0
- package/build/esm/integrations/node-fetch.js +105 -0
- package/build/esm/integrations/node-fetch.js.map +1 -0
- package/build/esm/integrations/tracing/amqplib.js +44 -0
- package/build/esm/integrations/tracing/amqplib.js.map +1 -0
- package/build/esm/integrations/tracing/anthropic-ai/index.js +76 -0
- package/build/esm/integrations/tracing/anthropic-ai/index.js.map +1 -0
- package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js +93 -0
- package/build/esm/integrations/tracing/anthropic-ai/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/connect.js +106 -0
- package/build/esm/integrations/tracing/connect.js.map +1 -0
- package/build/esm/integrations/tracing/dataloader.js +69 -0
- package/build/esm/integrations/tracing/dataloader.js.map +1 -0
- package/build/esm/integrations/tracing/express.js +161 -0
- package/build/esm/integrations/tracing/express.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/index.js +265 -0
- package/build/esm/integrations/tracing/fastify/index.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/v3/constants.js +21 -0
- package/build/esm/integrations/tracing/fastify/v3/constants.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
- package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +302 -0
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/fastify/v3/utils.js +131 -0
- package/build/esm/integrations/tracing/fastify/v3/utils.js.map +1 -0
- package/build/esm/integrations/tracing/firebase/firebase.js +47 -0
- package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -0
- package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js +42 -0
- package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +294 -0
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
- package/build/esm/integrations/tracing/firebase/otel/patches/functions.js +262 -0
- package/build/esm/integrations/tracing/firebase/otel/patches/functions.js.map +1 -0
- package/build/esm/integrations/tracing/genericPool.js +56 -0
- package/build/esm/integrations/tracing/genericPool.js.map +1 -0
- package/build/esm/integrations/tracing/google-genai/index.js +75 -0
- package/build/esm/integrations/tracing/google-genai/index.js.map +1 -0
- package/build/esm/integrations/tracing/google-genai/instrumentation.js +86 -0
- package/build/esm/integrations/tracing/google-genai/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/graphql.js +124 -0
- package/build/esm/integrations/tracing/graphql.js.map +1 -0
- package/build/esm/integrations/tracing/hapi/index.js +130 -0
- package/build/esm/integrations/tracing/hapi/index.js.map +1 -0
- package/build/esm/integrations/tracing/hono/constants.js +12 -0
- package/build/esm/integrations/tracing/hono/constants.js.map +1 -0
- package/build/esm/integrations/tracing/hono/index.js +133 -0
- package/build/esm/integrations/tracing/hono/index.js.map +1 -0
- package/build/esm/integrations/tracing/hono/instrumentation.js +234 -0
- package/build/esm/integrations/tracing/hono/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/index.js +107 -0
- package/build/esm/integrations/tracing/index.js.map +1 -0
- package/build/esm/integrations/tracing/kafka.js +45 -0
- package/build/esm/integrations/tracing/kafka.js.map +1 -0
- package/build/esm/integrations/tracing/knex.js +54 -0
- package/build/esm/integrations/tracing/knex.js.map +1 -0
- package/build/esm/integrations/tracing/koa.js +134 -0
- package/build/esm/integrations/tracing/koa.js.map +1 -0
- package/build/esm/integrations/tracing/langchain/index.js +113 -0
- package/build/esm/integrations/tracing/langchain/index.js.map +1 -0
- package/build/esm/integrations/tracing/langchain/instrumentation.js +218 -0
- package/build/esm/integrations/tracing/langchain/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/langgraph/index.js +90 -0
- package/build/esm/integrations/tracing/langgraph/index.js.map +1 -0
- package/build/esm/integrations/tracing/langgraph/instrumentation.js +58 -0
- package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/lrumemoizer.js +34 -0
- package/build/esm/integrations/tracing/lrumemoizer.js.map +1 -0
- package/build/esm/integrations/tracing/mongo.js +89 -0
- package/build/esm/integrations/tracing/mongo.js.map +1 -0
- package/build/esm/integrations/tracing/mongoose.js +43 -0
- package/build/esm/integrations/tracing/mongoose.js.map +1 -0
- package/build/esm/integrations/tracing/mysql.js +35 -0
- package/build/esm/integrations/tracing/mysql.js.map +1 -0
- package/build/esm/integrations/tracing/mysql2.js +43 -0
- package/build/esm/integrations/tracing/mysql2.js.map +1 -0
- package/build/esm/integrations/tracing/openai/index.js +75 -0
- package/build/esm/integrations/tracing/openai/index.js.map +1 -0
- package/build/esm/integrations/tracing/openai/instrumentation.js +102 -0
- package/build/esm/integrations/tracing/openai/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing/postgres.js +45 -0
- package/build/esm/integrations/tracing/postgres.js.map +1 -0
- package/build/esm/integrations/tracing/postgresjs.js +374 -0
- package/build/esm/integrations/tracing/postgresjs.js.map +1 -0
- package/build/esm/integrations/tracing/prisma.js +200 -0
- package/build/esm/integrations/tracing/prisma.js.map +1 -0
- package/build/esm/integrations/tracing/redis.js +117 -0
- package/build/esm/integrations/tracing/redis.js.map +1 -0
- package/build/esm/integrations/tracing/tedious.js +64 -0
- package/build/esm/integrations/tracing/tedious.js.map +1 -0
- package/build/esm/integrations/tracing/vercelai/constants.js +4 -0
- package/build/esm/integrations/tracing/vercelai/constants.js.map +1 -0
- package/build/esm/integrations/tracing/vercelai/index.js +79 -0
- package/build/esm/integrations/tracing/vercelai/index.js.map +1 -0
- package/build/esm/integrations/tracing/vercelai/instrumentation.js +269 -0
- package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/preload.js +21 -0
- package/build/esm/preload.js.map +1 -0
- package/build/esm/sdk/index.js +73 -0
- package/build/esm/sdk/index.js.map +1 -0
- package/build/esm/sdk/initOtel.js +121 -0
- package/build/esm/sdk/initOtel.js.map +1 -0
- package/build/esm/utils/redisCache.js +114 -0
- package/build/esm/utils/redisCache.js.map +1 -0
- package/build/import-hook.mjs +5 -0
- package/build/loader-hook.mjs +1 -0
- package/build/types/debug-build.d.ts +7 -0
- package/build/types/debug-build.d.ts.map +1 -0
- package/build/types/index.d.ts +42 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/init.d.ts +2 -0
- package/build/types/init.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/growthbook.d.ts +6 -0
- package/build/types/integrations/featureFlagShims/growthbook.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/index.d.ts +6 -0
- package/build/types/integrations/featureFlagShims/index.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/launchDarkly.d.ts +10 -0
- package/build/types/integrations/featureFlagShims/launchDarkly.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/openFeature.d.ts +23 -0
- package/build/types/integrations/featureFlagShims/openFeature.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/statsig.d.ts +6 -0
- package/build/types/integrations/featureFlagShims/statsig.d.ts.map +1 -0
- package/build/types/integrations/featureFlagShims/unleash.d.ts +6 -0
- package/build/types/integrations/featureFlagShims/unleash.d.ts.map +1 -0
- package/build/types/integrations/fs.d.ts +24 -0
- package/build/types/integrations/fs.d.ts.map +1 -0
- package/build/types/integrations/http.d.ts +136 -0
- package/build/types/integrations/http.d.ts.map +1 -0
- package/build/types/integrations/node-fetch.d.ts +36 -0
- package/build/types/integrations/node-fetch.d.ts.map +1 -0
- package/build/types/integrations/tracing/amqplib.d.ts +20 -0
- package/build/types/integrations/tracing/amqplib.d.ts.map +1 -0
- package/build/types/integrations/tracing/anthropic-ai/index.d.ts +59 -0
- package/build/types/integrations/tracing/anthropic-ai/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/anthropic-ai/instrumentation.d.ts +19 -0
- package/build/types/integrations/tracing/anthropic-ai/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/connect.d.ts +46 -0
- package/build/types/integrations/tracing/connect.d.ts.map +1 -0
- package/build/types/integrations/tracing/dataloader.d.ts +20 -0
- package/build/types/integrations/tracing/dataloader.d.ts.map +1 -0
- package/build/types/integrations/tracing/express.d.ts +72 -0
- package/build/types/integrations/tracing/express.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/index.d.ts +119 -0
- package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/types.d.ts +33 -0
- package/build/types/integrations/tracing/fastify/types.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/constants.d.ts +3 -0
- package/build/types/integrations/tracing/fastify/v3/constants.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
- package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
- package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
- package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/types.d.ts +21 -0
- package/build/types/integrations/tracing/fastify/v3/types.d.ts.map +1 -0
- package/build/types/integrations/tracing/fastify/v3/utils.d.ts +28 -0
- package/build/types/integrations/tracing/fastify/v3/utils.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/firebase.d.ts +6 -0
- package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/index.d.ts +2 -0
- package/build/types/integrations/tracing/firebase/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
- package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/otel/index.d.ts +3 -0
- package/build/types/integrations/tracing/firebase/otel/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts +25 -0
- package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts +23 -0
- package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts.map +1 -0
- package/build/types/integrations/tracing/firebase/otel/types.d.ts +120 -0
- package/build/types/integrations/tracing/firebase/otel/types.d.ts.map +1 -0
- package/build/types/integrations/tracing/genericPool.d.ts +20 -0
- package/build/types/integrations/tracing/genericPool.d.ts.map +1 -0
- package/build/types/integrations/tracing/google-genai/index.d.ts +59 -0
- package/build/types/integrations/tracing/google-genai/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/google-genai/instrumentation.d.ts +20 -0
- package/build/types/integrations/tracing/google-genai/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/graphql.d.ts +48 -0
- package/build/types/integrations/tracing/graphql.d.ts.map +1 -0
- package/build/types/integrations/tracing/hapi/index.d.ts +50 -0
- package/build/types/integrations/tracing/hapi/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/hapi/types.d.ts +166 -0
- package/build/types/integrations/tracing/hapi/types.d.ts.map +1 -0
- package/build/types/integrations/tracing/hono/constants.d.ts +11 -0
- package/build/types/integrations/tracing/hono/constants.d.ts.map +1 -0
- package/build/types/integrations/tracing/hono/index.d.ts +52 -0
- package/build/types/integrations/tracing/hono/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/hono/instrumentation.d.ts +55 -0
- package/build/types/integrations/tracing/hono/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/hono/types.d.ts +36 -0
- package/build/types/integrations/tracing/hono/types.d.ts.map +1 -0
- package/build/types/integrations/tracing/index.d.ts +12 -0
- package/build/types/integrations/tracing/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/kafka.d.ts +19 -0
- package/build/types/integrations/tracing/kafka.d.ts.map +1 -0
- package/build/types/integrations/tracing/knex.d.ts +20 -0
- package/build/types/integrations/tracing/knex.d.ts.map +1 -0
- package/build/types/integrations/tracing/koa.d.ts +70 -0
- package/build/types/integrations/tracing/koa.d.ts.map +1 -0
- package/build/types/integrations/tracing/langchain/index.d.ts +97 -0
- package/build/types/integrations/tracing/langchain/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/langchain/instrumentation.d.ts +29 -0
- package/build/types/integrations/tracing/langchain/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/langgraph/index.d.ts +74 -0
- package/build/types/integrations/tracing/langgraph/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/langgraph/instrumentation.d.ts +19 -0
- package/build/types/integrations/tracing/langgraph/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/lrumemoizer.d.ts +19 -0
- package/build/types/integrations/tracing/lrumemoizer.d.ts.map +1 -0
- package/build/types/integrations/tracing/mongo.d.ts +24 -0
- package/build/types/integrations/tracing/mongo.d.ts.map +1 -0
- package/build/types/integrations/tracing/mongoose.d.ts +20 -0
- package/build/types/integrations/tracing/mongoose.d.ts.map +1 -0
- package/build/types/integrations/tracing/mysql.d.ts +20 -0
- package/build/types/integrations/tracing/mysql.d.ts.map +1 -0
- package/build/types/integrations/tracing/mysql2.d.ts +20 -0
- package/build/types/integrations/tracing/mysql2.d.ts.map +1 -0
- package/build/types/integrations/tracing/openai/index.d.ts +59 -0
- package/build/types/integrations/tracing/openai/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/openai/instrumentation.d.ts +26 -0
- package/build/types/integrations/tracing/openai/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/postgres.d.ts +24 -0
- package/build/types/integrations/tracing/postgres.d.ts.map +1 -0
- package/build/types/integrations/tracing/postgresjs.d.ts +101 -0
- package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -0
- package/build/types/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts +38 -0
- package/build/types/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts.map +1 -0
- package/build/types/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts +31 -0
- package/build/types/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts.map +1 -0
- package/build/types/integrations/tracing/prisma.d.ts +50 -0
- package/build/types/integrations/tracing/prisma.d.ts.map +1 -0
- package/build/types/integrations/tracing/redis.d.ts +41 -0
- package/build/types/integrations/tracing/redis.d.ts.map +1 -0
- package/build/types/integrations/tracing/tedious.d.ts +20 -0
- package/build/types/integrations/tracing/tedious.d.ts.map +1 -0
- package/build/types/integrations/tracing/vercelai/constants.d.ts +2 -0
- package/build/types/integrations/tracing/vercelai/constants.d.ts.map +1 -0
- package/build/types/integrations/tracing/vercelai/index.d.ts +43 -0
- package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -0
- package/build/types/integrations/tracing/vercelai/instrumentation.d.ts +56 -0
- package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing/vercelai/types.d.ts +59 -0
- package/build/types/integrations/tracing/vercelai/types.d.ts.map +1 -0
- package/build/types/preload.d.ts +2 -0
- package/build/types/preload.d.ts.map +1 -0
- package/build/types/sdk/index.d.ts +18 -0
- package/build/types/sdk/index.d.ts.map +1 -0
- package/build/types/sdk/initOtel.d.ts +28 -0
- package/build/types/sdk/initOtel.d.ts.map +1 -0
- package/build/types/types.d.ts +89 -0
- package/build/types/types.d.ts.map +1 -0
- package/build/types/utils/redisCache.d.ts +16 -0
- package/build/types/utils/redisCache.d.ts.map +1 -0
- package/build/types-ts3.8/debug-build.d.ts +7 -0
- package/build/types-ts3.8/index.d.ts +42 -0
- package/build/types-ts3.8/init.d.ts +2 -0
- package/build/types-ts3.8/integrations/featureFlagShims/growthbook.d.ts +6 -0
- package/build/types-ts3.8/integrations/featureFlagShims/index.d.ts +6 -0
- package/build/types-ts3.8/integrations/featureFlagShims/launchDarkly.d.ts +10 -0
- package/build/types-ts3.8/integrations/featureFlagShims/openFeature.d.ts +23 -0
- package/build/types-ts3.8/integrations/featureFlagShims/statsig.d.ts +6 -0
- package/build/types-ts3.8/integrations/featureFlagShims/unleash.d.ts +6 -0
- package/build/types-ts3.8/integrations/fs.d.ts +24 -0
- package/build/types-ts3.8/integrations/http.d.ts +139 -0
- package/build/types-ts3.8/integrations/node-fetch.d.ts +36 -0
- package/build/types-ts3.8/integrations/tracing/amqplib.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/anthropic-ai/index.d.ts +59 -0
- package/build/types-ts3.8/integrations/tracing/anthropic-ai/instrumentation.d.ts +19 -0
- package/build/types-ts3.8/integrations/tracing/connect.d.ts +46 -0
- package/build/types-ts3.8/integrations/tracing/dataloader.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/express.d.ts +72 -0
- package/build/types-ts3.8/integrations/tracing/fastify/index.d.ts +119 -0
- package/build/types-ts3.8/integrations/tracing/fastify/types.d.ts +33 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/constants.d.ts +3 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/types.d.ts +21 -0
- package/build/types-ts3.8/integrations/tracing/fastify/v3/utils.d.ts +28 -0
- package/build/types-ts3.8/integrations/tracing/firebase/firebase.d.ts +6 -0
- package/build/types-ts3.8/integrations/tracing/firebase/index.d.ts +2 -0
- package/build/types-ts3.8/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
- package/build/types-ts3.8/integrations/tracing/firebase/otel/index.d.ts +3 -0
- package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/firestore.d.ts +25 -0
- package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/functions.d.ts +23 -0
- package/build/types-ts3.8/integrations/tracing/firebase/otel/types.d.ts +120 -0
- package/build/types-ts3.8/integrations/tracing/genericPool.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/google-genai/index.d.ts +59 -0
- package/build/types-ts3.8/integrations/tracing/google-genai/instrumentation.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/graphql.d.ts +48 -0
- package/build/types-ts3.8/integrations/tracing/hapi/index.d.ts +50 -0
- package/build/types-ts3.8/integrations/tracing/hapi/types.d.ts +166 -0
- package/build/types-ts3.8/integrations/tracing/hono/constants.d.ts +11 -0
- package/build/types-ts3.8/integrations/tracing/hono/index.d.ts +52 -0
- package/build/types-ts3.8/integrations/tracing/hono/instrumentation.d.ts +55 -0
- package/build/types-ts3.8/integrations/tracing/hono/types.d.ts +36 -0
- package/build/types-ts3.8/integrations/tracing/index.d.ts +12 -0
- package/build/types-ts3.8/integrations/tracing/kafka.d.ts +19 -0
- package/build/types-ts3.8/integrations/tracing/knex.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/koa.d.ts +70 -0
- package/build/types-ts3.8/integrations/tracing/langchain/index.d.ts +97 -0
- package/build/types-ts3.8/integrations/tracing/langchain/instrumentation.d.ts +29 -0
- package/build/types-ts3.8/integrations/tracing/langgraph/index.d.ts +74 -0
- package/build/types-ts3.8/integrations/tracing/langgraph/instrumentation.d.ts +19 -0
- package/build/types-ts3.8/integrations/tracing/lrumemoizer.d.ts +19 -0
- package/build/types-ts3.8/integrations/tracing/mongo.d.ts +24 -0
- package/build/types-ts3.8/integrations/tracing/mongoose.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/mysql.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/mysql2.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/openai/index.d.ts +59 -0
- package/build/types-ts3.8/integrations/tracing/openai/instrumentation.d.ts +26 -0
- package/build/types-ts3.8/integrations/tracing/postgres.d.ts +24 -0
- package/build/types-ts3.8/integrations/tracing/postgresjs.d.ts +101 -0
- package/build/types-ts3.8/integrations/tracing/prisma/vendor/v5-tracing-helper.d.ts +44 -0
- package/build/types-ts3.8/integrations/tracing/prisma/vendor/v6-tracing-helper.d.ts +34 -0
- package/build/types-ts3.8/integrations/tracing/prisma.d.ts +50 -0
- package/build/types-ts3.8/integrations/tracing/redis.d.ts +41 -0
- package/build/types-ts3.8/integrations/tracing/tedious.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing/vercelai/constants.d.ts +2 -0
- package/build/types-ts3.8/integrations/tracing/vercelai/index.d.ts +43 -0
- package/build/types-ts3.8/integrations/tracing/vercelai/instrumentation.d.ts +56 -0
- package/build/types-ts3.8/integrations/tracing/vercelai/types.d.ts +59 -0
- package/build/types-ts3.8/preload.d.ts +2 -0
- package/build/types-ts3.8/sdk/index.d.ts +18 -0
- package/build/types-ts3.8/sdk/initOtel.d.ts +31 -0
- package/build/types-ts3.8/types.d.ts +89 -0
- package/build/types-ts3.8/utils/redisCache.d.ts +16 -0
- package/changes.json +10 -0
- package/package.json +150 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import * as diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import { FastifyOtelInstrumentation } from '@fastify/otel';
|
|
3
|
+
import { debug, defineIntegration, getClient, getIsolationScope, captureException, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
4
|
+
import { generateInstrumentOnce } from '@sentry/node-core';
|
|
5
|
+
import { DEBUG_BUILD } from '../../../debug-build.js';
|
|
6
|
+
import { FastifyInstrumentationV3 } from './v3/instrumentation.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for the Fastify integration.
|
|
10
|
+
*
|
|
11
|
+
* `shouldHandleError` - Callback method deciding whether error should be captured and sent to Sentry
|
|
12
|
+
* This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.
|
|
13
|
+
* Fastify v3 and v4 use `setupFastifyErrorHandler` instead.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```javascript
|
|
18
|
+
* Sentry.init({
|
|
19
|
+
* integrations: [
|
|
20
|
+
* Sentry.fastifyIntegration({
|
|
21
|
+
* shouldHandleError(_error, _request, reply) {
|
|
22
|
+
* return reply.statusCode >= 500;
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const INTEGRATION_NAME = 'Fastify';
|
|
32
|
+
|
|
33
|
+
const instrumentFastifyV3 = generateInstrumentOnce(
|
|
34
|
+
`${INTEGRATION_NAME}.v3`,
|
|
35
|
+
() => new FastifyInstrumentationV3(),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function getFastifyIntegration() {
|
|
39
|
+
const client = getClient();
|
|
40
|
+
if (!client) {
|
|
41
|
+
return undefined;
|
|
42
|
+
} else {
|
|
43
|
+
return client.getIntegrationByName(INTEGRATION_NAME);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleFastifyError(
|
|
48
|
+
|
|
49
|
+
error,
|
|
50
|
+
request,
|
|
51
|
+
reply,
|
|
52
|
+
handlerOrigin,
|
|
53
|
+
) {
|
|
54
|
+
const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;
|
|
55
|
+
// Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered
|
|
56
|
+
if (handlerOrigin === 'diagnostics-channel') {
|
|
57
|
+
this.diagnosticsChannelExists = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {
|
|
61
|
+
DEBUG_BUILD &&
|
|
62
|
+
debug.warn(
|
|
63
|
+
'Fastify error handler was already registered via diagnostics channel.',
|
|
64
|
+
'You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options.',
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// If the diagnostics channel already exists, we don't need to handle the error again
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (shouldHandleError(error, request, reply)) {
|
|
72
|
+
captureException(error, { mechanism: { handled: false, type: 'auto.function.fastify' } });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const instrumentFastify = generateInstrumentOnce(`${INTEGRATION_NAME}.v5`, () => {
|
|
77
|
+
const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();
|
|
78
|
+
const plugin = fastifyOtelInstrumentationInstance.plugin();
|
|
79
|
+
|
|
80
|
+
// This message handler works for Fastify versions 3, 4 and 5
|
|
81
|
+
diagnosticsChannel.subscribe('fastify.initialization', message => {
|
|
82
|
+
const fastifyInstance = (message ).fastify;
|
|
83
|
+
|
|
84
|
+
fastifyInstance?.register(plugin).after(err => {
|
|
85
|
+
if (err) {
|
|
86
|
+
DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err);
|
|
87
|
+
} else {
|
|
88
|
+
instrumentClient();
|
|
89
|
+
|
|
90
|
+
if (fastifyInstance) {
|
|
91
|
+
instrumentOnRequest(fastifyInstance);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// This diagnostics channel only works on Fastify version 5
|
|
98
|
+
// For versions 3 and 4, we use `setupFastifyErrorHandler` instead
|
|
99
|
+
diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {
|
|
100
|
+
const { error, request, reply } = message
|
|
101
|
+
|
|
102
|
+
;
|
|
103
|
+
|
|
104
|
+
handleFastifyError.call(handleFastifyError, error, request, reply, 'diagnostics-channel');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Returning this as Instrumentation to avoid leaking @fastify/otel types into the public API
|
|
108
|
+
return fastifyOtelInstrumentationInstance ;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const _fastifyIntegration = (({ shouldHandleError }) => {
|
|
112
|
+
let _shouldHandleError;
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
name: INTEGRATION_NAME,
|
|
116
|
+
setupOnce() {
|
|
117
|
+
_shouldHandleError = shouldHandleError || defaultShouldHandleError;
|
|
118
|
+
|
|
119
|
+
instrumentFastifyV3();
|
|
120
|
+
instrumentFastify();
|
|
121
|
+
},
|
|
122
|
+
getShouldHandleError() {
|
|
123
|
+
return _shouldHandleError;
|
|
124
|
+
},
|
|
125
|
+
setShouldHandleError(fn) {
|
|
126
|
+
_shouldHandleError = fn;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}) ;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
|
|
133
|
+
*
|
|
134
|
+
* If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
|
|
135
|
+
*
|
|
136
|
+
* For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```javascript
|
|
140
|
+
* const Sentry = require('@sentry/node');
|
|
141
|
+
*
|
|
142
|
+
* Sentry.init({
|
|
143
|
+
* integrations: [Sentry.fastifyIntegration()],
|
|
144
|
+
* })
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const fastifyIntegration = defineIntegration((options = {}) =>
|
|
148
|
+
_fastifyIntegration(options),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Default function to determine if an error should be sent to Sentry
|
|
153
|
+
*
|
|
154
|
+
* 3xx and 4xx errors are not sent by default.
|
|
155
|
+
*/
|
|
156
|
+
function defaultShouldHandleError(_error, _request, reply) {
|
|
157
|
+
const statusCode = reply.statusCode;
|
|
158
|
+
// 3xx and 4xx errors are not sent by default.
|
|
159
|
+
return statusCode >= 500 || statusCode <= 299;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Add an Fastify error handler to capture errors to Sentry.
|
|
164
|
+
*
|
|
165
|
+
* @param fastify The Fastify instance to which to add the error handler
|
|
166
|
+
* @param options Configuration options for the handler
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```javascript
|
|
170
|
+
* const Sentry = require('@sentry/node');
|
|
171
|
+
* const Fastify = require("fastify");
|
|
172
|
+
*
|
|
173
|
+
* const app = Fastify();
|
|
174
|
+
*
|
|
175
|
+
* Sentry.setupFastifyErrorHandler(app);
|
|
176
|
+
*
|
|
177
|
+
* // Add your routes, etc.
|
|
178
|
+
*
|
|
179
|
+
* app.listen({ port: 3000 });
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function setupFastifyErrorHandler(fastify, options) {
|
|
183
|
+
if (options?.shouldHandleError) {
|
|
184
|
+
getFastifyIntegration()?.setShouldHandleError(options.shouldHandleError);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const plugin = Object.assign(
|
|
188
|
+
function (fastify, _options, done) {
|
|
189
|
+
fastify.addHook('onError', async (request, reply, error) => {
|
|
190
|
+
handleFastifyError.call(handleFastifyError, error, request, reply, 'onError-hook');
|
|
191
|
+
});
|
|
192
|
+
done();
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
[Symbol.for('skip-override')]: true,
|
|
196
|
+
[Symbol.for('fastify.display-name')]: 'sentry-fastify-error-handler',
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
fastify.register(plugin);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function addFastifySpanAttributes(span) {
|
|
204
|
+
const spanJSON = spanToJSON(span);
|
|
205
|
+
const spanName = spanJSON.description;
|
|
206
|
+
const attributes = spanJSON.data;
|
|
207
|
+
|
|
208
|
+
const type = attributes['fastify.type'];
|
|
209
|
+
|
|
210
|
+
const isHook = type === 'hook';
|
|
211
|
+
const isHandler = type === spanName?.startsWith('handler -');
|
|
212
|
+
// In @fastify/otel `request-handler` is separated by dash, not underscore
|
|
213
|
+
const isRequestHandler = spanName === 'request' || type === 'request-handler';
|
|
214
|
+
|
|
215
|
+
// If this is already set, or we have no fastify span, no need to process again...
|
|
216
|
+
if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || (!isHandler && !isRequestHandler && !isHook)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const opPrefix = isHook ? 'hook' : isHandler ? 'middleware' : isRequestHandler ? 'request_handler' : '<unknown>';
|
|
221
|
+
|
|
222
|
+
span.setAttributes({
|
|
223
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',
|
|
224
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${opPrefix}.fastify`,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const attrName = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];
|
|
228
|
+
if (typeof attrName === 'string') {
|
|
229
|
+
// Try removing `fastify -> ` and `@fastify/otel -> ` prefixes
|
|
230
|
+
// This is a bit of a hack, and not always working for all spans
|
|
231
|
+
// But it's the best we can do without a proper API
|
|
232
|
+
const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\/otel -> /, '');
|
|
233
|
+
|
|
234
|
+
span.updateName(updatedName);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function instrumentClient() {
|
|
239
|
+
const client = getClient();
|
|
240
|
+
if (client) {
|
|
241
|
+
client.on('spanStart', (span) => {
|
|
242
|
+
addFastifySpanAttributes(span);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function instrumentOnRequest(fastify) {
|
|
248
|
+
fastify.addHook('onRequest', async (request, _reply) => {
|
|
249
|
+
if (request.opentelemetry) {
|
|
250
|
+
const { span } = request.opentelemetry();
|
|
251
|
+
|
|
252
|
+
if (span) {
|
|
253
|
+
addFastifySpanAttributes(span);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const routeName = request.routeOptions?.url;
|
|
258
|
+
const method = request.method || 'GET';
|
|
259
|
+
|
|
260
|
+
getIsolationScope().setTransactionName(`${method} ${routeName}`);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export { fastifyIntegration, instrumentFastify, instrumentFastifyV3, setupFastifyErrorHandler };
|
|
265
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { FastifyOtelInstrumentation } from '@fastify/otel';\nimport type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n debug,\n defineIntegration,\n getClient,\n getIsolationScope,\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 type { FastifyInstance, FastifyMinimal, FastifyReply, FastifyRequest } from './types';\nimport { FastifyInstrumentationV3 } from './v3/instrumentation';\n\n/**\n * Options for the Fastify integration.\n *\n * `shouldHandleError` - Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\n *\n * @example\n *\n * ```javascript\n * Sentry.init({\n * integrations: [\n * Sentry.fastifyIntegration({\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 500;\n * },\n * });\n * },\n * });\n * ```\n *\n */\ninterface FastifyIntegrationOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\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 shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\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 *\n * ```javascript\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 400;\n * },\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';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(\n `${INTEGRATION_NAME}.v3`,\n () => new FastifyInstrumentationV3(),\n);\n\nfunction getFastifyIntegration(): ReturnType<typeof _fastifyIntegration> | undefined {\n const client = getClient();\n if (!client) {\n return undefined;\n } else {\n return client.getIntegrationByName(INTEGRATION_NAME);\n }\n}\n\nfunction handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } },\n reply: FastifyReply,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;\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 debug.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options.',\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, { mechanism: { handled: false, type: 'auto.function.fastify' } });\n }\n}\n\nexport const instrumentFastify = generateInstrumentOnce(`${INTEGRATION_NAME}.v5`, () => {\n const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();\n const plugin = fastifyOtelInstrumentationInstance.plugin();\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 && debug.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, 'diagnostics-channel');\n });\n\n // Returning this as Instrumentation to avoid leaking @fastify/otel types into the public API\n return fastifyOtelInstrumentationInstance as unknown as Instrumentation<InstrumentationConfig>;\n});\n\nconst _fastifyIntegration = (({ shouldHandleError }: Partial<FastifyIntegrationOptions>) => {\n let _shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n _shouldHandleError = shouldHandleError || defaultShouldHandleError;\n\n instrumentFastifyV3();\n instrumentFastify();\n },\n getShouldHandleError() {\n return _shouldHandleError;\n },\n setShouldHandleError(fn: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean): void {\n _shouldHandleError = fn;\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((options: Partial<FastifyIntegrationOptions> = {}) =>\n _fastifyIntegration(options),\n);\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: FastifyMinimal, options?: Partial<FastifyHandlerOptions>): void {\n if (options?.shouldHandleError) {\n getFastifyIntegration()?.setShouldHandleError(options.shouldHandleError);\n }\n\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, '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 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":[],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Vendored from https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/constants.ts
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const spanRequestSymbol = Symbol('opentelemetry.instrumentation.fastify.request_active_span');
|
|
19
|
+
|
|
20
|
+
export { spanRequestSymbol };
|
|
21
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../../../src/integrations/tracing/fastify/v3/constants.ts"],"sourcesContent":["// Vendored from https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/constants.ts\n/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const spanRequestSymbol = Symbol('opentelemetry.instrumentation.fastify.request_active_span');\n\n// The instrumentation creates a span for invocations of lifecycle hook handlers\n// that take `(request, reply, ...[, done])` arguments. Currently this is all\n// lifecycle hooks except `onRequestAbort`.\n// https://fastify.dev/docs/latest/Reference/Hooks\nexport const hooksNamesToWrap = new Set([\n 'onTimeout',\n 'onRequest',\n 'preParsing',\n 'preValidation',\n 'preSerialization',\n 'preHandler',\n 'onSend',\n 'onResponse',\n 'onError',\n]);\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;MAEa,iBAAA,GAAoB,MAAM,CAAC,2DAA2D;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Vendored from https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/enums/AttributeNames.ts
|
|
2
|
+
//
|
|
3
|
+
/*
|
|
4
|
+
* Copyright The OpenTelemetry Authors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
var AttributeNames; (function (AttributeNames) {
|
|
20
|
+
const FASTIFY_NAME = 'fastify.name'; AttributeNames["FASTIFY_NAME"] = FASTIFY_NAME;
|
|
21
|
+
const FASTIFY_TYPE = 'fastify.type'; AttributeNames["FASTIFY_TYPE"] = FASTIFY_TYPE;
|
|
22
|
+
const HOOK_NAME = 'hook.name'; AttributeNames["HOOK_NAME"] = HOOK_NAME;
|
|
23
|
+
const PLUGIN_NAME = 'plugin.name'; AttributeNames["PLUGIN_NAME"] = PLUGIN_NAME;
|
|
24
|
+
})(AttributeNames || (AttributeNames = {}));
|
|
25
|
+
|
|
26
|
+
var FastifyTypes; (function (FastifyTypes) {
|
|
27
|
+
const MIDDLEWARE = 'middleware'; FastifyTypes["MIDDLEWARE"] = MIDDLEWARE;
|
|
28
|
+
const REQUEST_HANDLER = 'request_handler'; FastifyTypes["REQUEST_HANDLER"] = REQUEST_HANDLER;
|
|
29
|
+
})(FastifyTypes || (FastifyTypes = {}));
|
|
30
|
+
|
|
31
|
+
var FastifyNames; (function (FastifyNames) {
|
|
32
|
+
const MIDDLEWARE = 'middleware'; FastifyNames["MIDDLEWARE"] = MIDDLEWARE;
|
|
33
|
+
const REQUEST_HANDLER = 'request handler'; FastifyNames["REQUEST_HANDLER"] = REQUEST_HANDLER;
|
|
34
|
+
})(FastifyNames || (FastifyNames = {}));
|
|
35
|
+
|
|
36
|
+
export { AttributeNames, FastifyNames, FastifyTypes };
|
|
37
|
+
//# sourceMappingURL=AttributeNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeNames.js","sources":["../../../../../../../src/integrations/tracing/fastify/v3/enums/AttributeNames.ts"],"sourcesContent":["// Vendored from https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/enums/AttributeNames.ts\n//\n/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport enum AttributeNames {\n FASTIFY_NAME = 'fastify.name',\n FASTIFY_TYPE = 'fastify.type',\n HOOK_NAME = 'hook.name',\n PLUGIN_NAME = 'plugin.name',\n}\n\nexport enum FastifyTypes {\n MIDDLEWARE = 'middleware',\n REQUEST_HANDLER = 'request_handler',\n}\n\nexport enum FastifyNames {\n MIDDLEWARE = 'middleware',\n REQUEST_HANDLER = 'request handler',\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAA,eAAA,CAAA,CAAA,UAAA,cAAA,EAA2B;AAC3B,EAAE,MAAA,YAAA,GAAe,cAAA,CAAA,CAAA,cAAA,CAAA,cAAA,CAAA,GAAA,YAAA;AACjB,EAAE,MAAA,YAAA,GAAe,cAAA,CAAA,CAAA,cAAA,CAAA,cAAA,CAAA,GAAA,YAAA;AACjB,EAAE,MAAA,SAAA,GAAY,WAAA,CAAA,CAAA,cAAA,CAAA,WAAA,CAAA,GAAA,SAAA;AACd,EAAE,MAAA,WAAA,GAAc,aAAA,CAAA,CAAA,cAAA,CAAA,aAAA,CAAA,GAAA,WAAA;AAChB,CAAA,EAAA,cAAA,KAAA,cAAA,GAAA,EAAA,CAAA,CAAA;;AAEA,IAAA,aAAA,CAAA,CAAA,UAAA,YAAA,EAAyB;AACzB,EAAE,MAAA,UAAA,GAAa,YAAA,CAAA,CAAA,YAAA,CAAA,YAAA,CAAA,GAAA,UAAA;AACf,EAAE,MAAA,eAAA,GAAkB,iBAAA,CAAA,CAAA,YAAA,CAAA,iBAAA,CAAA,GAAA,eAAA;AACpB,CAAA,EAAA,YAAA,KAAA,YAAA,GAAA,EAAA,CAAA,CAAA;;AAEA,IAAA,aAAA,CAAA,CAAA,UAAA,YAAA,EAAyB;AACzB,EAAE,MAAA,UAAA,GAAa,YAAA,CAAA,CAAA,YAAA,CAAA,YAAA,CAAA,GAAA,UAAA;AACf,EAAE,MAAA,eAAA,GAAkB,iBAAA,CAAA,CAAA,YAAA,CAAA,iBAAA,CAAA,GAAA,eAAA;AACpB,CAAA,EAAA,YAAA,KAAA,YAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { context, trace, SpanStatusCode } from '@opentelemetry/api';
|
|
2
|
+
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
|
|
3
|
+
import { InstrumentationBase, InstrumentationNodeModuleDefinition, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
|
|
4
|
+
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
|
|
5
|
+
import { getIsolationScope, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getClient } from '@sentry/core';
|
|
6
|
+
import { FastifyNames, AttributeNames, FastifyTypes } from './enums/AttributeNames.js';
|
|
7
|
+
import { startSpan, endSpan, safeExecuteInTheMiddleMaybePromise } from './utils.js';
|
|
8
|
+
|
|
9
|
+
// Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
12
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
13
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
15
|
+
|
|
16
|
+
/** @knipignore */
|
|
17
|
+
|
|
18
|
+
const PACKAGE_VERSION = '0.1.0';
|
|
19
|
+
|
|
20
|
+
const PACKAGE_NAME = '@sentry/instrumentation-fastify-v3';
|
|
21
|
+
const ANONYMOUS_NAME = 'anonymous';
|
|
22
|
+
|
|
23
|
+
// The instrumentation creates a span for invocations of lifecycle hook handlers
|
|
24
|
+
// that take `(request, reply, ...[, done])` arguments. Currently this is all
|
|
25
|
+
// lifecycle hooks except `onRequestAbort`.
|
|
26
|
+
// https://fastify.dev/docs/latest/Reference/Hooks
|
|
27
|
+
const hooksNamesToWrap = new Set([
|
|
28
|
+
'onTimeout',
|
|
29
|
+
'onRequest',
|
|
30
|
+
'preParsing',
|
|
31
|
+
'preValidation',
|
|
32
|
+
'preSerialization',
|
|
33
|
+
'preHandler',
|
|
34
|
+
'onSend',
|
|
35
|
+
'onResponse',
|
|
36
|
+
'onError',
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fastify instrumentation for OpenTelemetry
|
|
41
|
+
*/
|
|
42
|
+
class FastifyInstrumentationV3 extends InstrumentationBase {
|
|
43
|
+
constructor(config = {}) {
|
|
44
|
+
super(PACKAGE_NAME, PACKAGE_VERSION, config);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init() {
|
|
48
|
+
return [
|
|
49
|
+
new InstrumentationNodeModuleDefinition('fastify', ['>=3.0.0 <4'], moduleExports => {
|
|
50
|
+
return this._patchConstructor(moduleExports);
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_hookOnRequest() {
|
|
56
|
+
const instrumentation = this;
|
|
57
|
+
|
|
58
|
+
return function onRequest(request, reply, done) {
|
|
59
|
+
if (!instrumentation.isEnabled()) {
|
|
60
|
+
return done();
|
|
61
|
+
}
|
|
62
|
+
instrumentation._wrap(reply, 'send', instrumentation._patchSend());
|
|
63
|
+
|
|
64
|
+
const anyRequest = request ;
|
|
65
|
+
|
|
66
|
+
const rpcMetadata = getRPCMetadata(context.active());
|
|
67
|
+
const routeName = anyRequest.routeOptions
|
|
68
|
+
? anyRequest.routeOptions.url // since fastify@4.10.0
|
|
69
|
+
: request.routerPath;
|
|
70
|
+
if (routeName && rpcMetadata?.type === RPCType.HTTP) {
|
|
71
|
+
rpcMetadata.route = routeName;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const method = request.method || 'GET';
|
|
75
|
+
|
|
76
|
+
getIsolationScope().setTransactionName(`${method} ${routeName}`);
|
|
77
|
+
done();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_wrapHandler(
|
|
82
|
+
pluginName,
|
|
83
|
+
hookName,
|
|
84
|
+
original,
|
|
85
|
+
syncFunctionWithDone,
|
|
86
|
+
) {
|
|
87
|
+
const instrumentation = this;
|
|
88
|
+
this._diag.debug('Patching fastify route.handler function');
|
|
89
|
+
|
|
90
|
+
return function ( ...args) {
|
|
91
|
+
if (!instrumentation.isEnabled()) {
|
|
92
|
+
return original.apply(this, args);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const name = original.name || pluginName || ANONYMOUS_NAME;
|
|
96
|
+
const spanName = `${FastifyNames.MIDDLEWARE} - ${name}`;
|
|
97
|
+
|
|
98
|
+
const reply = args[1] ;
|
|
99
|
+
|
|
100
|
+
const span = startSpan(reply, instrumentation.tracer, spanName, {
|
|
101
|
+
[AttributeNames.FASTIFY_TYPE]: FastifyTypes.MIDDLEWARE,
|
|
102
|
+
[AttributeNames.PLUGIN_NAME]: pluginName,
|
|
103
|
+
[AttributeNames.HOOK_NAME]: hookName,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const origDone = syncFunctionWithDone && (args[args.length - 1] );
|
|
107
|
+
if (origDone) {
|
|
108
|
+
args[args.length - 1] = function (...doneArgs) {
|
|
109
|
+
endSpan(reply);
|
|
110
|
+
origDone.apply(this, doneArgs);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return context.with(trace.setSpan(context.active(), span), () => {
|
|
115
|
+
return safeExecuteInTheMiddleMaybePromise(
|
|
116
|
+
() => {
|
|
117
|
+
return original.apply(this, args);
|
|
118
|
+
},
|
|
119
|
+
err => {
|
|
120
|
+
if (err instanceof Error) {
|
|
121
|
+
span.setStatus({
|
|
122
|
+
code: SpanStatusCode.ERROR,
|
|
123
|
+
message: err.message,
|
|
124
|
+
});
|
|
125
|
+
span.recordException(err);
|
|
126
|
+
}
|
|
127
|
+
// async hooks should end the span as soon as the promise is resolved
|
|
128
|
+
if (!syncFunctionWithDone) {
|
|
129
|
+
endSpan(reply);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_wrapAddHook() {
|
|
138
|
+
const instrumentation = this;
|
|
139
|
+
this._diag.debug('Patching fastify server.addHook function');
|
|
140
|
+
|
|
141
|
+
// biome-ignore lint/complexity/useArrowFunction: <explanation>
|
|
142
|
+
return function (original) {
|
|
143
|
+
return function wrappedAddHook( ...args) {
|
|
144
|
+
const name = args[0] ;
|
|
145
|
+
const handler = args[1] ;
|
|
146
|
+
const pluginName = this.pluginName;
|
|
147
|
+
if (!hooksNamesToWrap.has(name)) {
|
|
148
|
+
return original.apply(this, args);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const syncFunctionWithDone =
|
|
152
|
+
typeof args[args.length - 1] === 'function' && handler.constructor.name !== 'AsyncFunction';
|
|
153
|
+
|
|
154
|
+
return original.apply(this, [
|
|
155
|
+
name,
|
|
156
|
+
instrumentation._wrapHandler(pluginName, name, handler, syncFunctionWithDone),
|
|
157
|
+
] );
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_patchConstructor(moduleExports
|
|
163
|
+
|
|
164
|
+
) {
|
|
165
|
+
const instrumentation = this;
|
|
166
|
+
|
|
167
|
+
function fastify( ...args) {
|
|
168
|
+
const app = moduleExports.fastify.apply(this, args);
|
|
169
|
+
app.addHook('onRequest', instrumentation._hookOnRequest());
|
|
170
|
+
app.addHook('preHandler', instrumentation._hookPreHandler());
|
|
171
|
+
|
|
172
|
+
instrumentClient();
|
|
173
|
+
|
|
174
|
+
instrumentation._wrap(app, 'addHook', instrumentation._wrapAddHook());
|
|
175
|
+
|
|
176
|
+
return app;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (moduleExports.errorCodes !== undefined) {
|
|
180
|
+
fastify.errorCodes = moduleExports.errorCodes;
|
|
181
|
+
}
|
|
182
|
+
fastify.fastify = fastify;
|
|
183
|
+
fastify.default = fastify;
|
|
184
|
+
return fastify;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_patchSend() {
|
|
188
|
+
const instrumentation = this;
|
|
189
|
+
this._diag.debug('Patching fastify reply.send function');
|
|
190
|
+
|
|
191
|
+
return function patchSend(original) {
|
|
192
|
+
return function send( ...args) {
|
|
193
|
+
const maybeError = args[0];
|
|
194
|
+
|
|
195
|
+
if (!instrumentation.isEnabled()) {
|
|
196
|
+
return original.apply(this, args);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return safeExecuteInTheMiddle(
|
|
200
|
+
() => {
|
|
201
|
+
return original.apply(this, args);
|
|
202
|
+
},
|
|
203
|
+
err => {
|
|
204
|
+
if (!err && maybeError instanceof Error) {
|
|
205
|
+
// eslint-disable-next-line no-param-reassign
|
|
206
|
+
err = maybeError;
|
|
207
|
+
}
|
|
208
|
+
endSpan(this, err);
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_hookPreHandler() {
|
|
216
|
+
const instrumentation = this;
|
|
217
|
+
this._diag.debug('Patching fastify preHandler function');
|
|
218
|
+
|
|
219
|
+
return function preHandler( request, reply, done) {
|
|
220
|
+
if (!instrumentation.isEnabled()) {
|
|
221
|
+
return done();
|
|
222
|
+
}
|
|
223
|
+
const anyRequest = request ;
|
|
224
|
+
|
|
225
|
+
const handler = anyRequest.routeOptions?.handler || anyRequest.context?.handler;
|
|
226
|
+
const handlerName = handler?.name.startsWith('bound ') ? handler.name.substring(6) : handler?.name;
|
|
227
|
+
const spanName = `${FastifyNames.REQUEST_HANDLER} - ${handlerName || this.pluginName || ANONYMOUS_NAME}`;
|
|
228
|
+
|
|
229
|
+
const spanAttributes = {
|
|
230
|
+
[AttributeNames.PLUGIN_NAME]: this.pluginName,
|
|
231
|
+
[AttributeNames.FASTIFY_TYPE]: FastifyTypes.REQUEST_HANDLER,
|
|
232
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
233
|
+
[SEMATTRS_HTTP_ROUTE]: anyRequest.routeOptions
|
|
234
|
+
? anyRequest.routeOptions.url // since fastify@4.10.0
|
|
235
|
+
: request.routerPath,
|
|
236
|
+
};
|
|
237
|
+
if (handlerName) {
|
|
238
|
+
spanAttributes[AttributeNames.FASTIFY_NAME] = handlerName;
|
|
239
|
+
}
|
|
240
|
+
const span = startSpan(reply, instrumentation.tracer, spanName, spanAttributes);
|
|
241
|
+
|
|
242
|
+
addFastifyV3SpanAttributes(span);
|
|
243
|
+
|
|
244
|
+
const { requestHook } = instrumentation.getConfig();
|
|
245
|
+
if (requestHook) {
|
|
246
|
+
safeExecuteInTheMiddle(
|
|
247
|
+
() => requestHook(span, { request }),
|
|
248
|
+
e => {
|
|
249
|
+
if (e) {
|
|
250
|
+
instrumentation._diag.error('request hook failed', e);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
true,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return context.with(trace.setSpan(context.active(), span), () => {
|
|
258
|
+
done();
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function instrumentClient() {
|
|
265
|
+
const client = getClient();
|
|
266
|
+
if (client) {
|
|
267
|
+
client.on('spanStart', (span) => {
|
|
268
|
+
addFastifyV3SpanAttributes(span);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function addFastifyV3SpanAttributes(span) {
|
|
274
|
+
const attributes = spanToJSON(span).data;
|
|
275
|
+
|
|
276
|
+
// this is one of: middleware, request_handler
|
|
277
|
+
const type = attributes['fastify.type'];
|
|
278
|
+
|
|
279
|
+
// If this is already set, or we have no fastify span, no need to process again...
|
|
280
|
+
if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
span.setAttributes({
|
|
285
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',
|
|
286
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.fastify`,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Also update the name, we don't need to "middleware - " prefix
|
|
290
|
+
const name = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];
|
|
291
|
+
if (typeof name === 'string') {
|
|
292
|
+
// Try removing `fastify -> ` and `@fastify/otel -> ` prefixes
|
|
293
|
+
// This is a bit of a hack, and not always working for all spans
|
|
294
|
+
// But it's the best we can do without a proper API
|
|
295
|
+
const updatedName = name.replace(/^fastify -> /, '').replace(/^@fastify\/otel -> /, '');
|
|
296
|
+
|
|
297
|
+
span.updateName(updatedName);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export { FastifyInstrumentationV3 };
|
|
302
|
+
//# sourceMappingURL=instrumentation.js.map
|