@sentry/node 10.63.0 → 10.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +15 -14
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/http.js +4 -7
- package/build/cjs/integrations/http.js.map +1 -1
- package/build/cjs/integrations/node-fetch.js +24 -0
- package/build/cjs/integrations/node-fetch.js.map +1 -0
- package/build/cjs/integrations/tracing/amqplib/vendored/semconv.js +0 -6
- package/build/cjs/integrations/tracing/amqplib/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/amqplib/vendored/utils.js +11 -10
- package/build/cjs/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/connect/vendored/instrumentation.js +2 -2
- package/build/cjs/integrations/tracing/connect/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +2 -2
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +9 -9
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
- package/build/cjs/integrations/tracing/graphql/index.js +3 -2
- package/build/cjs/integrations/tracing/graphql/index.js.map +1 -1
- package/build/cjs/integrations/tracing/graphql/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/graphql/vendored/utils.js +1 -4
- package/build/cjs/integrations/tracing/graphql/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/hapi/vendored/utils.js +8 -9
- package/build/cjs/integrations/tracing/hapi/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/hono/index.js +7 -7
- package/build/cjs/integrations/tracing/hono/index.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka/vendored/instrumentation.js +2 -1
- package/build/cjs/integrations/tracing/kafka/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/kafka/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/kafka/vendored/utils.js +12 -11
- package/build/cjs/integrations/tracing/kafka/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js +11 -10
- package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/knex/vendored/semconv.js +0 -16
- package/build/cjs/integrations/tracing/knex/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/koa/vendored/instrumentation.js +2 -2
- package/build/cjs/integrations/tracing/koa/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/koa/vendored/utils.js +2 -2
- package/build/cjs/integrations/tracing/koa/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/mongo/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo/vendored/utils.js +13 -12
- package/build/cjs/integrations/tracing/mongo/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/index.js +3 -2
- package/build/cjs/integrations/tracing/mongoose/index.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js +11 -8
- package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/mongoose/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/mongoose/vendored/utils.js +9 -9
- package/build/cjs/integrations/tracing/mongoose/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql/vendored/instrumentation.js +9 -8
- package/build/cjs/integrations/tracing/mysql/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/mysql/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2/index.js +3 -2
- package/build/cjs/integrations/tracing/mysql2/index.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js +8 -5
- package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/mysql2/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2/vendored/utils.js +7 -4
- package/build/cjs/integrations/tracing/mysql2/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/postgres/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/postgres/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/postgres/vendored/utils.js +12 -11
- package/build/cjs/integrations/tracing/postgres/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/postgresjs.js +8 -7
- package/build/cjs/integrations/tracing/postgresjs.js.map +1 -1
- package/build/cjs/integrations/tracing/prisma/index.js +48 -53
- package/build/cjs/integrations/tracing/prisma/index.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/cache.js +41 -0
- package/build/cjs/integrations/tracing/redis/cache.js.map +1 -0
- package/build/cjs/integrations/tracing/redis/index.js +15 -42
- package/build/cjs/integrations/tracing/redis/index.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js +22 -13
- package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js +21 -15
- package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/semconv.js +0 -8
- package/build/cjs/integrations/tracing/redis/vendored/semconv.js.map +1 -1
- package/build/cjs/integrations/tracing/tedious/vendored/instrumentation.js +9 -8
- package/build/cjs/integrations/tracing/tedious/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/tedious/vendored/semconv.js +0 -12
- package/build/cjs/integrations/tracing/tedious/vendored/semconv.js.map +1 -1
- package/build/cjs/sdk/experimentalUseDiagnosticsChannelInjection.js +14 -2
- package/build/cjs/sdk/experimentalUseDiagnosticsChannelInjection.js.map +1 -1
- package/build/cjs/sdk/index.js +2 -2
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +36 -0
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/esm/index.js +2 -2
- package/build/esm/integrations/http.js +5 -8
- package/build/esm/integrations/http.js.map +1 -1
- package/build/esm/integrations/node-fetch.js +22 -0
- package/build/esm/integrations/node-fetch.js.map +1 -0
- package/build/esm/integrations/tracing/amqplib/vendored/semconv.js +1 -4
- package/build/esm/integrations/tracing/amqplib/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/amqplib/vendored/utils.js +7 -6
- package/build/esm/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/connect/vendored/instrumentation.js +2 -2
- package/build/esm/integrations/tracing/connect/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +2 -2
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +7 -7
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
- package/build/esm/integrations/tracing/graphql/index.js +4 -3
- package/build/esm/integrations/tracing/graphql/index.js.map +1 -1
- package/build/esm/integrations/tracing/graphql/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/graphql/vendored/utils.js +1 -4
- package/build/esm/integrations/tracing/graphql/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/hapi/vendored/utils.js +3 -4
- package/build/esm/integrations/tracing/hapi/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/hono/index.js +3 -3
- package/build/esm/integrations/tracing/hono/index.js.map +1 -1
- package/build/esm/integrations/tracing/kafka/vendored/instrumentation.js +3 -2
- package/build/esm/integrations/tracing/kafka/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/kafka/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/kafka/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/kafka/vendored/utils.js +11 -10
- package/build/esm/integrations/tracing/kafka/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/knex/vendored/instrumentation.js +10 -9
- package/build/esm/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/knex/vendored/semconv.js +1 -9
- package/build/esm/integrations/tracing/knex/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/koa/vendored/instrumentation.js +2 -2
- package/build/esm/integrations/tracing/koa/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/koa/vendored/utils.js +2 -2
- package/build/esm/integrations/tracing/koa/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/mongo/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/mongo/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/mongo/vendored/utils.js +11 -10
- package/build/esm/integrations/tracing/mongo/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/index.js +4 -3
- package/build/esm/integrations/tracing/mongoose/index.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js +9 -6
- package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/mongoose/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/mongoose/vendored/utils.js +10 -10
- package/build/esm/integrations/tracing/mongoose/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/mysql/vendored/instrumentation.js +8 -7
- package/build/esm/integrations/tracing/mysql/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/mysql/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/mysql/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2/index.js +4 -3
- package/build/esm/integrations/tracing/mysql2/index.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js +7 -4
- package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/mysql2/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2/vendored/utils.js +8 -5
- package/build/esm/integrations/tracing/mysql2/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/postgres/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/postgres/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/postgres/vendored/utils.js +13 -12
- package/build/esm/integrations/tracing/postgres/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/postgresjs.js +7 -6
- package/build/esm/integrations/tracing/postgresjs.js.map +1 -1
- package/build/esm/integrations/tracing/prisma/index.js +49 -54
- package/build/esm/integrations/tracing/prisma/index.js.map +1 -1
- package/build/esm/integrations/tracing/redis/cache.js +38 -0
- package/build/esm/integrations/tracing/redis/cache.js.map +1 -0
- package/build/esm/integrations/tracing/redis/index.js +12 -42
- package/build/esm/integrations/tracing/redis/index.js.map +1 -1
- package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js +19 -10
- package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js +16 -10
- package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/redis/vendored/semconv.js +1 -5
- package/build/esm/integrations/tracing/redis/vendored/semconv.js.map +1 -1
- package/build/esm/integrations/tracing/tedious/vendored/instrumentation.js +8 -7
- package/build/esm/integrations/tracing/tedious/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/tedious/vendored/semconv.js +1 -7
- package/build/esm/integrations/tracing/tedious/vendored/semconv.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/sdk/experimentalUseDiagnosticsChannelInjection.js +15 -4
- package/build/esm/sdk/experimentalUseDiagnosticsChannelInjection.js.map +1 -1
- package/build/esm/sdk/index.js +1 -1
- package/build/esm/sdk/initOtel.js +38 -2
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/http.d.ts +2 -2
- package/build/types/integrations/http.d.ts.map +1 -1
- package/build/types/integrations/node-fetch.d.ts +9 -0
- package/build/types/integrations/node-fetch.d.ts.map +1 -0
- package/build/types/integrations/tracing/amqplib/vendored/semconv.d.ts +0 -6
- package/build/types/integrations/tracing/amqplib/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/amqplib/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/graphql/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/graphql/vendored/graphql-types.d.ts +1 -135
- package/build/types/integrations/tracing/graphql/vendored/graphql-types.d.ts.map +1 -1
- package/build/types/integrations/tracing/graphql/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/hapi/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/kafka/vendored/semconv.d.ts +5 -63
- package/build/types/integrations/tracing/kafka/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/kafka/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/knex/vendored/semconv.d.ts +0 -32
- package/build/types/integrations/tracing/knex/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo/vendored/semconv.d.ts +1 -37
- package/build/types/integrations/tracing/mongo/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/vendored/mongoose.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/vendored/semconv.d.ts +0 -48
- package/build/types/integrations/tracing/mongoose/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongoose/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql/vendored/semconv.d.ts +1 -62
- package/build/types/integrations/tracing/mysql/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2/vendored/semconv.d.ts +0 -6
- package/build/types/integrations/tracing/mysql2/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgres/vendored/semconv.d.ts +1 -50
- package/build/types/integrations/tracing/postgres/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgres/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -1
- package/build/types/integrations/tracing/prisma/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/cache.d.ts +22 -0
- package/build/types/integrations/tracing/redis/cache.d.ts.map +1 -0
- package/build/types/integrations/tracing/redis/index.d.ts +2 -20
- package/build/types/integrations/tracing/redis/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/vendored/ioredis-instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/vendored/redis-instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/vendored/semconv.d.ts +0 -4
- package/build/types/integrations/tracing/redis/vendored/semconv.d.ts.map +1 -1
- package/build/types/integrations/tracing/tedious/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/tedious/vendored/semconv.d.ts +1 -62
- package/build/types/integrations/tracing/tedious/vendored/semconv.d.ts.map +1 -1
- package/build/types/sdk/experimentalUseDiagnosticsChannelInjection.d.ts +2 -0
- package/build/types/sdk/experimentalUseDiagnosticsChannelInjection.d.ts.map +1 -1
- package/build/types/sdk/initOtel.d.ts +2 -3
- package/build/types/sdk/initOtel.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +1 -1
- package/build/types-ts3.8/integrations/http.d.ts +2 -2
- package/build/types-ts3.8/integrations/node-fetch.d.ts +9 -0
- package/build/types-ts3.8/integrations/tracing/amqplib/vendored/semconv.d.ts +0 -6
- package/build/types-ts3.8/integrations/tracing/graphql/vendored/graphql-types.d.ts +1 -135
- package/build/types-ts3.8/integrations/tracing/kafka/vendored/semconv.d.ts +5 -63
- package/build/types-ts3.8/integrations/tracing/knex/vendored/semconv.d.ts +0 -32
- package/build/types-ts3.8/integrations/tracing/mongo/vendored/semconv.d.ts +1 -37
- package/build/types-ts3.8/integrations/tracing/mongoose/vendored/semconv.d.ts +0 -48
- package/build/types-ts3.8/integrations/tracing/mysql/vendored/semconv.d.ts +1 -62
- package/build/types-ts3.8/integrations/tracing/mysql2/vendored/semconv.d.ts +0 -6
- package/build/types-ts3.8/integrations/tracing/postgres/vendored/semconv.d.ts +1 -50
- package/build/types-ts3.8/integrations/tracing/redis/cache.d.ts +22 -0
- package/build/types-ts3.8/integrations/tracing/redis/index.d.ts +2 -20
- package/build/types-ts3.8/integrations/tracing/redis/vendored/semconv.d.ts +0 -4
- package/build/types-ts3.8/integrations/tracing/tedious/vendored/semconv.d.ts +1 -62
- package/build/types-ts3.8/sdk/experimentalUseDiagnosticsChannelInjection.d.ts +2 -0
- package/build/types-ts3.8/sdk/initOtel.d.ts +3 -4
- package/package.json +8 -9
- package/build/cjs/integrations/node-fetch/index.js +0 -38
- package/build/cjs/integrations/node-fetch/index.js.map +0 -1
- package/build/cjs/integrations/node-fetch/undici-instrumentation.js +0 -266
- package/build/cjs/integrations/node-fetch/undici-instrumentation.js.map +0 -1
- package/build/cjs/integrations/tracing/hapi/vendored/semconv.js +0 -6
- package/build/cjs/integrations/tracing/hapi/vendored/semconv.js.map +0 -1
- package/build/cjs/integrations/tracing/redis/vendored/redis-common.js +0 -34
- package/build/cjs/integrations/tracing/redis/vendored/redis-common.js.map +0 -1
- package/build/esm/integrations/node-fetch/index.js +0 -36
- package/build/esm/integrations/node-fetch/index.js.map +0 -1
- package/build/esm/integrations/node-fetch/undici-instrumentation.js +0 -264
- package/build/esm/integrations/node-fetch/undici-instrumentation.js.map +0 -1
- package/build/esm/integrations/tracing/hapi/vendored/semconv.js +0 -4
- package/build/esm/integrations/tracing/hapi/vendored/semconv.js.map +0 -1
- package/build/esm/integrations/tracing/redis/vendored/redis-common.js +0 -32
- package/build/esm/integrations/tracing/redis/vendored/redis-common.js.map +0 -1
- package/build/types/integrations/node-fetch/index.d.ts +0 -5
- package/build/types/integrations/node-fetch/index.d.ts.map +0 -1
- package/build/types/integrations/node-fetch/types.d.ts +0 -96
- package/build/types/integrations/node-fetch/types.d.ts.map +0 -1
- package/build/types/integrations/node-fetch/undici-instrumentation.d.ts +0 -14
- package/build/types/integrations/node-fetch/undici-instrumentation.d.ts.map +0 -1
- package/build/types/integrations/tracing/hapi/vendored/semconv.d.ts +0 -13
- package/build/types/integrations/tracing/hapi/vendored/semconv.d.ts.map +0 -1
- package/build/types/integrations/tracing/redis/vendored/redis-common.d.ts +0 -6
- package/build/types/integrations/tracing/redis/vendored/redis-common.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/node-fetch/index.d.ts +0 -5
- package/build/types-ts3.8/integrations/node-fetch/types.d.ts +0 -96
- package/build/types-ts3.8/integrations/node-fetch/undici-instrumentation.d.ts +0 -14
- package/build/types-ts3.8/integrations/tracing/hapi/vendored/semconv.d.ts +0 -13
- package/build/types-ts3.8/integrations/tracing/redis/vendored/redis-common.d.ts +0 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TraceFlags } from '@opentelemetry/api';
|
|
2
|
+
import { MESSAGING_OPERATION_NAME, MESSAGING_OPERATION_TYPE, MESSAGING_DESTINATION_NAME, MESSAGING_SYSTEM, ERROR_TYPE } from '@sentry/conventions/attributes';
|
|
2
3
|
import { startInactiveSpan, SPAN_KIND, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR, propagationContextFromHeaders, getTraceData } from '@sentry/core';
|
|
3
|
-
import { MESSAGING_SYSTEM_VALUE_KAFKA, ATTR_MESSAGING_KAFKA_OFFSET, ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE, ATTR_MESSAGING_KAFKA_MESSAGE_KEY,
|
|
4
|
+
import { MESSAGING_SYSTEM_VALUE_KAFKA, ATTR_MESSAGING_KAFKA_OFFSET, ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE, ATTR_MESSAGING_KAFKA_MESSAGE_KEY, MESSAGING_OPERATION_TYPE_VALUE_RECEIVE, ERROR_TYPE_VALUE_OTHER, MESSAGING_OPERATION_TYPE_VALUE_SEND, ATTR_MESSAGING_DESTINATION_PARTITION_ID } from './semconv.js';
|
|
4
5
|
|
|
5
6
|
const PRODUCER_ORIGIN = "auto.kafkajs.otel.producer";
|
|
6
7
|
const CONSUMER_ORIGIN = "auto.kafkajs.otel.consumer";
|
|
@@ -42,10 +43,10 @@ function startConsumerSpan({ topic, message, operationType, links, attributes })
|
|
|
42
43
|
links,
|
|
43
44
|
attributes: {
|
|
44
45
|
...attributes,
|
|
45
|
-
[
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[
|
|
46
|
+
[MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
|
|
47
|
+
[MESSAGING_DESTINATION_NAME]: topic,
|
|
48
|
+
[MESSAGING_OPERATION_TYPE]: operationType,
|
|
49
|
+
[MESSAGING_OPERATION_NAME]: operationName,
|
|
49
50
|
[ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key ? String(message.key) : void 0,
|
|
50
51
|
[ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : void 0,
|
|
51
52
|
[ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,
|
|
@@ -60,13 +61,13 @@ function startProducerSpan(topic, message) {
|
|
|
60
61
|
name: `send ${topic}`,
|
|
61
62
|
kind: SPAN_KIND.PRODUCER,
|
|
62
63
|
attributes: {
|
|
63
|
-
[
|
|
64
|
-
[
|
|
64
|
+
[MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
|
|
65
|
+
[MESSAGING_DESTINATION_NAME]: topic,
|
|
65
66
|
[ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key ? String(message.key) : void 0,
|
|
66
67
|
[ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : void 0,
|
|
67
68
|
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: message.partition !== void 0 ? String(message.partition) : void 0,
|
|
68
|
-
[
|
|
69
|
-
[
|
|
69
|
+
[MESSAGING_OPERATION_NAME]: "send",
|
|
70
|
+
[MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,
|
|
70
71
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRODUCER_ORIGIN
|
|
71
72
|
}
|
|
72
73
|
});
|
|
@@ -91,7 +92,7 @@ function endSpansOnPromise(spans, sendPromise) {
|
|
|
91
92
|
errorType = reason.constructor.name;
|
|
92
93
|
}
|
|
93
94
|
spans.forEach((span) => {
|
|
94
|
-
span.setAttribute(
|
|
95
|
+
span.setAttribute(ERROR_TYPE, errorType);
|
|
95
96
|
span.setStatus({
|
|
96
97
|
code: SPAN_STATUS_ERROR,
|
|
97
98
|
message: errorMessage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/kafka/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-kafkajs\n * - Upstream version: @opentelemetry/instrumentation-kafkajs@0.27.0\n * - Span creation extracted here and migrated to the @sentry/core API; origin folded into span creation\n */\n\nimport { TraceFlags } from '@opentelemetry/api';\nimport type { Span, SpanAttributes, SpanLink } from '@sentry/core';\nimport {\n getTraceData,\n propagationContextFromHeaders,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { KafkaMessage, Message } from './kafkajs-types';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_MESSAGING_DESTINATION_NAME,\n ATTR_MESSAGING_DESTINATION_PARTITION_ID,\n ATTR_MESSAGING_KAFKA_MESSAGE_KEY,\n ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE,\n ATTR_MESSAGING_KAFKA_OFFSET,\n ATTR_MESSAGING_OPERATION_NAME,\n ATTR_MESSAGING_OPERATION_TYPE,\n ATTR_MESSAGING_SYSTEM,\n ERROR_TYPE_VALUE_OTHER,\n MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n MESSAGING_OPERATION_TYPE_VALUE_SEND,\n MESSAGING_SYSTEM_VALUE_KAFKA,\n} from './semconv';\n\nconst PRODUCER_ORIGIN = 'auto.kafkajs.otel.producer';\nconst CONSUMER_ORIGIN = 'auto.kafkajs.otel.consumer';\n\nexport interface ConsumerSpanOptions {\n topic: string;\n message: KafkaMessage | undefined;\n operationType: string;\n attributes: SpanAttributes;\n links?: SpanLink[];\n}\n\n/**\n * Reads a header value off a kafkajs message as a string. kafkajs delivers headers as `Buffer`s (or\n * arrays of them), so we normalize to a string before handing them to Sentry's trace helpers.\n */\nexport function getHeaderAsString(headers: KafkaMessage['headers'], key: string): string | undefined {\n const value = headers?.[key];\n if (value == null) {\n return undefined;\n }\n return Array.isArray(value) ? value[0]?.toString() : value.toString();\n}\n\n/**\n * Builds a span link to the producer span carried in the message headers, mirroring the upstream\n * behavior of linking each batch-processed message to its originating producer span.\n */\nexport function getLinksFromHeaders(headers: KafkaMessage['headers']): SpanLink[] | undefined {\n const sentryTrace = getHeaderAsString(headers, 'sentry-trace');\n if (!sentryTrace) {\n return undefined;\n }\n\n const { traceId, parentSpanId, sampled } = propagationContextFromHeaders(\n sentryTrace,\n getHeaderAsString(headers, 'baggage'),\n );\n if (!parentSpanId) {\n return undefined;\n }\n\n return [\n {\n context: {\n traceId,\n spanId: parentSpanId,\n isRemote: true,\n traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,\n },\n },\n ];\n}\n\n/** Starts an inactive consumer (process/receive) span carrying the kafkajs messaging attributes. */\nexport function startConsumerSpan({ topic, message, operationType, links, attributes }: ConsumerSpanOptions): Span {\n const operationName =\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? 'poll' // for batch processing spans\n : operationType; // for individual message processing spans\n\n return startInactiveSpan({\n name: `${operationName} ${topic}`,\n kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SPAN_KIND.CLIENT : SPAN_KIND.CONSUMER,\n links,\n attributes: {\n ...attributes,\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_OPERATION_TYPE]: operationType,\n [ATTR_MESSAGING_OPERATION_NAME]: operationName,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,\n // Mirror the upstream behavior of only tagging per-message processing spans (not the batch\n // receiving span, which carries no message) with the auto origin.\n ...(message ? { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: CONSUMER_ORIGIN } : {}),\n },\n });\n}\n\n/** Starts an inactive producer span and propagates its trace into the message headers. */\nexport function startProducerSpan(topic: string, message: Message): Span {\n const span = startInactiveSpan({\n name: `send ${topic}`,\n kind: SPAN_KIND.PRODUCER,\n attributes: {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]:\n message.partition !== undefined ? String(message.partition) : undefined,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRODUCER_ORIGIN,\n },\n });\n\n // Propagate the producer span's trace to consumers via the message headers.\n message.headers = message.headers ?? {};\n const traceData = getTraceData({ span });\n if (traceData['sentry-trace']) {\n message.headers['sentry-trace'] = traceData['sentry-trace'];\n }\n if (traceData.baggage) {\n message.headers['baggage'] = traceData.baggage;\n }\n\n return span;\n}\n\n/**\n * Resolves once `sendPromise` settles, ending all `spans` and, on failure, marking them with the\n * error status and `error.type` before re-throwing.\n */\nexport function endSpansOnPromise<T>(spans: Span[], sendPromise: Promise<T>): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string | undefined;\n let errorType: string = ERROR_TYPE_VALUE_OTHER;\n if (typeof reason === 'string' || reason === undefined) {\n errorMessage = reason;\n } else if (typeof reason === 'object' && Object.prototype.hasOwnProperty.call(reason, 'message')) {\n errorMessage = reason.message;\n errorType = reason.constructor.name;\n }\n\n spans.forEach(span => {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: errorMessage,\n });\n });\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n}\n"],"names":[],"mappings":";;;;AAqCA,MAAM,eAAA,GAAkB,4BAAA;AACxB,MAAM,eAAA,GAAkB,4BAAA;AAcjB,SAAS,iBAAA,CAAkB,SAAkC,GAAA,EAAiC;AACnG,EAAA,MAAM,KAAA,GAAQ,UAAU,GAAG,CAAA;AAC3B,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,KAAA,CAAM,CAAC,CAAA,EAAG,QAAA,EAAS,GAAI,KAAA,CAAM,QAAA,EAAS;AACtE;AAMO,SAAS,oBAAoB,OAAA,EAA0D;AAC5F,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,cAAc,CAAA;AAC7D,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,OAAA,EAAS,YAAA,EAAc,OAAA,EAAQ,GAAI,6BAAA;AAAA,IACzC,WAAA;AAAA,IACA,iBAAA,CAAkB,SAAS,SAAS;AAAA,GACtC;AACA,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAO;AAAA,IACL;AAAA,MACE,OAAA,EAAS;AAAA,QACP,OAAA;AAAA,QACA,MAAA,EAAQ,YAAA;AAAA,QACR,QAAA,EAAU,IAAA;AAAA,QACV,UAAA,EAAY,OAAA,GAAU,UAAA,CAAW,OAAA,GAAU,UAAA,CAAW;AAAA;AACxD;AACF,GACF;AACF;AAGO,SAAS,kBAAkB,EAAE,KAAA,EAAO,SAAS,aAAA,EAAe,KAAA,EAAO,YAAW,EAA8B;AACjH,EAAA,MAAM,aAAA,GACJ,aAAA,KAAkB,sCAAA,GACd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AAAA,IACjC;AAEA,IAAA,KAAA,CAAM,QAAQ,CAAA,IAAA,KAAQ;AACpB,MAAA,IAAA,CAAK,YAAA,CAAa,iBAAiB,SAAS,CAAA;AAC5C,MAAA,IAAA,CAAK,SAAA,CAAU;AAAA,QACb,IAAA,EAAM,iBAAA;AAAA,QACN,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,MAAM,MAAA;AAAA,EACR,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,IAAA,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAA,KAAQ,IAAA,CAAK,GAAA,EAAK,CAAA;AAAA,EAClC,CAAC,CAAA;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/kafka/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-kafkajs\n * - Upstream version: @opentelemetry/instrumentation-kafkajs@0.27.0\n * - Span creation extracted here and migrated to the @sentry/core API; origin folded into span creation\n */\n\nimport { TraceFlags } from '@opentelemetry/api';\nimport {\n ERROR_TYPE,\n MESSAGING_DESTINATION_NAME,\n MESSAGING_OPERATION_NAME,\n MESSAGING_OPERATION_TYPE,\n MESSAGING_SYSTEM,\n} from '@sentry/conventions/attributes';\nimport type { Span, SpanAttributes, SpanLink } from '@sentry/core';\nimport {\n getTraceData,\n propagationContextFromHeaders,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { KafkaMessage, Message } from './kafkajs-types';\nimport {\n ATTR_MESSAGING_DESTINATION_PARTITION_ID,\n ATTR_MESSAGING_KAFKA_MESSAGE_KEY,\n ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE,\n ATTR_MESSAGING_KAFKA_OFFSET,\n ERROR_TYPE_VALUE_OTHER,\n MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n MESSAGING_OPERATION_TYPE_VALUE_SEND,\n MESSAGING_SYSTEM_VALUE_KAFKA,\n} from './semconv';\n\nconst PRODUCER_ORIGIN = 'auto.kafkajs.otel.producer';\nconst CONSUMER_ORIGIN = 'auto.kafkajs.otel.consumer';\n\nexport interface ConsumerSpanOptions {\n topic: string;\n message: KafkaMessage | undefined;\n operationType: string;\n attributes: SpanAttributes;\n links?: SpanLink[];\n}\n\n/**\n * Reads a header value off a kafkajs message as a string. kafkajs delivers headers as `Buffer`s (or\n * arrays of them), so we normalize to a string before handing them to Sentry's trace helpers.\n */\nexport function getHeaderAsString(headers: KafkaMessage['headers'], key: string): string | undefined {\n const value = headers?.[key];\n if (value == null) {\n return undefined;\n }\n return Array.isArray(value) ? value[0]?.toString() : value.toString();\n}\n\n/**\n * Builds a span link to the producer span carried in the message headers, mirroring the upstream\n * behavior of linking each batch-processed message to its originating producer span.\n */\nexport function getLinksFromHeaders(headers: KafkaMessage['headers']): SpanLink[] | undefined {\n const sentryTrace = getHeaderAsString(headers, 'sentry-trace');\n if (!sentryTrace) {\n return undefined;\n }\n\n const { traceId, parentSpanId, sampled } = propagationContextFromHeaders(\n sentryTrace,\n getHeaderAsString(headers, 'baggage'),\n );\n if (!parentSpanId) {\n return undefined;\n }\n\n return [\n {\n context: {\n traceId,\n spanId: parentSpanId,\n isRemote: true,\n traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,\n },\n },\n ];\n}\n\n/** Starts an inactive consumer (process/receive) span carrying the kafkajs messaging attributes. */\nexport function startConsumerSpan({ topic, message, operationType, links, attributes }: ConsumerSpanOptions): Span {\n const operationName =\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? 'poll' // for batch processing spans\n : operationType; // for individual message processing spans\n\n return startInactiveSpan({\n name: `${operationName} ${topic}`,\n kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SPAN_KIND.CLIENT : SPAN_KIND.CONSUMER,\n links,\n attributes: {\n ...attributes,\n [MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [MESSAGING_DESTINATION_NAME]: topic,\n [MESSAGING_OPERATION_TYPE]: operationType,\n [MESSAGING_OPERATION_NAME]: operationName,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,\n // Mirror the upstream behavior of only tagging per-message processing spans (not the batch\n // receiving span, which carries no message) with the auto origin.\n ...(message ? { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: CONSUMER_ORIGIN } : {}),\n },\n });\n}\n\n/** Starts an inactive producer span and propagates its trace into the message headers. */\nexport function startProducerSpan(topic: string, message: Message): Span {\n const span = startInactiveSpan({\n name: `send ${topic}`,\n kind: SPAN_KIND.PRODUCER,\n attributes: {\n [MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]:\n message.partition !== undefined ? String(message.partition) : undefined,\n [MESSAGING_OPERATION_NAME]: 'send',\n [MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRODUCER_ORIGIN,\n },\n });\n\n // Propagate the producer span's trace to consumers via the message headers.\n message.headers = message.headers ?? {};\n const traceData = getTraceData({ span });\n if (traceData['sentry-trace']) {\n message.headers['sentry-trace'] = traceData['sentry-trace'];\n }\n if (traceData.baggage) {\n message.headers['baggage'] = traceData.baggage;\n }\n\n return span;\n}\n\n/**\n * Resolves once `sendPromise` settles, ending all `spans` and, on failure, marking them with the\n * error status and `error.type` before re-throwing.\n */\nexport function endSpansOnPromise<T>(spans: Span[], sendPromise: Promise<T>): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string | undefined;\n let errorType: string = ERROR_TYPE_VALUE_OTHER;\n if (typeof reason === 'string' || reason === undefined) {\n errorMessage = reason;\n } else if (typeof reason === 'object' && Object.prototype.hasOwnProperty.call(reason, 'message')) {\n errorMessage = reason.message;\n errorType = reason.constructor.name;\n }\n\n spans.forEach(span => {\n span.setAttribute(ERROR_TYPE, errorType);\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: errorMessage,\n });\n });\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n}\n"],"names":[],"mappings":";;;;;AAuCA,MAAM,eAAA,GAAkB,4BAAA;AACxB,MAAM,eAAA,GAAkB,4BAAA;AAcjB,SAAS,iBAAA,CAAkB,SAAkC,GAAA,EAAiC;AACnG,EAAA,MAAM,KAAA,GAAQ,UAAU,GAAG,CAAA;AAC3B,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,KAAA,CAAM,CAAC,CAAA,EAAG,QAAA,EAAS,GAAI,KAAA,CAAM,QAAA,EAAS;AACtE;AAMO,SAAS,oBAAoB,OAAA,EAA0D;AAC5F,EAAA,MAAM,WAAA,GAAc,iBAAA,CAAkB,OAAA,EAAS,cAAc,CAAA;AAC7D,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,OAAA,EAAS,YAAA,E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AAO,IAAA;AACT;AAMO,SAAS,iBAAA,CAAqB,OAAe,WAAA,EAAqC;AACvF,EAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,WAAW,CAAA,CAC/B,MAAM,CAAA,MAAA,KAAU;AACf,IAAA,IAAI,YAAA;AACJ,IAAA,IAAI,SAAA,GAAoB,sBAAA;AACxB,IAAA,IAAI,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,KAAW,MAAA,EAAW;AACtD,MAAA,YAAA,GAAe,MAAA;AAAA,IACjB,CAAA,MAAA,IAAW,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,CAAO,UAAU,cAAA,CAAe,IAAA,CAAK,MAAA,EAAQ,SAAS,CAAA,EAAG;AAChG,MAAA,YAAA,GAAe,MAAA,CAAO,OAAA;AACtB,MAAA,SAAA,GAAY,OAAO,WAAA,CAAY,IAAA;AAAA,IACjC;AAEA,IAAA,KAAA,CAAM,QAAQ,CAAA,IAAA,KAAQ;AACpB,MAAA,IAAA,CAAK,YAAA,CAAa,YAAY,SAAS,CAAA;AACvC,MAAA,IAAA,CAAK,SAAA,CAAU;AAAA,QACb,IAAA,EAAM,iBAAA;AAAA,QACN,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,MAAM,MAAA;AAAA,EACR,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,IAAA,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAA,KAAQ,IAAA,CAAK,GAAA,EAAK,CAAA;AAAA,EAClC,CAAC,CAAA;AACL;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
|
|
2
2
|
import { SDK_VERSION, getActiveSpan, startSpan, SPAN_KIND, SPAN_STATUS_ERROR, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
3
|
+
import { DB_STATEMENT, NET_TRANSPORT, NET_PEER_PORT, NET_PEER_NAME, DB_USER, DB_SYSTEM, DB_NAME, DB_OPERATION } from '@sentry/conventions/attributes';
|
|
3
4
|
import { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile.js';
|
|
4
|
-
import {
|
|
5
|
+
import { ATTR_DB_SQL_TABLE } from './semconv.js';
|
|
5
6
|
import { extractTableName, extractDatabaseFromConnectionString, limitLength, extractPortFromConnectionString, extractHostFromConnectionString, mapSystem, getName, getFormatter } from './utils.js';
|
|
6
7
|
|
|
7
8
|
const PACKAGE_NAME = "@sentry/instrumentation-knex";
|
|
@@ -76,15 +77,15 @@ class KnexInstrumentation extends InstrumentationBase {
|
|
|
76
77
|
const attributes = {
|
|
77
78
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
78
79
|
"knex.version": moduleVersion,
|
|
79
|
-
[
|
|
80
|
+
[DB_SYSTEM]: mapSystem(this.client.driverName),
|
|
80
81
|
[ATTR_DB_SQL_TABLE]: table,
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
82
|
+
[DB_OPERATION]: operation,
|
|
83
|
+
[DB_USER]: config?.connection?.user,
|
|
84
|
+
[DB_NAME]: name,
|
|
85
|
+
[NET_PEER_NAME]: config?.connection?.host ?? extractHostFromConnectionString(connectionString),
|
|
86
|
+
[NET_PEER_PORT]: config?.connection?.port ?? extractPortFromConnectionString(connectionString),
|
|
87
|
+
[NET_TRANSPORT]: config?.connection?.filename === ":memory:" ? "inproc" : void 0,
|
|
88
|
+
[DB_STATEMENT]: limitLength(query?.sql, MAX_QUERY_LENGTH)
|
|
88
89
|
};
|
|
89
90
|
const parentSpan = this.builder[parentSpanSymbol] || getActiveSpan();
|
|
90
91
|
const args = arguments;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\n/* oxlint-disable typescript/no-deprecated */\n\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startSpan,\n} from '@sentry/core';\nimport { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';\nimport {\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_SQL_TABLE,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n ATTR_NET_TRANSPORT,\n} from './semconv';\nimport * as utils from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-knex';\nconst ORIGIN = 'auto.db.otel.knex';\n\nconst MODULE_NAME = 'knex';\nconst SUPPORTED_VERSIONS = [\n // use \"lib/execution\" for runner.js, \"lib\" for client.js as basepath, latest tested 0.95.6\n '>=0.22.0 <4',\n // use \"lib\" as basepath\n '>=0.10.0 <0.18.0',\n '>=0.19.0 <0.22.0',\n // use \"src\" as basepath\n '>=0.18.0 <0.19.0',\n];\n\n// Max length of the query text captured in the `db.statement` attribute; \"..\" is appended when truncated.\nconst MAX_QUERY_LENGTH = 1022;\n\nconst parentSpanSymbol = Symbol('sentry.instrumentation-knex.parent-span');\n\nexport class KnexInstrumentation extends InstrumentationBase<InstrumentationConfig> {\n public constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n public init(): InstrumentationNodeModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, SUPPORTED_VERSIONS);\n\n module.files.push(\n this._getClientNodeModuleFileInstrumentation('src'),\n this._getClientNodeModuleFileInstrumentation('lib'),\n this._getRunnerNodeModuleFileInstrumentation('src'),\n this._getRunnerNodeModuleFileInstrumentation('lib'),\n this._getRunnerNodeModuleFileInstrumentation('lib/execution'),\n );\n\n return module;\n }\n\n private _getRunnerNodeModuleFileInstrumentation(basePath: string): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/runner.js`,\n SUPPORTED_VERSIONS,\n (Runner: any, moduleVersion?: string) => {\n this._ensureWrapped(Runner.prototype, 'query', this._createQueryWrapper(moduleVersion));\n return Runner;\n },\n (Runner: any) => {\n this._unwrap(Runner.prototype, 'query');\n return Runner;\n },\n );\n }\n\n private _getClientNodeModuleFileInstrumentation(basePath: string): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/client.js`,\n SUPPORTED_VERSIONS,\n (Client: any) => {\n this._ensureWrapped(Client.prototype, 'queryBuilder', this._storeContext.bind(this));\n this._ensureWrapped(Client.prototype, 'schemaBuilder', this._storeContext.bind(this));\n this._ensureWrapped(Client.prototype, 'raw', this._storeContext.bind(this));\n return Client;\n },\n (Client: any) => {\n this._unwrap(Client.prototype, 'queryBuilder');\n this._unwrap(Client.prototype, 'schemaBuilder');\n this._unwrap(Client.prototype, 'raw');\n return Client;\n },\n );\n }\n\n private _createQueryWrapper(moduleVersion?: string) {\n return function wrapQuery(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any, query: any) {\n const config = this.client.config;\n\n const table = utils.extractTableName(this.builder);\n const operation = query?.method;\n const connectionString = config?.connection?.connectionString;\n const name =\n config?.connection?.filename ||\n config?.connection?.database ||\n utils.extractDatabaseFromConnectionString(connectionString);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n 'knex.version': moduleVersion,\n [ATTR_DB_SYSTEM]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_SQL_TABLE]: table,\n [ATTR_DB_OPERATION]: operation,\n [ATTR_DB_USER]: config?.connection?.user,\n [ATTR_DB_NAME]: name,\n [ATTR_NET_PEER_NAME]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [ATTR_NET_PEER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n [ATTR_NET_TRANSPORT]: config?.connection?.filename === ':memory:' ? 'inproc' : undefined,\n [ATTR_DB_STATEMENT]: utils.limitLength(query?.sql, MAX_QUERY_LENGTH),\n };\n\n // The query builder captures the span active when it was created (see `_storeContext`).\n // `onlyIfParent` ensures we only instrument queries that run as part of an existing trace.\n const parentSpan: Span | undefined = this.builder[parentSpanSymbol] || getActiveSpan();\n\n const args = arguments;\n return startSpan(\n {\n name: utils.getName(name, operation, table),\n kind: SPAN_KIND.CLIENT,\n attributes,\n parentSpan,\n onlyIfParent: true,\n },\n span =>\n // `Runner.query` returns a real, already-executing Promise, so it is safe to let\n // `startSpan` await it and auto-end the span.\n original.apply(this, args).catch((err: any) => {\n const formatter = utils.getFormatter(this);\n const fullQuery = formatter(query.sql, query.bindings || []);\n const message = err.message.replace(`${fullQuery} - `, '');\n span.setStatus({ code: SPAN_STATUS_ERROR, message });\n throw err;\n }),\n );\n };\n };\n }\n\n private _storeContext(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any) {\n const builder = original.apply(this, arguments);\n // Capture the span that is active when the query builder is created. The query often executes\n // in a different async context, so we reuse this span as the parent when the query runs.\n Object.defineProperty(builder, parentSpanSymbol, {\n value: getActiveSpan(),\n });\n return builder;\n };\n }\n\n private _ensureWrapped(obj: any, methodName: string, wrapper: (original: any) => any): void {\n if (isWrapped(obj[methodName])) {\n this._unwrap(obj, methodName);\n }\n this._wrap(obj, methodName, wrapper);\n }\n}\n"],"names":["utils.extractTableName","utils.extractDatabaseFromConnectionString","utils.mapSystem","utils.extractHostFromConnectionString","utils.extractPortFromConnectionString","utils.limitLength","utils.getName","utils.getFormatter"],"mappings":";;;;;;AAsCA,MAAM,YAAA,GAAe,8BAAA;AACrB,MAAM,MAAA,GAAS,mBAAA;AAEf,MAAM,WAAA,GAAc,MAAA;AACpB,MAAM,kBAAA,GAAqB;AAAA;AAAA,EAEzB,aAAA;AAAA;AAAA,EAEA,kBAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EAEA;AACF,CAAA;AAGA,MAAM,gBAAA,GAAmB,IAAA;AAEzB,MAAM,gBAAA,0BAA0B,yCAAyC,CAAA;AAElE,MAAM,4BAA4B,mBAAA,CAA2C;AAAA,EAC3E,WAAA,CAAY,MAAA,GAAgC,EAAC,EAAG;AACrD,IAAA,KAAA,CAAM,YAAA,EAAc,aAAa,MAAM,CAAA;AAAA,EACzC;AAAA,EAEO,IAAA,GAA4C;AACjD,IAAA,MAAM,MAAA,GAAS,IAAI,mCAAA,CAAoC,WAAA,EAAa,kBAAkB,CAAA;AAEtF,IAAA,MAAA,CAAO,KAAA,CAAM,IAAA;AAAA,MACX,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,eAAe;AAAA,KAC9D;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEQ,wCAAwC,QAAA,EAAiD;AAC/F,IAAA,OAAO,IAAI,6BAAA;AAAA,MACT,QAAQ,QAAQ,CAAA,UAAA,CAAA;AAAA,MA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AAA,IAAA,CAAK,OAAA,CAAQ,KAAK,UAAU,CAAA;AAAA,IAC9B;AACA,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,UAAA,EAAY,OAAO,CAAA;AAAA,EACrC;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\n/* oxlint-disable typescript/no-deprecated */\n\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startSpan,\n} from '@sentry/core';\nimport {\n DB_NAME,\n DB_OPERATION,\n DB_STATEMENT,\n DB_SYSTEM,\n DB_USER,\n NET_PEER_NAME,\n NET_PEER_PORT,\n NET_TRANSPORT,\n} from '@sentry/conventions/attributes';\nimport { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';\nimport { ATTR_DB_SQL_TABLE } from './semconv';\nimport * as utils from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-knex';\nconst ORIGIN = 'auto.db.otel.knex';\n\nconst MODULE_NAME = 'knex';\nconst SUPPORTED_VERSIONS = [\n // use \"lib/execution\" for runner.js, \"lib\" for client.js as basepath, latest tested 0.95.6\n '>=0.22.0 <4',\n // use \"lib\" as basepath\n '>=0.10.0 <0.18.0',\n '>=0.19.0 <0.22.0',\n // use \"src\" as basepath\n '>=0.18.0 <0.19.0',\n];\n\n// Max length of the query text captured in the `db.statement` attribute; \"..\" is appended when truncated.\nconst MAX_QUERY_LENGTH = 1022;\n\nconst parentSpanSymbol = Symbol('sentry.instrumentation-knex.parent-span');\n\nexport class KnexInstrumentation extends InstrumentationBase<InstrumentationConfig> {\n public constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n public init(): InstrumentationNodeModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition(MODULE_NAME, SUPPORTED_VERSIONS);\n\n module.files.push(\n this._getClientNodeModuleFileInstrumentation('src'),\n this._getClientNodeModuleFileInstrumentation('lib'),\n this._getRunnerNodeModuleFileInstrumentation('src'),\n this._getRunnerNodeModuleFileInstrumentation('lib'),\n this._getRunnerNodeModuleFileInstrumentation('lib/execution'),\n );\n\n return module;\n }\n\n private _getRunnerNodeModuleFileInstrumentation(basePath: string): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/runner.js`,\n SUPPORTED_VERSIONS,\n (Runner: any, moduleVersion?: string) => {\n this._ensureWrapped(Runner.prototype, 'query', this._createQueryWrapper(moduleVersion));\n return Runner;\n },\n (Runner: any) => {\n this._unwrap(Runner.prototype, 'query');\n return Runner;\n },\n );\n }\n\n private _getClientNodeModuleFileInstrumentation(basePath: string): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/client.js`,\n SUPPORTED_VERSIONS,\n (Client: any) => {\n this._ensureWrapped(Client.prototype, 'queryBuilder', this._storeContext.bind(this));\n this._ensureWrapped(Client.prototype, 'schemaBuilder', this._storeContext.bind(this));\n this._ensureWrapped(Client.prototype, 'raw', this._storeContext.bind(this));\n return Client;\n },\n (Client: any) => {\n this._unwrap(Client.prototype, 'queryBuilder');\n this._unwrap(Client.prototype, 'schemaBuilder');\n this._unwrap(Client.prototype, 'raw');\n return Client;\n },\n );\n }\n\n private _createQueryWrapper(moduleVersion?: string) {\n return function wrapQuery(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any, query: any) {\n const config = this.client.config;\n\n const table = utils.extractTableName(this.builder);\n const operation = query?.method;\n const connectionString = config?.connection?.connectionString;\n const name =\n config?.connection?.filename ||\n config?.connection?.database ||\n utils.extractDatabaseFromConnectionString(connectionString);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n 'knex.version': moduleVersion,\n [DB_SYSTEM]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_SQL_TABLE]: table,\n [DB_OPERATION]: operation,\n [DB_USER]: config?.connection?.user,\n [DB_NAME]: name,\n [NET_PEER_NAME]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [NET_PEER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n [NET_TRANSPORT]: config?.connection?.filename === ':memory:' ? 'inproc' : undefined,\n [DB_STATEMENT]: utils.limitLength(query?.sql, MAX_QUERY_LENGTH),\n };\n\n // The query builder captures the span active when it was created (see `_storeContext`).\n // `onlyIfParent` ensures we only instrument queries that run as part of an existing trace.\n const parentSpan: Span | undefined = this.builder[parentSpanSymbol] || getActiveSpan();\n\n const args = arguments;\n return startSpan(\n {\n name: utils.getName(name, operation, table),\n kind: SPAN_KIND.CLIENT,\n attributes,\n parentSpan,\n onlyIfParent: true,\n },\n span =>\n // `Runner.query` returns a real, already-executing Promise, so it is safe to let\n // `startSpan` await it and auto-end the span.\n original.apply(this, args).catch((err: any) => {\n const formatter = utils.getFormatter(this);\n const fullQuery = formatter(query.sql, query.bindings || []);\n const message = err.message.replace(`${fullQuery} - `, '');\n span.setStatus({ code: SPAN_STATUS_ERROR, message });\n throw err;\n }),\n );\n };\n };\n }\n\n private _storeContext(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any) {\n const builder = original.apply(this, arguments);\n // Capture the span that is active when the query builder is created. The query often executes\n // in a different async context, so we reuse this span as the parent when the query runs.\n Object.defineProperty(builder, parentSpanSymbol, {\n value: getActiveSpan(),\n });\n return builder;\n };\n }\n\n private _ensureWrapped(obj: any, methodName: string, wrapper: (original: any) => any): void {\n if (isWrapped(obj[methodName])) {\n this._unwrap(obj, methodName);\n }\n this._wrap(obj, methodName, wrapper);\n }\n}\n"],"names":["utils.extractTableName","utils.extractDatabaseFromConnectionString","utils.mapSystem","utils.extractHostFromConnectionString","utils.extractPortFromConnectionString","utils.limitLength","utils.getName","utils.getFormatter"],"mappings":";;;;;;;AAsCA,MAAM,YAAA,GAAe,8BAAA;AACrB,MAAM,MAAA,GAAS,mBAAA;AAEf,MAAM,WAAA,GAAc,MAAA;AACpB,MAAM,kBAAA,GAAqB;AAAA;AAAA,EAEzB,aAAA;AAAA;AAAA,EAEA,kBAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EAEA;AACF,CAAA;AAGA,MAAM,gBAAA,GAAmB,IAAA;AAEzB,MAAM,gBAAA,0BAA0B,yCAAyC,CAAA;AAElE,MAAM,4BAA4B,mBAAA,CAA2C;AAAA,EAC3E,WAAA,CAAY,MAAA,GAAgC,EAAC,EAAG;AACrD,IAAA,KAAA,CAAM,YAAA,EAAc,aAAa,MAAM,CAAA;AAAA,EACzC;AAAA,EAEO,IAAA,GAA4C;AACjD,IAAA,MAAM,MAAA,GAAS,IAAI,mCAAA,CAAoC,WAAA,EAAa,kBAAkB,CAAA;AAEtF,IAAA,MAAA,CAAO,KAAA,CAAM,IAAA;AAAA,MACX,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,KAAK,CAAA;AAAA,MAClD,IAAA,CAAK,wCAAwC,eAAe;AAAA,KAC9D;AAEA,IAAA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EQ,cAAA,CAAe,GAAA,EAAU,UAAA,EAAoB,OAAA,EAAuC;AAC1F,IAAA,IAAI,SAAA,CAAU,GAAA,CAAI,UAAU,CAAC,CAAA,EAAG;AAC9B,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAK,UAAU,CAAA;AAAA,IAC9B;AACA,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,UAAA,EAAY,OAAO,CAAA;AAAA,EACrC;AACF;;;;"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
const ATTR_DB_NAME = "db.name";
|
|
2
|
-
const ATTR_DB_OPERATION = "db.operation";
|
|
3
1
|
const ATTR_DB_SQL_TABLE = "db.sql.table";
|
|
4
|
-
const ATTR_DB_STATEMENT = "db.statement";
|
|
5
|
-
const ATTR_DB_SYSTEM = "db.system";
|
|
6
|
-
const ATTR_DB_USER = "db.user";
|
|
7
|
-
const ATTR_NET_PEER_NAME = "net.peer.name";
|
|
8
|
-
const ATTR_NET_PEER_PORT = "net.peer.port";
|
|
9
|
-
const ATTR_NET_TRANSPORT = "net.transport";
|
|
10
2
|
const DB_SYSTEM_NAME_VALUE_SQLITE = "sqlite";
|
|
11
3
|
const DB_SYSTEM_NAME_VALUE_POSTGRESQL = "postgresql";
|
|
12
4
|
|
|
13
|
-
export {
|
|
5
|
+
export { ATTR_DB_SQL_TABLE, DB_SYSTEM_NAME_VALUE_POSTGRESQL, DB_SYSTEM_NAME_VALUE_SQLITE };
|
|
14
6
|
//# sourceMappingURL=semconv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semconv.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n */\n\n/**\n * @deprecated Replaced by `db.
|
|
1
|
+
{"version":3,"file":"semconv.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n */\n\n/**\n * @deprecated Replaced by `db.collection.name`.\n */\nexport const ATTR_DB_SQL_TABLE = 'db.sql.table' as const;\n\nexport const DB_SYSTEM_NAME_VALUE_SQLITE = 'sqlite' as const;\n\nexport const DB_SYSTEM_NAME_VALUE_POSTGRESQL = 'postgresql' as const;\n"],"names":[],"mappings":"AAYO,MAAM,iBAAA,GAAoB;AAE1B,MAAM,2BAAA,GAA8B;AAEpC,MAAM,+BAAA,GAAkC;;;;"}
|
|
@@ -2,7 +2,7 @@ import * as api from '@opentelemetry/api';
|
|
|
2
2
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';
|
|
3
3
|
import { KoaLayerType } from './types.js';
|
|
4
4
|
import { SDK_VERSION, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getIsolationScope, getDefaultIsolationScope, debug } from '@sentry/core';
|
|
5
|
-
import {
|
|
5
|
+
import { HTTP_ROUTE } from '@sentry/conventions/attributes';
|
|
6
6
|
import { isLayerIgnored, getMiddlewareMetadata } from './utils.js';
|
|
7
7
|
import { setHttpServerSpanRouteAttribute } from '../../../../utils/setHttpServerSpanRouteAttribute.js';
|
|
8
8
|
import { DEBUG_BUILD } from '../../../../debug-build.js';
|
|
@@ -107,7 +107,7 @@ class KoaInstrumentation extends InstrumentationBase {
|
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
() => {
|
|
110
|
-
const route = metadata.attributes[
|
|
110
|
+
const route = metadata.attributes[HTTP_ROUTE];
|
|
111
111
|
if (getIsolationScope() === getDefaultIsolationScope()) {
|
|
112
112
|
DEBUG_BUILD && debug.warn("Isolation scope is default isolation scope - skipping setting transactionName");
|
|
113
113
|
} else if (route) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/koa/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-koa\n * - Upstream version: @opentelemetry/instrumentation-koa@0.66.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Span creation migrated to the @sentry/core API; op/origin/name and transaction name folded into\n * span creation (previously set via a Sentry requestHook)\n */\n\nimport * as api from '@opentelemetry/api';\nimport { isWrapped, InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\n\nimport { KoaLayerType, type KoaInstrumentationConfig } from './types';\nimport {\n debug,\n getDefaultIsolationScope,\n getIsolationScope,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n} from '@sentry/core';\nimport { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport { getMiddlewareMetadata, isLayerIgnored } from './utils';\nimport { setHttpServerSpanRouteAttribute } from '../../../../utils/setHttpServerSpanRouteAttribute';\nimport { DEBUG_BUILD } from '../../../../debug-build';\nimport { AttributeNames } from './enums/AttributeNames';\nimport {\n kLayerPatched,\n type Next,\n type KoaContext,\n type KoaMiddleware,\n type KoaPatchedMiddleware,\n} from './internal-types';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-koa';\n\ninterface KoaModuleExports {\n prototype: { use: KoaMiddleware };\n}\n\ntype KoaModule = KoaModuleExports & { [Symbol.toStringTag]?: string; default?: KoaModuleExports };\n\n/** Koa instrumentation for OpenTelemetry */\nexport class KoaInstrumentation extends InstrumentationBase<KoaInstrumentationConfig> {\n constructor(config: KoaInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n 'koa',\n ['>=2.0.0 <4'],\n (module: KoaModule) => {\n const moduleExports =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n if (moduleExports == null) {\n return moduleExports;\n }\n if (isWrapped(moduleExports.prototype.use)) {\n this._unwrap(moduleExports.prototype, 'use');\n }\n this._wrap(moduleExports.prototype, 'use', this._getKoaUsePatch.bind(this));\n return module;\n },\n (module: KoaModule) => {\n const moduleExports =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n if (moduleExports && isWrapped(moduleExports.prototype.use)) {\n this._unwrap(moduleExports.prototype, 'use');\n }\n },\n );\n }\n\n /**\n * Patches the Koa.use function in order to instrument each original\n * middleware layer which is introduced\n * @param {KoaMiddleware} middleware - the original middleware function\n */\n private _getKoaUsePatch(original: (middleware: KoaMiddleware) => unknown) {\n const patchRouterDispatch = this._patchRouterDispatch.bind(this);\n const patchLayer = this._patchLayer.bind(this);\n return function use(this: unknown, middlewareFunction: KoaMiddleware) {\n const patchedFunction = middlewareFunction.router\n ? patchRouterDispatch(middlewareFunction)\n : patchLayer(middlewareFunction, false);\n return original.apply(this, [patchedFunction]);\n };\n }\n\n /**\n * Patches the dispatch function used by @koa/router. This function\n * goes through each routed middleware and adds instrumentation via a call\n * to the @function _patchLayer function.\n * @param {KoaMiddleware} dispatchLayer - the original dispatch function which dispatches\n * routed middleware\n */\n private _patchRouterDispatch(dispatchLayer: KoaMiddleware): KoaMiddleware {\n const router = dispatchLayer.router;\n\n const routesStack = router?.stack ?? [];\n for (const pathLayer of routesStack) {\n const path = pathLayer.path;\n const pathStack = pathLayer.stack;\n for (let j = 0; j < pathStack.length; j++) {\n const routedMiddleware: KoaMiddleware = pathStack[j]!;\n pathStack[j] = this._patchLayer(routedMiddleware, true, path);\n }\n }\n\n return dispatchLayer;\n }\n\n /**\n * Patches each individual @param middlewareLayer function in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {KoaMiddleware} middlewareLayer - the original middleware function.\n * @param {boolean} isRouter - tracks whether the original middleware function\n * was dispatched by the router originally\n * @param {string?} layerPath - if present, provides additional data from the\n * router about the routed path which the middleware is attached to\n */\n private _patchLayer(\n middlewareLayer: KoaPatchedMiddleware,\n isRouter: boolean,\n layerPath?: string | RegExp,\n ): KoaMiddleware {\n const layerType = isRouter ? KoaLayerType.ROUTER : KoaLayerType.MIDDLEWARE;\n // Skip patching layer if its ignored in the config\n if (middlewareLayer[kLayerPatched] === true || isLayerIgnored(layerType, this.getConfig())) return middlewareLayer;\n\n if (\n middlewareLayer.constructor.name === 'GeneratorFunction' ||\n middlewareLayer.constructor.name === 'AsyncGeneratorFunction'\n ) {\n return middlewareLayer;\n }\n\n middlewareLayer[kLayerPatched] = true;\n\n return (context: KoaContext, next: Next) => {\n const parent = api.trace.getSpan(api.context.active());\n if (parent === undefined) {\n return middlewareLayer(context, next);\n }\n const metadata = getMiddlewareMetadata(context, middlewareLayer, isRouter, layerPath);\n\n if (context._matchedRoute) {\n setHttpServerSpanRouteAttribute(context._matchedRoute.toString());\n }\n\n const koaName = metadata.attributes[AttributeNames.KOA_NAME];\n // Somehow, name is sometimes `''` for middleware spans\n // See: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2220\n const name = typeof koaName === 'string' ? koaName || '< unknown >' : metadata.name;\n\n return startSpan(\n {\n name,\n op: `${layerType}.koa`,\n attributes: {\n ...metadata.attributes,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.koa',\n },\n },\n () => {\n const route = metadata.attributes[ATTR_HTTP_ROUTE];\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && debug.warn('Isolation scope is default isolation scope - skipping setting transactionName');\n } else if (route) {\n const method = (context.request as { method?: string } | undefined)?.method?.toUpperCase() || 'GET';\n getIsolationScope().setTransactionName(`${method} ${route}`);\n }\n return middlewareLayer(context, next);\n },\n );\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAqCA,MAAM,YAAA,GAAe,6BAAA;AASd,MAAM,2BAA2B,mBAAA,CAA8C;AAAA,EACpF,WAAA,CAAY,MAAA,GAAmC,EAAC,EAAG;AACjD,IAAA,KAAA,CAAM,YAAA,EAAc,aAAa,MAAM,CAAA;AAAA,EACzC;AAAA,EAEU,IAAA,GAAO;AACf,IAAA,OAAO,IAAI,mCAAA;AAAA,MACT,KAAA;AAAA,MACA,CAAC,YAAY,CAAA;AAAA,MACb,CAAC,MAAA,KAAsB;AACrB,QAAA,MAAM,gBACJ,MAAA,CAAO,MAAA,CAAO,WAAW,CAAA,KAAM,QAAA,GAC3B,OAAO,OAAA,GACP,MAAA;AACN,QAAA,IAAI,iBAAiB,IAAA,EAAM;AACzB,UAAA,OAAO,aAAA;AAAA,QACT;AACA,QAAA,IAAI,SAAA,CAAU,aAAA,CAAc,SAAA,CAAU,GAAG,CAAA,EAAG;AAC1C,UAAA,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,SAAA,EAAW,KAAK,CAAA;AAAA,QAC7C;AACA,QAAA,IAAA,CAAK,KAAA,CAAM,cAAc,SAAA,EAAW,KAAA,EAAO,KAAK,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAC,CAAA;AAC1E,QAAA,OAAO,MAAA;AAAA,MACT,CAAA;AAAA,MACA,CAAC,MAAA,KAAsB;AACrB,QAAA,MAAM,gBACJ,MAAA,CAAO,MAAA,CAAO,WAAW,CAAA,KAAM,QAAA,GAC3B,OAAO,OAAA,GACP,MAAA;AACN,QAAA,IAAI,aAAA,IAAiB,SAAA,CAAU,aAAA,CAAc,SAAA,CAAU,GAAG,CAAA,EA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,CAAA;AAAA,UAChB,UAAA,EAAY;AAAA,YACV,GAAG,QAAA,CAAS,UAAA;AAAA,YACZ,CAAC,gCAAgC,GAAG;AAAA;AACtC,SACF;AAAA,QACA,MAAM;AACJ,UAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,UAAA,CAAW,eAAe,CAAA;AACjD,UAAA,IAAI,iBAAA,EAAkB,KAAM,wBAAA,EAAyB,EAAG;AACtD,YAAA,WAAA,IAAe,KAAA,CAAM,KAAK,+EAA+E,CAAA;AAAA,UAC3G,WAAW,KAAA,EAAO;AAChB,YAAA,MAAM,MAAA,GAAU,OAAA,CAAQ,OAAA,EAA6C,MAAA,EAAQ,aAAY,IAAK,KAAA;AAC9F,YAAA,iBAAA,GAAoB,kBAAA,CAAmB,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,KAAK,CAAA,CAAE,CAAA;AAAA,UAC7D;AACA,UAAA,OAAO,eAAA,CAAgB,SAAS,IAAI,CAAA;AAAA,QACtC;AAAA,OACF;AAAA,IACF,CAAA;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/koa/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-koa\n * - Upstream version: @opentelemetry/instrumentation-koa@0.66.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n * - Span creation migrated to the @sentry/core API; op/origin/name and transaction name folded into\n * span creation (previously set via a Sentry requestHook)\n */\n\nimport * as api from '@opentelemetry/api';\nimport { isWrapped, InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\n\nimport { KoaLayerType, type KoaInstrumentationConfig } from './types';\nimport {\n debug,\n getDefaultIsolationScope,\n getIsolationScope,\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n} from '@sentry/core';\nimport { HTTP_ROUTE } from '@sentry/conventions/attributes';\nimport { getMiddlewareMetadata, isLayerIgnored } from './utils';\nimport { setHttpServerSpanRouteAttribute } from '../../../../utils/setHttpServerSpanRouteAttribute';\nimport { DEBUG_BUILD } from '../../../../debug-build';\nimport { AttributeNames } from './enums/AttributeNames';\nimport {\n kLayerPatched,\n type Next,\n type KoaContext,\n type KoaMiddleware,\n type KoaPatchedMiddleware,\n} from './internal-types';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-koa';\n\ninterface KoaModuleExports {\n prototype: { use: KoaMiddleware };\n}\n\ntype KoaModule = KoaModuleExports & { [Symbol.toStringTag]?: string; default?: KoaModuleExports };\n\n/** Koa instrumentation for OpenTelemetry */\nexport class KoaInstrumentation extends InstrumentationBase<KoaInstrumentationConfig> {\n constructor(config: KoaInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n 'koa',\n ['>=2.0.0 <4'],\n (module: KoaModule) => {\n const moduleExports =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n if (moduleExports == null) {\n return moduleExports;\n }\n if (isWrapped(moduleExports.prototype.use)) {\n this._unwrap(moduleExports.prototype, 'use');\n }\n this._wrap(moduleExports.prototype, 'use', this._getKoaUsePatch.bind(this));\n return module;\n },\n (module: KoaModule) => {\n const moduleExports =\n module[Symbol.toStringTag] === 'Module'\n ? module.default // ESM\n : module; // CommonJS\n if (moduleExports && isWrapped(moduleExports.prototype.use)) {\n this._unwrap(moduleExports.prototype, 'use');\n }\n },\n );\n }\n\n /**\n * Patches the Koa.use function in order to instrument each original\n * middleware layer which is introduced\n * @param {KoaMiddleware} middleware - the original middleware function\n */\n private _getKoaUsePatch(original: (middleware: KoaMiddleware) => unknown) {\n const patchRouterDispatch = this._patchRouterDispatch.bind(this);\n const patchLayer = this._patchLayer.bind(this);\n return function use(this: unknown, middlewareFunction: KoaMiddleware) {\n const patchedFunction = middlewareFunction.router\n ? patchRouterDispatch(middlewareFunction)\n : patchLayer(middlewareFunction, false);\n return original.apply(this, [patchedFunction]);\n };\n }\n\n /**\n * Patches the dispatch function used by @koa/router. This function\n * goes through each routed middleware and adds instrumentation via a call\n * to the @function _patchLayer function.\n * @param {KoaMiddleware} dispatchLayer - the original dispatch function which dispatches\n * routed middleware\n */\n private _patchRouterDispatch(dispatchLayer: KoaMiddleware): KoaMiddleware {\n const router = dispatchLayer.router;\n\n const routesStack = router?.stack ?? [];\n for (const pathLayer of routesStack) {\n const path = pathLayer.path;\n const pathStack = pathLayer.stack;\n for (let j = 0; j < pathStack.length; j++) {\n const routedMiddleware: KoaMiddleware = pathStack[j]!;\n pathStack[j] = this._patchLayer(routedMiddleware, true, path);\n }\n }\n\n return dispatchLayer;\n }\n\n /**\n * Patches each individual @param middlewareLayer function in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {KoaMiddleware} middlewareLayer - the original middleware function.\n * @param {boolean} isRouter - tracks whether the original middleware function\n * was dispatched by the router originally\n * @param {string?} layerPath - if present, provides additional data from the\n * router about the routed path which the middleware is attached to\n */\n private _patchLayer(\n middlewareLayer: KoaPatchedMiddleware,\n isRouter: boolean,\n layerPath?: string | RegExp,\n ): KoaMiddleware {\n const layerType = isRouter ? KoaLayerType.ROUTER : KoaLayerType.MIDDLEWARE;\n // Skip patching layer if its ignored in the config\n if (middlewareLayer[kLayerPatched] === true || isLayerIgnored(layerType, this.getConfig())) return middlewareLayer;\n\n if (\n middlewareLayer.constructor.name === 'GeneratorFunction' ||\n middlewareLayer.constructor.name === 'AsyncGeneratorFunction'\n ) {\n return middlewareLayer;\n }\n\n middlewareLayer[kLayerPatched] = true;\n\n return (context: KoaContext, next: Next) => {\n const parent = api.trace.getSpan(api.context.active());\n if (parent === undefined) {\n return middlewareLayer(context, next);\n }\n const metadata = getMiddlewareMetadata(context, middlewareLayer, isRouter, layerPath);\n\n if (context._matchedRoute) {\n setHttpServerSpanRouteAttribute(context._matchedRoute.toString());\n }\n\n const koaName = metadata.attributes[AttributeNames.KOA_NAME];\n // Somehow, name is sometimes `''` for middleware spans\n // See: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2220\n const name = typeof koaName === 'string' ? koaName || '< unknown >' : metadata.name;\n\n return startSpan(\n {\n name,\n op: `${layerType}.koa`,\n attributes: {\n ...metadata.attributes,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.koa',\n },\n },\n () => {\n const route = metadata.attributes[HTTP_ROUTE];\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && debug.warn('Isolation scope is default isolation scope - skipping setting transactionName');\n } else if (route) {\n const method = (context.request as { method?: string } | undefined)?.method?.toUpperCase() || 'GET';\n getIsolationScope().setTransactionName(`${method} ${route}`);\n }\n return middlewareLayer(context, next);\n },\n );\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAqCA,MAAM,YAAA,GAAe,6BAAA;AASd,MAAM,2BAA2B,mBAAA,CAA8C;AAAA,EACpF,WAAA,CAAY,MAAA,GAAmC,EAAC,EAAG;AACjD,IAAA,KAAA,CAAM,YAAA,EAAc,aAAa,MAAM,CAAA;AAAA,EACzC;AAAA,EAEU,IAAA,GAAO;AACf,IAAA,OAAO,IAAI,mCAAA;AAAA,MACT,KAAA;AAAA,MACA,CAAC,YAAY,CAAA;AAAA,MACb,CAAC,MAAA,KAAsB;AACrB,QAAA,MAAM,gBACJ,MAAA,CAAO,MAAA,CAAO,WAAW,CAAA,KAAM,QAAA,GAC3B,OAAO,OAAA,GACP,MAAA;AACN,QAAA,IAAI,iBAAiB,IAAA,EAAM;AACzB,UAAA,OAAO,aAAA;AAAA,QACT;AACA,QAAA,IAAI,SAAA,CAAU,aAAA,CAAc,SAAA,CAAU,GAAG,CAAA,EAAG;AAC1C,UAAA,IA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import { HTTP_ROUTE } from '@sentry/conventions/attributes';
|
|
4
4
|
|
|
5
5
|
const getMiddlewareMetadata = (context, layer, isRouter, layerPath) => {
|
|
6
6
|
if (isRouter) {
|
|
@@ -8,7 +8,7 @@ const getMiddlewareMetadata = (context, layer, isRouter, layerPath) => {
|
|
|
8
8
|
attributes: {
|
|
9
9
|
[AttributeNames.KOA_NAME]: layerPath?.toString(),
|
|
10
10
|
[AttributeNames.KOA_TYPE]: KoaLayerType.ROUTER,
|
|
11
|
-
[
|
|
11
|
+
[HTTP_ROUTE]: layerPath?.toString()
|
|
12
12
|
},
|
|
13
13
|
name: context._matchedRouteName || `router - ${layerPath}`
|
|
14
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/koa/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-koa\n * - Upstream version: @opentelemetry/instrumentation-koa@0.66.0\n */\n\nimport { KoaLayerType, type KoaInstrumentationConfig } from './types';\nimport type { KoaContext, KoaMiddleware } from './internal-types';\nimport { AttributeNames } from './enums/AttributeNames';\nimport type { Attributes } from '@opentelemetry/api';\nimport {
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/koa/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-koa\n * - Upstream version: @opentelemetry/instrumentation-koa@0.66.0\n */\n\nimport { KoaLayerType, type KoaInstrumentationConfig } from './types';\nimport type { KoaContext, KoaMiddleware } from './internal-types';\nimport { AttributeNames } from './enums/AttributeNames';\nimport type { Attributes } from '@opentelemetry/api';\nimport { HTTP_ROUTE } from '@sentry/conventions/attributes';\n\nexport const getMiddlewareMetadata = (\n context: KoaContext,\n layer: KoaMiddleware,\n isRouter: boolean,\n layerPath?: string | RegExp,\n): {\n attributes: Attributes;\n name: string;\n} => {\n if (isRouter) {\n return {\n attributes: {\n [AttributeNames.KOA_NAME]: layerPath?.toString(),\n [AttributeNames.KOA_TYPE]: KoaLayerType.ROUTER,\n [HTTP_ROUTE]: layerPath?.toString(),\n },\n name: context._matchedRouteName || `router - ${layerPath}`,\n };\n } else {\n return {\n attributes: {\n [AttributeNames.KOA_NAME]: layer.name ?? 'middleware',\n [AttributeNames.KOA_TYPE]: KoaLayerType.MIDDLEWARE,\n },\n name: `middleware - ${layer.name}`,\n };\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isLayerIgnored = (type: KoaLayerType, config?: KoaInstrumentationConfig): boolean => {\n return !!(Array.isArray(config?.ignoreLayersType) && config?.ignoreLayersType?.includes(type));\n};\n"],"names":[],"mappings":";;;;AAeO,MAAM,qBAAA,GAAwB,CACnC,OAAA,EACA,KAAA,EACA,UACA,SAAA,KAIG;AACH,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,OAAO;AAAA,MACL,UAAA,EAAY;AAAA,QACV,CAAC,cAAA,CAAe,QAAQ,GAAG,WAAW,QAAA,EAAS;AAAA,QAC/C,CAAC,cAAA,CAAe,QAAQ,GAAG,YAAA,CAAa,MAAA;AAAA,QACxC,CAAC,UAAU,GAAG,SAAA,EAAW,QAAA;AAAS,OACpC;AAAA,MACA,IAAA,EAAM,OAAA,CAAQ,iBAAA,IAAqB,CAAA,SAAA,EAAY,SAAS,CAAA;AAAA,KAC1D;AAAA,EACF,CAAA,MAAO;AACL,IAAA,OAAO;AAAA,MACL,UAAA,EAAY;AAAA,QACV,CAAC,cAAA,CAAe,QAAQ,GAAG,MAAM,IAAA,IAAQ,YAAA;AAAA,QACzC,CAAC,cAAA,CAAe,QAAQ,GAAG,YAAA,CAAa;AAAA,OAC1C;AAAA,MACA,IAAA,EAAM,CAAA,aAAA,EAAgB,KAAA,CAAM,IAAI,CAAA;AAAA,KAClC;AAAA,EACF;AACF;AAQO,MAAM,cAAA,GAAiB,CAAC,IAAA,EAAoB,MAAA,KAA+C;AAChG,EAAA,OAAO,CAAC,EAAE,KAAA,CAAM,OAAA,CAAQ,MAAA,EAAQ,gBAAgB,CAAA,IAAK,MAAA,EAAQ,gBAAA,EAAkB,QAAA,CAAS,IAAI,CAAA,CAAA;AAC9F;;;;"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
const ATTR_DB_CONNECTION_STRING = "db.connection_string";
|
|
2
2
|
const ATTR_DB_MONGODB_COLLECTION = "db.mongodb.collection";
|
|
3
|
-
const ATTR_DB_NAME = "db.name";
|
|
4
|
-
const ATTR_DB_OPERATION = "db.operation";
|
|
5
|
-
const ATTR_DB_STATEMENT = "db.statement";
|
|
6
|
-
const ATTR_DB_SYSTEM = "db.system";
|
|
7
|
-
const ATTR_NET_PEER_NAME = "net.peer.name";
|
|
8
|
-
const ATTR_NET_PEER_PORT = "net.peer.port";
|
|
9
3
|
const DB_SYSTEM_VALUE_MONGODB = "mongodb";
|
|
10
4
|
|
|
11
|
-
export { ATTR_DB_CONNECTION_STRING, ATTR_DB_MONGODB_COLLECTION,
|
|
5
|
+
export { ATTR_DB_CONNECTION_STRING, ATTR_DB_MONGODB_COLLECTION, DB_SYSTEM_VALUE_MONGODB };
|
|
12
6
|
//# sourceMappingURL=semconv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semconv.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use `server.address`, `server.port` attributes instead.\n *\n * @deprecated Replaced by `server.address` and `server.port`.\n */\nexport const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;\n\n/**\n * Deprecated, use `db.collection.name` instead.\n *\n * @deprecated Replaced by `db.collection.name`.\n */\nexport const ATTR_DB_MONGODB_COLLECTION = 'db.mongodb.collection' as const;\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"semconv.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/semconv.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use `server.address`, `server.port` attributes instead.\n *\n * @deprecated Replaced by `server.address` and `server.port`.\n */\nexport const ATTR_DB_CONNECTION_STRING = 'db.connection_string' as const;\n\n/**\n * Deprecated, use `db.collection.name` instead.\n *\n * @deprecated Replaced by `db.collection.name`.\n */\nexport const ATTR_DB_MONGODB_COLLECTION = 'db.mongodb.collection' as const;\n\n/**\n * Enum value \"mongodb\" for attribute `db.system`.\n */\nexport const DB_SYSTEM_VALUE_MONGODB = 'mongodb' as const;\n"],"names":[],"mappings":"AAoBO,MAAM,yBAAA,GAA4B;AAOlC,MAAM,0BAAA,GAA6B;AAKnC,MAAM,uBAAA,GAA0B;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getActiveSpan, startInactiveSpan, SPAN_KIND, SPAN_STATUS_ERROR, withActiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
2
|
-
import {
|
|
1
|
+
import { getActiveSpan, startInactiveSpan, SPAN_KIND, SPAN_STATUS_ERROR, withActiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, isObjectLike } from '@sentry/core';
|
|
2
|
+
import { DB_OPERATION, NET_PEER_NAME, NET_PEER_PORT, DB_STATEMENT, DB_NAME, DB_SYSTEM } from '@sentry/conventions/attributes';
|
|
3
|
+
import { DB_SYSTEM_VALUE_MONGODB, ATTR_DB_CONNECTION_STRING, ATTR_DB_MONGODB_COLLECTION } from './semconv.js';
|
|
3
4
|
import { MongodbCommandType } from './internal-types.js';
|
|
4
5
|
|
|
5
6
|
const ORIGIN = "auto.db.otel.mongo";
|
|
@@ -22,7 +23,7 @@ function scrubStatement(value) {
|
|
|
22
23
|
return "?";
|
|
23
24
|
}
|
|
24
25
|
function isCommandObj(value) {
|
|
25
|
-
return
|
|
26
|
+
return isObjectLike(value) && !isBuffer(value);
|
|
26
27
|
}
|
|
27
28
|
function isBuffer(value) {
|
|
28
29
|
return typeof Buffer !== "undefined" && Buffer.isBuffer(value);
|
|
@@ -87,26 +88,26 @@ function getSpanAttributes(dbName, dbCollection, host, port, commandObj, operati
|
|
|
87
88
|
const attributes = {
|
|
88
89
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
89
90
|
// eslint-disable-next-line typescript/no-deprecated
|
|
90
|
-
[
|
|
91
|
+
[DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,
|
|
91
92
|
// eslint-disable-next-line typescript/no-deprecated
|
|
92
|
-
[
|
|
93
|
+
[DB_NAME]: dbName,
|
|
93
94
|
// eslint-disable-next-line typescript/no-deprecated
|
|
94
95
|
[ATTR_DB_MONGODB_COLLECTION]: dbCollection,
|
|
95
96
|
// eslint-disable-next-line typescript/no-deprecated
|
|
96
|
-
[
|
|
97
|
+
[DB_OPERATION]: operation,
|
|
97
98
|
// eslint-disable-next-line typescript/no-deprecated
|
|
98
99
|
[ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`
|
|
99
100
|
};
|
|
100
101
|
if (host && port) {
|
|
101
|
-
attributes[
|
|
102
|
+
attributes[NET_PEER_NAME] = host;
|
|
102
103
|
const portNumber = parseInt(port, 10);
|
|
103
104
|
if (!isNaN(portNumber)) {
|
|
104
|
-
attributes[
|
|
105
|
+
attributes[NET_PEER_PORT] = portNumber;
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
if (commandObj) {
|
|
108
109
|
try {
|
|
109
|
-
attributes[
|
|
110
|
+
attributes[DB_STATEMENT] = serializeDbStatement(commandObj);
|
|
110
111
|
} catch {
|
|
111
112
|
}
|
|
112
113
|
}
|
|
@@ -115,7 +116,7 @@ function getSpanAttributes(dbName, dbCollection, host, port, commandObj, operati
|
|
|
115
116
|
function startMongoSpan(attributes) {
|
|
116
117
|
return startInactiveSpan({
|
|
117
118
|
// eslint-disable-next-line typescript/no-deprecated
|
|
118
|
-
name: `mongodb.${attributes[
|
|
119
|
+
name: `mongodb.${attributes[DB_OPERATION] || "command"}`,
|
|
119
120
|
kind: SPAN_KIND.CLIENT,
|
|
120
121
|
attributes
|
|
121
122
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n ATTR_DB_CONNECTION_STRING,\n ATTR_DB_MONGODB_COLLECTION,\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n DB_SYSTEM_VALUE_MONGODB,\n} from './semconv';\nimport type { MongodbNamespace, MongoInternalCommand, MongoInternalTopology } from './internal-types';\nimport { MongodbCommandType } from './internal-types';\n\nconst ORIGIN = 'auto.db.otel.mongo';\n\n/**\n * Replaces values in the command object with '?', hiding PII and helping grouping.\n */\nfunction serializeDbStatement(commandObj: Record<string, unknown>): string {\n return JSON.stringify(scrubStatement(commandObj));\n}\n\nfunction scrubStatement(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(element => scrubStatement(element));\n }\n\n if (isCommandObj(value)) {\n const initial: Record<string, unknown> = {};\n return Object.entries(value)\n .map(([key, element]) => [key, scrubStatement(element)])\n .reduce((prev, current) => {\n if (isCommandEntry(current)) {\n prev[current[0]] = current[1];\n }\n return prev;\n }, initial);\n }\n\n // A value like string or number, possibly contains PII, scrub it\n return '?';\n}\n\nfunction isCommandObj(value: Record<string, unknown> | unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !isBuffer(value);\n}\n\nfunction isBuffer(value: unknown): boolean {\n return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);\n}\n\nfunction isCommandEntry(value: [string, unknown] | unknown): value is [string, unknown] {\n return Array.isArray(value);\n}\n\n/**\n * Get the mongodb command type from the object.\n */\nexport function getCommandType(command: MongoInternalCommand): MongodbCommandType {\n if (command.createIndexes !== undefined) {\n return MongodbCommandType.CREATE_INDEXES;\n } else if (command.findandmodify !== undefined) {\n return MongodbCommandType.FIND_AND_MODIFY;\n } else if (command.ismaster !== undefined) {\n return MongodbCommandType.IS_MASTER;\n } else if (command.count !== undefined) {\n return MongodbCommandType.COUNT;\n } else if (command.aggregate !== undefined) {\n return MongodbCommandType.AGGREGATE;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v4 connection context.\n */\nexport function getV4SpanAttributes(\n connectionCtx: any,\n ns: MongodbNamespace,\n command?: any,\n operation?: string,\n): SpanAttributes {\n let host, port: undefined | string;\n if (connectionCtx) {\n const hostParts = typeof connectionCtx.address === 'string' ? connectionCtx.address.split(':') : '';\n if (hostParts.length === 2) {\n host = hostParts[0];\n port = hostParts[1];\n }\n }\n let commandObj: Record<string, unknown>;\n if (command?.documents && command.documents[0]) {\n commandObj = command.documents[0];\n } else if (command?.cursors) {\n commandObj = command.cursors;\n } else {\n commandObj = command;\n }\n\n return getSpanAttributes(ns.db, ns.collection, host, port, commandObj, operation);\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v3 topology.\n */\nexport function getV3SpanAttributes(\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined,\n): SpanAttributes {\n let host: undefined | string;\n let port: undefined | string;\n if (topology?.s) {\n host = topology.s.options?.host ?? topology.s.host;\n port = (topology.s.options?.port ?? topology.s.port)?.toString();\n if (host == null || port == null) {\n const address = topology.description?.address;\n if (address) {\n const addressSegments = address.split(':');\n host = addressSegments[0];\n port = addressSegments[1];\n }\n }\n }\n\n // The namespace is a combination of the database name and the name of the\n // collection or index, like so: [database-name].[collection-or-index-name].\n // It could be a string or an instance of MongoDBNamespace, as such we\n // always coerce to a string to extract db and collection.\n const [dbName, dbCollection] = ns.toString().split('.');\n const commandObj = command?.query ?? command?.q ?? command;\n\n return getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation);\n}\n\nfunction getSpanAttributes(\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined,\n): SpanAttributes {\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_NAME]: dbName,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_MONGODB_COLLECTION]: dbCollection,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_OPERATION]: operation,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n };\n\n if (host && port) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[ATTR_NET_PEER_NAME] = host;\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[ATTR_NET_PEER_PORT] = portNumber;\n }\n }\n\n if (commandObj) {\n try {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[ATTR_DB_STATEMENT] = serializeDbStatement(commandObj);\n } catch {\n // ignore serialization errors — the statement is best-effort metadata\n }\n }\n\n return attributes;\n}\n\nexport function startMongoSpan(attributes: SpanAttributes): Span {\n return startInactiveSpan({\n // eslint-disable-next-line typescript/no-deprecated\n name: `mongodb.${attributes[ATTR_DB_OPERATION] || 'command'}`,\n kind: SPAN_KIND.CLIENT,\n attributes,\n });\n}\n\n/**\n * Wraps the result handler so it ends the span (with error status on failure) and runs the\n * original callback re-activated under the parent span — mongodb loses the async context when\n * it invokes the callback on a later tick.\n */\nexport function patchEnd(span: Span | undefined, resultHandler: Function): Function {\n const parentSpan = getActiveSpan();\n let spanEnded = false;\n\n return function patchedEnd(this: {}, ...args: unknown[]) {\n if (!spanEnded) {\n spanEnded = true;\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n span.end();\n }\n }\n\n return withActiveSpan(parentSpan ?? null, () => resultHandler.apply(this, args));\n };\n}\n\n// The instrumentation only creates spans when there is an active parent span, to avoid emitting\n// orphaned mongodb spans.\nexport function shouldSkipInstrumentation(): boolean {\n return !getActiveSpan();\n}\n"],"names":[],"mappings":";;;;AAiCA,MAAM,MAAA,GAAS,oBAAA;AAKf,SAAS,qBAAqB,UAAA,EAA6C;AACzE,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,cAAA,CAAe,UAAU,CAAC,CAAA;AAClD;AAEA,SAAS,eAAe,KAAA,EAAyB;AAC/C,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAA,OAAA,KAAW,cAAA,CAAe,OAAO,CAAC,CAAA;AAAA,EACrD;AAEA,EAAA,IAAI,YAAA,CAAa,KAAK,CAAA,EAAG;AACvB,IAAA,MAAM,UAAmC,EAAC;AAC1C,IAAA,OAAO,MAAA,CAAO,QAAQ,KAAK,CAAA,CACxB,IAAI,CAAC,CAAC,KAAK,OAAO,CAAA,KAAM,CAAC,GAAA,EAAK,cAAA,CAAe,OAAO,CAAC,CAAC,EACtD,MAAA,CAAO,CAAC,MAAM,OAAA,KAAY;AACzB,MAAA,IAAI,cAAA,CAAe,OAAO,CAAA,EAAG;AAC3B,QAAA,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAC,CAAA,GAAI,QAAQ,CAAC,CAAA;AAAA,MAC9B;AACA,MAAA,OAAO,IAAA;AAAA,IACT,GAAG,OAAO,CAAA;AAAA,EACd;AAGA,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,aAAa,KAAA,EAA4E;AAChG,EAAA,OAAO,OAAO,KAAA,KAAU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C;AAC/D,EAAA,OAAO,iBAAA,CAAkB;AAAA;AAAA,IAEvB,IAAA,EAAM,CAAA,QAAA,EAAW,UAAA,CAAW,iBAAiB,KAAK,SAAS,CAAA,CAAA;AAAA,IAC3D,MAAM,SAAA,CAAU,MAAA;AAAA,IAChB;AAAA,GACD,CAAA;AACH;AAOO,SAAS,QAAA,CAAS,MAAwB,aAAA,EAAmC;AAClF,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,SAAA,GAAY,KAAA;AAEhB,EAAA,OAAO,SAAS,cAAwB,IAAA,EAAiB;AACvD,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,MAAM,KAAA,GAAQ,KAAK,CAAC,CAAA;AACpB,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,mBAAmB,OAAA,EAAS,KAAA,CAAM,SAAS,CAAA;AAAA,QACpE;AACA,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IACF;AAEA,IAAA,OAAO,cAAA,CAAe,cAAc,IAAA,EAAM,MAAM,cAAc,KAAA,CAAM,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACjF,CAAA;AACF;AAIO,SAAS,yBAAA,GAAqC;AACnD,EAAA,OAAO,CAAC,aAAA,EAAc;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/mongo/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-mongodb\n * - Upstream version: @opentelemetry/instrumentation-mongodb@0.71.0\n * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n */\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n getActiveSpan,\n isObjectLike,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n DB_NAME,\n DB_OPERATION,\n DB_STATEMENT,\n DB_SYSTEM,\n NET_PEER_NAME,\n NET_PEER_PORT,\n} from '@sentry/conventions/attributes';\nimport { ATTR_DB_CONNECTION_STRING, ATTR_DB_MONGODB_COLLECTION, DB_SYSTEM_VALUE_MONGODB } from './semconv';\nimport type { MongodbNamespace, MongoInternalCommand, MongoInternalTopology } from './internal-types';\nimport { MongodbCommandType } from './internal-types';\n\nconst ORIGIN = 'auto.db.otel.mongo';\n\n/**\n * Replaces values in the command object with '?', hiding PII and helping grouping.\n */\nfunction serializeDbStatement(commandObj: Record<string, unknown>): string {\n return JSON.stringify(scrubStatement(commandObj));\n}\n\nfunction scrubStatement(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(element => scrubStatement(element));\n }\n\n if (isCommandObj(value)) {\n const initial: Record<string, unknown> = {};\n return Object.entries(value)\n .map(([key, element]) => [key, scrubStatement(element)])\n .reduce((prev, current) => {\n if (isCommandEntry(current)) {\n prev[current[0]] = current[1];\n }\n return prev;\n }, initial);\n }\n\n // A value like string or number, possibly contains PII, scrub it\n return '?';\n}\n\nfunction isCommandObj(value: Record<string, unknown> | unknown): value is Record<string, unknown> {\n return isObjectLike(value) && !isBuffer(value);\n}\n\nfunction isBuffer(value: unknown): boolean {\n return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);\n}\n\nfunction isCommandEntry(value: [string, unknown] | unknown): value is [string, unknown] {\n return Array.isArray(value);\n}\n\n/**\n * Get the mongodb command type from the object.\n */\nexport function getCommandType(command: MongoInternalCommand): MongodbCommandType {\n if (command.createIndexes !== undefined) {\n return MongodbCommandType.CREATE_INDEXES;\n } else if (command.findandmodify !== undefined) {\n return MongodbCommandType.FIND_AND_MODIFY;\n } else if (command.ismaster !== undefined) {\n return MongodbCommandType.IS_MASTER;\n } else if (command.count !== undefined) {\n return MongodbCommandType.COUNT;\n } else if (command.aggregate !== undefined) {\n return MongodbCommandType.AGGREGATE;\n } else {\n return MongodbCommandType.UNKNOWN;\n }\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v4 connection context.\n */\nexport function getV4SpanAttributes(\n connectionCtx: any,\n ns: MongodbNamespace,\n command?: any,\n operation?: string,\n): SpanAttributes {\n let host, port: undefined | string;\n if (connectionCtx) {\n const hostParts = typeof connectionCtx.address === 'string' ? connectionCtx.address.split(':') : '';\n if (hostParts.length === 2) {\n host = hostParts[0];\n port = hostParts[1];\n }\n }\n let commandObj: Record<string, unknown>;\n if (command?.documents && command.documents[0]) {\n commandObj = command.documents[0];\n } else if (command?.cursors) {\n commandObj = command.cursors;\n } else {\n commandObj = command;\n }\n\n return getSpanAttributes(ns.db, ns.collection, host, port, commandObj, operation);\n}\n\n/**\n * Determine a span's attributes by fetching related metadata from the v3 topology.\n */\nexport function getV3SpanAttributes(\n ns: string,\n topology: MongoInternalTopology,\n command?: MongoInternalCommand,\n operation?: string | undefined,\n): SpanAttributes {\n let host: undefined | string;\n let port: undefined | string;\n if (topology?.s) {\n host = topology.s.options?.host ?? topology.s.host;\n port = (topology.s.options?.port ?? topology.s.port)?.toString();\n if (host == null || port == null) {\n const address = topology.description?.address;\n if (address) {\n const addressSegments = address.split(':');\n host = addressSegments[0];\n port = addressSegments[1];\n }\n }\n }\n\n // The namespace is a combination of the database name and the name of the\n // collection or index, like so: [database-name].[collection-or-index-name].\n // It could be a string or an instance of MongoDBNamespace, as such we\n // always coerce to a string to extract db and collection.\n const [dbName, dbCollection] = ns.toString().split('.');\n const commandObj = command?.query ?? command?.q ?? command;\n\n return getSpanAttributes(dbName, dbCollection, host, port, commandObj, operation);\n}\n\nfunction getSpanAttributes(\n dbName?: string,\n dbCollection?: string,\n host?: undefined | string,\n port?: undefined | string,\n commandObj?: any,\n operation?: string | undefined,\n): SpanAttributes {\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_SYSTEM]: DB_SYSTEM_VALUE_MONGODB,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_NAME]: dbName,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_MONGODB_COLLECTION]: dbCollection,\n // eslint-disable-next-line typescript/no-deprecated\n [DB_OPERATION]: operation,\n // eslint-disable-next-line typescript/no-deprecated\n [ATTR_DB_CONNECTION_STRING]: `mongodb://${host}:${port}/${dbName}`,\n };\n\n if (host && port) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[NET_PEER_NAME] = host;\n const portNumber = parseInt(port, 10);\n if (!isNaN(portNumber)) {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[NET_PEER_PORT] = portNumber;\n }\n }\n\n if (commandObj) {\n try {\n // eslint-disable-next-line typescript/no-deprecated\n attributes[DB_STATEMENT] = serializeDbStatement(commandObj);\n } catch {\n // ignore serialization errors — the statement is best-effort metadata\n }\n }\n\n return attributes;\n}\n\nexport function startMongoSpan(attributes: SpanAttributes): Span {\n return startInactiveSpan({\n // eslint-disable-next-line typescript/no-deprecated\n name: `mongodb.${attributes[DB_OPERATION] || 'command'}`,\n kind: SPAN_KIND.CLIENT,\n attributes,\n });\n}\n\n/**\n * Wraps the result handler so it ends the span (with error status on failure) and runs the\n * original callback re-activated under the parent span — mongodb loses the async context when\n * it invokes the callback on a later tick.\n */\nexport function patchEnd(span: Span | undefined, resultHandler: Function): Function {\n const parentSpan = getActiveSpan();\n let spanEnded = false;\n\n return function patchedEnd(this: {}, ...args: unknown[]) {\n if (!spanEnded) {\n spanEnded = true;\n const error = args[0];\n if (span) {\n if (error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n span.end();\n }\n }\n\n return withActiveSpan(parentSpan ?? null, () => resultHandler.apply(this, args));\n };\n}\n\n// The instrumentation only creates spans when there is an active parent span, to avoid emitting\n// orphaned mongodb spans.\nexport function shouldSkipInstrumentation(): boolean {\n return !getActiveSpan();\n}\n"],"names":[],"mappings":";;;;;AAgCA,MAAM,MAAA,GAAS,oBAAA;AAKf,SAAS,qBAAqB,UAAA,EAA6C;AACzE,EAAA,OAAO,IAAA,CAAK,SAAA,CAAU,cAAA,CAAe,UAAU,CAAC,CAAA;AAClD;AAEA,SAAS,eAAe,KAAA,EAAyB;AAC/C,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAA,OAAA,KAAW,cAAA,CAAe,OAAO,CAAC,CAAA;AAAA,EACrD;AAEA,EAAA,IAAI,YAAA,CAAa,KAAK,CAAA,EAAG;AACvB,IAAA,MAAM,UAAmC,EAAC;AAC1C,IAAA,OAAO,MAAA,CAAO,QAAQ,KAAK,CAAA,CACxB,IAAI,CAAC,CAAC,KAAK,OAAO,CAAA,KAAM,CAAC,GAAA,EAAK,cAAA,CAAe,OAAO,CAAC,CAAC,EACtD,MAAA,CAAO,CAAC,MAAM,OAAA,KAAY;AACzB,MAAA,IAAI,cAAA,CAAe,OAAO,CAAA,EAAG;AAC3B,QAAA,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAC,CAAA,GAAI,QAAQ,CAAC,CAAA;AAAA,MAC9B;AACA,MAAA,OAAO,IAAA;AAAA,IACT,GAAG,OAAO,CAAA;AAAA,EACd;AAGA,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,aAAa,KAAA,EAA4E;AAChG,EAAA,OAAO,YAAA,CAAa,KAAK,CAAA,IAAK,CAAC,SAAS,KAAK,CAAA;AAC/C;AAEA,SAAS,SAAS,KAAA,EAAyB;AACzC,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,SAAS,KAA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IAChB;AAAA,GACD,CAAA;AACH;AAOO,SAAS,QAAA,CAAS,MAAwB,aAAA,EAAmC;AAClF,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,SAAA,GAAY,KAAA;AAEhB,EAAA,OAAO,SAAS,cAAwB,IAAA,EAAiB;AACvD,IAAA,IAAI,CAAC,SAAA,EAAW;AACd,MAAA,SAAA,GAAY,IAAA;AACZ,MAAA,MAAM,KAAA,GAAQ,KAAK,CAAC,CAAA;AACpB,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,mBAAmB,OAAA,EAAS,KAAA,CAAM,SAAS,CAAA;AAAA,QACpE;AACA,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IACF;AAEA,IAAA,OAAO,cAAA,CAAe,cAAc,IAAA,EAAM,MAAM,cAAc,KAAA,CAAM,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACjF,CAAA;AACF;AAIO,SAAS,yBAAA,GAAqC;AACnD,EAAA,OAAO,CAAC,aAAA,EAAc;AACxB;;;;"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { MongooseInstrumentation } from './vendored/mongoose.js';
|
|
2
|
-
import { defineIntegration } from '@sentry/core';
|
|
2
|
+
import { defineIntegration, extendIntegration } from '@sentry/core';
|
|
3
3
|
import { generateInstrumentOnce } from '@sentry/node-core';
|
|
4
|
+
import { mongooseIntegration as mongooseIntegration$1 } from '@sentry/server-utils';
|
|
4
5
|
|
|
5
6
|
const INTEGRATION_NAME = "Mongoose";
|
|
6
7
|
const instrumentMongoose = generateInstrumentOnce(INTEGRATION_NAME, () => new MongooseInstrumentation());
|
|
7
8
|
const _mongooseIntegration = (() => {
|
|
8
|
-
return {
|
|
9
|
+
return extendIntegration(mongooseIntegration$1(), {
|
|
9
10
|
name: INTEGRATION_NAME,
|
|
10
11
|
setupOnce() {
|
|
11
12
|
instrumentMongoose();
|
|
12
13
|
}
|
|
13
|
-
};
|
|
14
|
+
});
|
|
14
15
|
});
|
|
15
16
|
const mongooseIntegration = defineIntegration(_mongooseIntegration);
|
|
16
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/mongoose/index.ts"],"sourcesContent":["import { MongooseInstrumentation } from './vendored/mongoose';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\n\nconst INTEGRATION_NAME = 'Mongoose' as const;\n\nexport const instrumentMongoose = generateInstrumentOnce(INTEGRATION_NAME, () => new MongooseInstrumentation());\n\nconst _mongooseIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentMongoose();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [mongoose](https://www.npmjs.com/package/mongoose) library.\n *\n * For more information, see the [`mongooseIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/mongoose/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.mongooseIntegration()],\n * });\n * ```\n */\nexport const mongooseIntegration = defineIntegration(_mongooseIntegration);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/mongoose/index.ts"],"sourcesContent":["import { MongooseInstrumentation } from './vendored/mongoose';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, extendIntegration } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { mongooseIntegration as mongooseChannelIntegration } from '@sentry/server-utils';\n\nconst INTEGRATION_NAME = 'Mongoose' as const;\n\nexport const instrumentMongoose = generateInstrumentOnce(INTEGRATION_NAME, () => new MongooseInstrumentation());\n\nconst _mongooseIntegration = (() => {\n // The diagnostics_channel subscription (mongoose >= 9.7) lives in server-utils so it is shared\n // across server runtimes; we extend it here to also run the IITM-based patcher for mongoose < 9.7.\n return extendIntegration(mongooseChannelIntegration(), {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentMongoose();\n },\n });\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [mongoose](https://www.npmjs.com/package/mongoose) library.\n *\n * For more information, see the [`mongooseIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/mongoose/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.mongooseIntegration()],\n * });\n * ```\n */\nexport const mongooseIntegration = defineIntegration(_mongooseIntegration);\n"],"names":["mongooseChannelIntegration"],"mappings":";;;;;AAMA,MAAM,gBAAA,GAAmB,UAAA;AAElB,MAAM,qBAAqB,sBAAA,CAAuB,gBAAA,EAAkB,MAAM,IAAI,yBAAyB;AAE9G,MAAM,wBAAwB,MAAM;AAGlC,EAAA,OAAO,iBAAA,CAAkBA,uBAA2B,EAAG;AAAA,IACrD,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,kBAAA,EAAmB;AAAA,IACrB;AAAA,GACD,CAAA;AACH,CAAA,CAAA;AAgBO,MAAM,mBAAA,GAAsB,kBAAkB,oBAAoB;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { DB_SYSTEM, DB_OPERATION } from '@sentry/conventions/attributes';
|
|
2
3
|
import { SDK_VERSION, getActiveSpan, startInactiveSpan, SPAN_KIND, withActiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
3
|
-
import { ATTR_DB_SYSTEM, ATTR_DB_OPERATION } from './semconv.js';
|
|
4
4
|
import { getAttributesFromCollection, handleCallbackResponse, handlePromiseResponse } from './utils.js';
|
|
5
5
|
|
|
6
6
|
const PACKAGE_NAME = "@sentry/instrumentation-mongoose";
|
|
@@ -52,7 +52,10 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
52
52
|
init() {
|
|
53
53
|
const module = new InstrumentationNodeModuleDefinition(
|
|
54
54
|
"mongoose",
|
|
55
|
-
|
|
55
|
+
// mongoose >= 9.7.0 publishes via diagnostics_channel and is instrumented by
|
|
56
|
+
// `subscribeMongooseDiagnosticChannels` instead, so this IITM patcher must not
|
|
57
|
+
// overlap it — otherwise every operation would emit two mongoose spans.
|
|
58
|
+
[">=5.9.7 <9.7.0"],
|
|
56
59
|
this.patch.bind(this),
|
|
57
60
|
this.unpatch.bind(this)
|
|
58
61
|
);
|
|
@@ -193,10 +196,10 @@ class MongooseInstrumentation extends InstrumentationBase {
|
|
|
193
196
|
_startSpan(collection, modelName, operation, parentSpan) {
|
|
194
197
|
const attributes = {
|
|
195
198
|
...getAttributesFromCollection(collection),
|
|
196
|
-
//
|
|
197
|
-
[
|
|
198
|
-
//
|
|
199
|
-
[
|
|
199
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
200
|
+
[DB_OPERATION]: operation,
|
|
201
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
202
|
+
[DB_SYSTEM]: "mongoose",
|
|
200
203
|
// keep for backwards compatibility
|
|
201
204
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
|
|
202
205
|
};
|