@sentry/server-utils 10.65.0 → 10.66.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/graphql/graphql-dc-subscriber.js +2 -4
- package/build/cjs/graphql/graphql-dc-subscriber.js.map +1 -1
- package/build/cjs/graphql/utils.js +7 -1
- package/build/cjs/graphql/utils.js.map +1 -1
- package/build/cjs/index.js +11 -8
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/dataloader.js +95 -0
- package/build/cjs/integrations/tracing-channel/dataloader.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/generic-pool.js +34 -0
- package/build/cjs/integrations/tracing-channel/generic-pool.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/graphql/spans.js +2 -2
- package/build/cjs/integrations/tracing-channel/graphql/spans.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/ioredis.js +29 -26
- package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/kafkajs/consumer.js +71 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/consumer.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/index.js +70 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/index.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/semconv.js +22 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/semconv.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/spans.js +119 -0
- package/build/cjs/integrations/tracing-channel/kafkajs/spans.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/knex.js +188 -0
- package/build/cjs/integrations/tracing-channel/knex.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/mysql2.js +83 -0
- package/build/cjs/integrations/tracing-channel/mysql2.js.map +1 -0
- package/build/cjs/orchestrion/bundler/esbuild.js +11 -0
- package/build/cjs/orchestrion/bundler/esbuild.js.map +1 -0
- package/build/cjs/orchestrion/bundler/options.js +15 -0
- package/build/cjs/orchestrion/bundler/options.js.map +1 -0
- package/build/cjs/orchestrion/bundler/rollup.js +11 -0
- package/build/cjs/orchestrion/bundler/rollup.js.map +1 -0
- package/build/cjs/orchestrion/bundler/vite.js +4 -21
- package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
- package/build/cjs/orchestrion/bundler/webpack.js +32 -0
- package/build/cjs/orchestrion/bundler/webpack.js.map +1 -0
- package/build/cjs/orchestrion/channels.js +50 -20
- package/build/cjs/orchestrion/channels.js.map +1 -1
- package/build/cjs/orchestrion/config/dataloader.js +53 -0
- package/build/cjs/orchestrion/config/dataloader.js.map +1 -0
- package/build/cjs/orchestrion/config/firebase.js +8 -0
- package/build/cjs/orchestrion/config/firebase.js.map +1 -0
- package/build/cjs/orchestrion/config/generic-pool.js +21 -0
- package/build/cjs/orchestrion/config/generic-pool.js.map +1 -0
- package/build/cjs/orchestrion/config/index.js +55 -23
- package/build/cjs/orchestrion/config/index.js.map +1 -1
- package/build/cjs/orchestrion/config/kafkajs.js +30 -0
- package/build/cjs/orchestrion/config/kafkajs.js.map +1 -0
- package/build/cjs/orchestrion/config/knex.js +43 -0
- package/build/cjs/orchestrion/config/knex.js.map +1 -0
- package/build/cjs/orchestrion/config/langchain.js +8 -0
- package/build/cjs/orchestrion/config/langchain.js.map +1 -0
- package/build/cjs/orchestrion/config/langgraph.js +8 -0
- package/build/cjs/orchestrion/config/langgraph.js.map +1 -0
- package/build/cjs/orchestrion/config/mongodb.js +8 -0
- package/build/cjs/orchestrion/config/mongodb.js.map +1 -0
- package/build/cjs/orchestrion/config/mongoose.js +8 -0
- package/build/cjs/orchestrion/config/mongoose.js.map +1 -0
- package/build/cjs/orchestrion/config/mysql2.js +32 -0
- package/build/cjs/orchestrion/config/mysql2.js.map +1 -0
- package/build/cjs/orchestrion/config/nestjs.js +122 -0
- package/build/cjs/orchestrion/config/nestjs.js.map +1 -0
- package/build/cjs/orchestrion/config/prisma.js +8 -0
- package/build/cjs/orchestrion/config/prisma.js.map +1 -0
- package/build/cjs/orchestrion/config/react-router.js +8 -0
- package/build/cjs/orchestrion/config/react-router.js.map +1 -0
- package/build/cjs/orchestrion/config/remix.js +8 -0
- package/build/cjs/orchestrion/config/remix.js.map +1 -0
- package/build/cjs/orchestrion/config/tedious.js +8 -0
- package/build/cjs/orchestrion/config/tedious.js.map +1 -0
- package/build/cjs/orchestrion/detect.js +12 -11
- package/build/cjs/orchestrion/detect.js.map +1 -1
- package/build/cjs/orchestrion/index.js +16 -1
- package/build/cjs/orchestrion/index.js.map +1 -1
- package/build/cjs/orchestrion/runtime/register.js +25 -14
- package/build/cjs/orchestrion/runtime/register.js.map +1 -1
- package/build/cjs/prisma/global.js +14 -0
- package/build/cjs/prisma/global.js.map +1 -0
- package/build/cjs/prisma/index.js +27 -0
- package/build/cjs/prisma/index.js.map +1 -0
- package/build/cjs/prisma/tracing-helper.js +211 -0
- package/build/cjs/prisma/tracing-helper.js.map +1 -0
- package/build/cjs/vercel-ai/util.js +0 -11
- package/build/cjs/vercel-ai/util.js.map +1 -1
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +9 -9
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/esm/graphql/graphql-dc-subscriber.js +3 -5
- package/build/esm/graphql/graphql-dc-subscriber.js.map +1 -1
- package/build/esm/graphql/utils.js +8 -2
- package/build/esm/graphql/utils.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/tracing-channel/dataloader.js +93 -0
- package/build/esm/integrations/tracing-channel/dataloader.js.map +1 -0
- package/build/esm/integrations/tracing-channel/generic-pool.js +32 -0
- package/build/esm/integrations/tracing-channel/generic-pool.js.map +1 -0
- package/build/esm/integrations/tracing-channel/graphql/spans.js +3 -3
- package/build/esm/integrations/tracing-channel/graphql/spans.js.map +1 -1
- package/build/esm/integrations/tracing-channel/ioredis.js +29 -27
- package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -1
- package/build/esm/integrations/tracing-channel/kafkajs/consumer.js +67 -0
- package/build/esm/integrations/tracing-channel/kafkajs/consumer.js.map +1 -0
- package/build/esm/integrations/tracing-channel/kafkajs/index.js +68 -0
- package/build/esm/integrations/tracing-channel/kafkajs/index.js.map +1 -0
- package/build/esm/integrations/tracing-channel/kafkajs/semconv.js +12 -0
- package/build/esm/integrations/tracing-channel/kafkajs/semconv.js.map +1 -0
- package/build/esm/integrations/tracing-channel/kafkajs/spans.js +112 -0
- package/build/esm/integrations/tracing-channel/kafkajs/spans.js.map +1 -0
- package/build/esm/integrations/tracing-channel/knex.js +186 -0
- package/build/esm/integrations/tracing-channel/knex.js.map +1 -0
- package/build/esm/integrations/tracing-channel/mysql2.js +81 -0
- package/build/esm/integrations/tracing-channel/mysql2.js.map +1 -0
- package/build/esm/orchestrion/bundler/esbuild.js +9 -0
- package/build/esm/orchestrion/bundler/esbuild.js.map +1 -0
- package/build/esm/orchestrion/bundler/options.js +13 -0
- package/build/esm/orchestrion/bundler/options.js.map +1 -0
- package/build/esm/orchestrion/bundler/rollup.js +9 -0
- package/build/esm/orchestrion/bundler/rollup.js.map +1 -0
- package/build/esm/orchestrion/bundler/vite.js +5 -22
- package/build/esm/orchestrion/bundler/vite.js.map +1 -1
- package/build/esm/orchestrion/bundler/webpack.js +27 -0
- package/build/esm/orchestrion/bundler/webpack.js.map +1 -0
- package/build/esm/orchestrion/channels.js +50 -20
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config/dataloader.js +50 -0
- package/build/esm/orchestrion/config/dataloader.js.map +1 -0
- package/build/esm/orchestrion/config/firebase.js +5 -0
- package/build/esm/orchestrion/config/firebase.js.map +1 -0
- package/build/esm/orchestrion/config/generic-pool.js +18 -0
- package/build/esm/orchestrion/config/generic-pool.js.map +1 -0
- package/build/esm/orchestrion/config/index.js +55 -24
- package/build/esm/orchestrion/config/index.js.map +1 -1
- package/build/esm/orchestrion/config/kafkajs.js +27 -0
- package/build/esm/orchestrion/config/kafkajs.js.map +1 -0
- package/build/esm/orchestrion/config/knex.js +40 -0
- package/build/esm/orchestrion/config/knex.js.map +1 -0
- package/build/esm/orchestrion/config/langchain.js +5 -0
- package/build/esm/orchestrion/config/langchain.js.map +1 -0
- package/build/esm/orchestrion/config/langgraph.js +5 -0
- package/build/esm/orchestrion/config/langgraph.js.map +1 -0
- package/build/esm/orchestrion/config/mongodb.js +5 -0
- package/build/esm/orchestrion/config/mongodb.js.map +1 -0
- package/build/esm/orchestrion/config/mongoose.js +5 -0
- package/build/esm/orchestrion/config/mongoose.js.map +1 -0
- package/build/esm/orchestrion/config/mysql2.js +29 -0
- package/build/esm/orchestrion/config/mysql2.js.map +1 -0
- package/build/esm/orchestrion/config/nestjs.js +119 -0
- package/build/esm/orchestrion/config/nestjs.js.map +1 -0
- package/build/esm/orchestrion/config/prisma.js +5 -0
- package/build/esm/orchestrion/config/prisma.js.map +1 -0
- package/build/esm/orchestrion/config/react-router.js +5 -0
- package/build/esm/orchestrion/config/react-router.js.map +1 -0
- package/build/esm/orchestrion/config/remix.js +5 -0
- package/build/esm/orchestrion/config/remix.js.map +1 -0
- package/build/esm/orchestrion/config/tedious.js +5 -0
- package/build/esm/orchestrion/config/tedious.js.map +1 -0
- package/build/esm/orchestrion/detect.js +13 -12
- package/build/esm/orchestrion/detect.js.map +1 -1
- package/build/esm/orchestrion/index.js +11 -2
- package/build/esm/orchestrion/index.js.map +1 -1
- package/build/esm/orchestrion/runtime/register.js +27 -16
- package/build/esm/orchestrion/runtime/register.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/prisma/global.js +12 -0
- package/build/esm/prisma/global.js.map +1 -0
- package/build/esm/prisma/index.js +24 -0
- package/build/esm/prisma/index.js.map +1 -0
- package/build/esm/prisma/tracing-helper.js +209 -0
- package/build/esm/prisma/tracing-helper.js.map +1 -0
- package/build/esm/vercel-ai/util.js +1 -11
- package/build/esm/vercel-ai/util.js.map +1 -1
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +11 -11
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/types/graphql/utils.d.ts +2 -6
- package/build/types/graphql/utils.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/dataloader.d.ts +11 -0
- package/build/types/integrations/tracing-channel/dataloader.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/generic-pool.d.ts +10 -0
- package/build/types/integrations/tracing-channel/generic-pool.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/ioredis.d.ts +20 -0
- package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/kafkajs/consumer.d.ts +8 -0
- package/build/types/integrations/tracing-channel/kafkajs/consumer.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/kafkajs/index.d.ts +17 -0
- package/build/types/integrations/tracing-channel/kafkajs/index.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/kafkajs/semconv.d.ts +10 -0
- package/build/types/integrations/tracing-channel/kafkajs/semconv.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/kafkajs/spans.d.ts +38 -0
- package/build/types/integrations/tracing-channel/kafkajs/spans.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/kafkajs/types.d.ts +40 -0
- package/build/types/integrations/tracing-channel/kafkajs/types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/knex.d.ts +11 -0
- package/build/types/integrations/tracing-channel/knex.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/mysql2.d.ts +15 -0
- package/build/types/integrations/tracing-channel/mysql2.d.ts.map +1 -0
- package/build/types/orchestrion/bundler/esbuild.d.ts +21 -0
- package/build/types/orchestrion/bundler/esbuild.d.ts.map +1 -0
- package/build/types/orchestrion/bundler/options.d.ts +19 -0
- package/build/types/orchestrion/bundler/options.d.ts.map +1 -0
- package/build/types/orchestrion/bundler/rollup.d.ts +17 -0
- package/build/types/orchestrion/bundler/rollup.d.ts.map +1 -0
- package/build/types/orchestrion/bundler/vite.d.ts +4 -17
- package/build/types/orchestrion/bundler/vite.d.ts.map +1 -1
- package/build/types/orchestrion/bundler/webpack.d.ts +19 -0
- package/build/types/orchestrion/bundler/webpack.d.ts.map +1 -0
- package/build/types/orchestrion/channels.d.ts +64 -37
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/dataloader.d.ts +46 -0
- package/build/types/orchestrion/config/dataloader.d.ts.map +1 -0
- package/build/types/orchestrion/config/firebase.d.ts +4 -0
- package/build/types/orchestrion/config/firebase.d.ts.map +1 -0
- package/build/types/orchestrion/config/generic-pool.d.ts +31 -0
- package/build/types/orchestrion/config/generic-pool.d.ts.map +1 -0
- package/build/types/orchestrion/config/index.d.ts +18 -5
- package/build/types/orchestrion/config/index.d.ts.map +1 -1
- package/build/types/orchestrion/config/kafkajs.d.ts +17 -0
- package/build/types/orchestrion/config/kafkajs.d.ts.map +1 -0
- package/build/types/orchestrion/config/knex.d.ts +9 -0
- package/build/types/orchestrion/config/knex.d.ts.map +1 -0
- package/build/types/orchestrion/config/langchain.d.ts +4 -0
- package/build/types/orchestrion/config/langchain.d.ts.map +1 -0
- package/build/types/orchestrion/config/langgraph.d.ts +4 -0
- package/build/types/orchestrion/config/langgraph.d.ts.map +1 -0
- package/build/types/orchestrion/config/mongodb.d.ts +4 -0
- package/build/types/orchestrion/config/mongodb.d.ts.map +1 -0
- package/build/types/orchestrion/config/mongoose.d.ts +4 -0
- package/build/types/orchestrion/config/mongoose.d.ts.map +1 -0
- package/build/types/orchestrion/config/mysql2.d.ts +18 -0
- package/build/types/orchestrion/config/mysql2.d.ts.map +1 -0
- package/build/types/orchestrion/config/nestjs.d.ts +24 -0
- package/build/types/orchestrion/config/nestjs.d.ts.map +1 -0
- package/build/types/orchestrion/config/prisma.d.ts +4 -0
- package/build/types/orchestrion/config/prisma.d.ts.map +1 -0
- package/build/types/orchestrion/config/react-router.d.ts +4 -0
- package/build/types/orchestrion/config/react-router.d.ts.map +1 -0
- package/build/types/orchestrion/config/remix.d.ts +4 -0
- package/build/types/orchestrion/config/remix.d.ts.map +1 -0
- package/build/types/orchestrion/config/tedious.d.ts +4 -0
- package/build/types/orchestrion/config/tedious.d.ts.map +1 -0
- package/build/types/orchestrion/detect.d.ts +3 -10
- package/build/types/orchestrion/detect.d.ts.map +1 -1
- package/build/types/orchestrion/index.d.ts +25 -1
- package/build/types/orchestrion/index.d.ts.map +1 -1
- package/build/types/orchestrion/runtime/register.d.ts +11 -9
- package/build/types/orchestrion/runtime/register.d.ts.map +1 -1
- package/build/types/prisma/global.d.ts +5 -0
- package/build/types/prisma/global.d.ts.map +1 -0
- package/build/types/prisma/index.d.ts +45 -0
- package/build/types/prisma/index.d.ts.map +1 -0
- package/build/types/prisma/tracing-helper.d.ts +46 -0
- package/build/types/prisma/tracing-helper.d.ts.map +1 -0
- package/build/types/prisma/types.d.ts +37 -0
- package/build/types/prisma/types.d.ts.map +1 -0
- package/build/types/vercel-ai/util.d.ts +0 -2
- package/build/types/vercel-ai/util.d.ts.map +1 -1
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
- package/build/types-ts3.8/graphql/utils.d.ts +2 -6
- package/build/types-ts3.8/index.d.ts +2 -0
- package/build/types-ts3.8/integrations/tracing-channel/dataloader.d.ts +11 -0
- package/build/types-ts3.8/integrations/tracing-channel/generic-pool.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/ioredis.d.ts +20 -0
- package/build/types-ts3.8/integrations/tracing-channel/kafkajs/consumer.d.ts +8 -0
- package/build/types-ts3.8/integrations/tracing-channel/kafkajs/index.d.ts +17 -0
- package/build/types-ts3.8/integrations/tracing-channel/kafkajs/semconv.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/kafkajs/spans.d.ts +38 -0
- package/build/types-ts3.8/integrations/tracing-channel/kafkajs/types.d.ts +40 -0
- package/build/types-ts3.8/integrations/tracing-channel/knex.d.ts +11 -0
- package/build/types-ts3.8/integrations/tracing-channel/mysql2.d.ts +15 -0
- package/build/types-ts3.8/orchestrion/bundler/esbuild.d.ts +21 -0
- package/build/types-ts3.8/orchestrion/bundler/options.d.ts +19 -0
- package/build/types-ts3.8/orchestrion/bundler/rollup.d.ts +17 -0
- package/build/types-ts3.8/orchestrion/bundler/vite.d.ts +4 -17
- package/build/types-ts3.8/orchestrion/bundler/webpack.d.ts +19 -0
- package/build/types-ts3.8/orchestrion/channels.d.ts +64 -37
- package/build/types-ts3.8/orchestrion/config/dataloader.d.ts +46 -0
- package/build/types-ts3.8/orchestrion/config/firebase.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/generic-pool.d.ts +31 -0
- package/build/types-ts3.8/orchestrion/config/index.d.ts +18 -5
- package/build/types-ts3.8/orchestrion/config/kafkajs.d.ts +17 -0
- package/build/types-ts3.8/orchestrion/config/knex.d.ts +9 -0
- package/build/types-ts3.8/orchestrion/config/langchain.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/langgraph.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/mongodb.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/mongoose.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/mysql2.d.ts +18 -0
- package/build/types-ts3.8/orchestrion/config/nestjs.d.ts +24 -0
- package/build/types-ts3.8/orchestrion/config/prisma.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/react-router.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/remix.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/config/tedious.d.ts +4 -0
- package/build/types-ts3.8/orchestrion/detect.d.ts +3 -10
- package/build/types-ts3.8/orchestrion/index.d.ts +25 -1
- package/build/types-ts3.8/orchestrion/runtime/register.d.ts +11 -9
- package/build/types-ts3.8/prisma/global.d.ts +5 -0
- package/build/types-ts3.8/prisma/index.d.ts +45 -0
- package/build/types-ts3.8/prisma/tracing-helper.d.ts +52 -0
- package/build/types-ts3.8/prisma/types.d.ts +40 -0
- package/build/types-ts3.8/vercel-ai/util.d.ts +0 -2
- package/package.json +41 -8
|
@@ -49,13 +49,12 @@ function setupValidateChannel(tracingChannel$1) {
|
|
|
49
49
|
tracingChannel.bindTracingChannelToSpan(
|
|
50
50
|
tracingChannel$1(GRAPHQL_DC_CHANNEL_VALIDATE),
|
|
51
51
|
(data) => {
|
|
52
|
-
const document = utils.redactGraphqlDocument(data.document);
|
|
53
52
|
return core.startInactiveSpan({
|
|
54
53
|
name: SPAN_NAME_VALIDATE,
|
|
55
54
|
attributes: {
|
|
56
55
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
57
56
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op.WEB_SERVER_GRAPHQL_SPAN_OP,
|
|
58
|
-
[attributes.GRAPHQL_DOCUMENT]: document
|
|
57
|
+
[attributes.GRAPHQL_DOCUMENT]: utils.collectGraphqlDocument(data.document)
|
|
59
58
|
}
|
|
60
59
|
});
|
|
61
60
|
},
|
|
@@ -72,7 +71,6 @@ function setupOperationChannel(tracingChannel$1, channelName, fallbackName, useO
|
|
|
72
71
|
tracingChannel.bindTracingChannelToSpan(
|
|
73
72
|
tracingChannel$1(channelName),
|
|
74
73
|
(data) => {
|
|
75
|
-
const document = utils.redactGraphqlDocument(data.document);
|
|
76
74
|
const span = core.startInactiveSpan({
|
|
77
75
|
name: utils.getOperationSpanName(data.operationType, data.operationName, fallbackName),
|
|
78
76
|
attributes: {
|
|
@@ -80,7 +78,7 @@ function setupOperationChannel(tracingChannel$1, channelName, fallbackName, useO
|
|
|
80
78
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op.WEB_SERVER_GRAPHQL_SPAN_OP,
|
|
81
79
|
[attributes.GRAPHQL_OPERATION_TYPE]: data.operationType,
|
|
82
80
|
[attributes.GRAPHQL_OPERATION_NAME]: data.operationName || void 0,
|
|
83
|
-
[attributes.GRAPHQL_DOCUMENT]: document
|
|
81
|
+
[attributes.GRAPHQL_DOCUMENT]: utils.collectGraphqlDocument(data.document)
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
84
|
if (useOperationNameForRootSpan && data.operationType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql-dc-subscriber.js","sources":["../../../src/graphql/graphql-dc-subscriber.ts"],"sourcesContent":["import type { TracingChannel } from 'node:diagnostics_channel';\nimport { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport type { GraphqlDocumentNode } from './utils';\nimport { getOperationSpanName, hasResultErrors, redactGraphqlDocument, renameRootSpanWithOperation } from './utils';\n\n// Channel names published by graphql >= 17.0.0 (see graphql-js `src/diagnostics.ts`).\n// Hardcoded so the subscriber does not have to import graphql — the channels just\n// have to be subscribed to before the user's graphql code publishes.\nexport const GRAPHQL_DC_CHANNEL_PARSE = 'graphql:parse';\nexport const GRAPHQL_DC_CHANNEL_VALIDATE = 'graphql:validate';\nexport const GRAPHQL_DC_CHANNEL_EXECUTE = 'graphql:execute';\nexport const GRAPHQL_DC_CHANNEL_SUBSCRIBE = 'graphql:subscribe';\nexport const GRAPHQL_DC_CHANNEL_RESOLVE = 'graphql:resolve';\n\nconst ORIGIN = 'auto.graphql.diagnostic_channel';\n\nconst SPAN_NAME_PARSE = 'graphql.parse';\nconst SPAN_NAME_VALIDATE = 'graphql.validate';\nconst SPAN_NAME_EXECUTE = 'graphql.execute';\nconst SPAN_NAME_SUBSCRIBE = 'graphql.subscribe';\nconst SPAN_NAME_RESOLVE = 'graphql.resolve';\n\n// Field-level attributes for resolver spans. Not in `@sentry/conventions`; these match the keys the\n// vendored OTel instrumentation emits so there is no drift between the two paths.\nconst GRAPHQL_FIELD_NAME = 'graphql.field.name';\nconst GRAPHQL_FIELD_PATH = 'graphql.field.path';\nconst GRAPHQL_FIELD_TYPE = 'graphql.field.type';\nconst GRAPHQL_PARENT_NAME = 'graphql.parent.name';\n\n/** Context published on the sync-only `graphql:parse` channel. */\nexport interface GraphqlParseData {\n source: string | { body?: string };\n result?: GraphqlDocumentNode;\n error?: unknown;\n}\n\n/** Context published on the sync-only `graphql:validate` channel. */\nexport interface GraphqlValidateData {\n document: GraphqlDocumentNode;\n /** Validation errors returned by validation; an empty array means the document is valid. */\n result?: ReadonlyArray<unknown>;\n error?: unknown;\n}\n\n/**\n * Context published on the `graphql:execute` and `graphql:subscribe` channels.\n *\n * `result` carries an `ExecutionResult` (or, for subscriptions, an async generator); GraphQL errors\n * collected during execution surface on `result.errors` rather than as the channel's `error`\n * lifecycle event, which only fires on an abrupt throw.\n */\nexport interface GraphqlOperationData {\n document: GraphqlDocumentNode;\n operationName?: string;\n operationType?: string;\n result?: unknown;\n error?: unknown;\n}\n\n/**\n * Context published on the per-field `graphql:resolve` channel.\n *\n * A resolver throw or rejection publishes the `error` lifecycle event here; the same failure also\n * surfaces in the enclosing execution result.\n */\nexport interface GraphqlResolveData {\n fieldName: string;\n parentType: string;\n fieldType: string;\n fieldPath: string;\n /** Whether the field is handled by graphql's default property resolver (vs. a user resolver). */\n isDefaultResolver: boolean;\n alias?: string;\n args?: unknown;\n result?: unknown;\n error?: unknown;\n}\n\n/** Options controlling which graphql channels the subscriber emits spans for. */\nexport interface GraphqlDiagnosticChannelsOptions {\n /**\n * Do not create spans for resolvers. Resolver spans are per-field and can be very high volume.\n * Defaults to `true`.\n */\n ignoreResolveSpans?: boolean;\n\n /**\n * When resolver spans are enabled, do not create them for graphql's default property resolver\n * (fields without a user-defined resolver), which are rarely interesting. Defaults to `true`.\n */\n ignoreTrivialResolveSpans?: boolean;\n\n /**\n * Rename the enclosing root span to include the operation name(s), e.g.\n * `GET /graphql` -> `GET /graphql (query GetUser)`. Defaults to `true`.\n */\n useOperationNameForRootSpan?: boolean;\n}\n\n/**\n * Platform-provided factory that creates a native tracing channel for the given name. The\n * subscriber binds the span and its lifecycle onto the channel via `bindTracingChannelToSpan`,\n * which propagates the active span through the runtime's async context.\n *\n * Node passes `node:diagnostics_channel`'s `tracingChannel` directly.\n */\nexport type GraphqlTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;\n\n/**\n * Subscribe Sentry span handlers to graphql's diagnostics-channel events\n * (`graphql:parse`, `:validate`, `:execute`, `:subscribe`), published by graphql >= 17.0.0.\n *\n * On older graphql versions the channels are never published to, so the subscribers are inert —\n * there is no double-instrumentation against the vendored OTel patcher, which is gated to `< 17`.\n *\n * The per-field `graphql:resolve` channel is only subscribed when `ignoreResolveSpans` is `false`:\n * resolver spans are per-field and can be extremely high-volume, so they are off by default (matching\n * the legacy OTel path). When enabled, `ignoreTrivialResolveSpans` (default `true`) additionally skips\n * graphql's default property resolver.\n */\nexport function subscribeGraphqlDiagnosticChannels(\n tracingChannel: GraphqlTracingChannelFactory,\n options: GraphqlDiagnosticChannelsOptions = {},\n): void {\n const ignoreResolveSpans = options.ignoreResolveSpans !== false;\n const ignoreTrivialResolveSpans = options.ignoreTrivialResolveSpans !== false;\n const useOperationNameForRootSpan = options.useOperationNameForRootSpan !== false;\n\n setupParseChannel(tracingChannel);\n setupValidateChannel(tracingChannel);\n setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_EXECUTE, SPAN_NAME_EXECUTE, useOperationNameForRootSpan);\n setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_SUBSCRIBE, SPAN_NAME_SUBSCRIBE, useOperationNameForRootSpan);\n\n if (!ignoreResolveSpans) {\n setupResolveChannel(tracingChannel, ignoreTrivialResolveSpans);\n }\n}\n\nfunction setupParseChannel(tracingChannel: GraphqlTracingChannelFactory): void {\n bindTracingChannelToSpan(tracingChannel<GraphqlParseData>(GRAPHQL_DC_CHANNEL_PARSE), () =>\n startInactiveSpan({\n name: SPAN_NAME_PARSE,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n },\n }),\n );\n}\n\nfunction setupValidateChannel(tracingChannel: GraphqlTracingChannelFactory): void {\n bindTracingChannelToSpan(\n tracingChannel<GraphqlValidateData>(GRAPHQL_DC_CHANNEL_VALIDATE),\n data => {\n const document = redactGraphqlDocument(data.document);\n\n return startInactiveSpan({\n name: SPAN_NAME_VALIDATE,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_DOCUMENT]: document,\n },\n });\n },\n {\n beforeSpanEnd: (span, data) => {\n // Validation completes normally even when it returns errors, so flag the span here.\n if (Array.isArray(data.result) && data.result.length > 0) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'invalid_argument' });\n }\n },\n },\n );\n}\n\nfunction setupOperationChannel(\n tracingChannel: GraphqlTracingChannelFactory,\n channelName: string,\n fallbackName: string,\n useOperationNameForRootSpan: boolean,\n): void {\n bindTracingChannelToSpan(\n tracingChannel<GraphqlOperationData>(channelName),\n data => {\n const document = redactGraphqlDocument(data.document);\n\n const span = startInactiveSpan({\n name: getOperationSpanName(data.operationType, data.operationName, fallbackName),\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_OPERATION_TYPE]: data.operationType,\n [GRAPHQL_OPERATION_NAME]: data.operationName || undefined,\n [GRAPHQL_DOCUMENT]: document,\n },\n });\n\n if (useOperationNameForRootSpan && data.operationType) {\n renameRootSpanWithOperation(span, data.operationType, data.operationName);\n }\n\n return span;\n },\n {\n beforeSpanEnd: (span, data) => {\n // GraphQL errors are returned on `result.errors`, not as a thrown error, so flag the span here.\n if (hasResultErrors(data.result)) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n },\n },\n );\n}\n\nfunction setupResolveChannel(tracingChannel: GraphqlTracingChannelFactory, ignoreTrivialResolveSpans: boolean): void {\n bindTracingChannelToSpan(tracingChannel<GraphqlResolveData>(GRAPHQL_DC_CHANNEL_RESOLVE), data => {\n // Returning `undefined` opts this field out: no span is created and the active context is left\n // untouched, so the field still resolves under its parent span.\n if (ignoreTrivialResolveSpans && data.isDefaultResolver) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `${SPAN_NAME_RESOLVE} ${data.fieldPath}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_FIELD_NAME]: data.fieldName,\n [GRAPHQL_FIELD_PATH]: data.fieldPath,\n [GRAPHQL_FIELD_TYPE]: data.fieldType,\n [GRAPHQL_PARENT_NAME]: data.parentType,\n },\n });\n });\n}\n"],"names":["tracingChannel","bindTracingChannelToSpan","startInactiveSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","WEB_SERVER_GRAPHQL_SPAN_OP","redactGraphqlDocument","GRAPHQL_DOCUMENT","SPAN_STATUS_ERROR","getOperationSpanName","GRAPHQL_OPERATION_TYPE","GRAPHQL_OPERATION_NAME","renameRootSpanWithOperation","hasResultErrors"],"mappings":";;;;;;;;AAgBO,MAAM,wBAAA,GAA2B;AACjC,MAAM,2BAAA,GAA8B;AACpC,MAAM,0BAAA,GAA6B;A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QAC3B,CAAC,mBAAmB,GAAG,IAAA,CAAK;AAAA;AAC9B,KACD,CAAA;AAAA,EACH,CAAC,CAAA;AACH;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"graphql-dc-subscriber.js","sources":["../../../src/graphql/graphql-dc-subscriber.ts"],"sourcesContent":["import type { TracingChannel } from 'node:diagnostics_channel';\nimport { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport type { GraphqlDocumentNode } from './utils';\nimport { collectGraphqlDocument, getOperationSpanName, hasResultErrors, renameRootSpanWithOperation } from './utils';\n\n// Channel names published by graphql >= 17.0.0 (see graphql-js `src/diagnostics.ts`).\n// Hardcoded so the subscriber does not have to import graphql — the channels just\n// have to be subscribed to before the user's graphql code publishes.\nexport const GRAPHQL_DC_CHANNEL_PARSE = 'graphql:parse';\nexport const GRAPHQL_DC_CHANNEL_VALIDATE = 'graphql:validate';\nexport const GRAPHQL_DC_CHANNEL_EXECUTE = 'graphql:execute';\nexport const GRAPHQL_DC_CHANNEL_SUBSCRIBE = 'graphql:subscribe';\nexport const GRAPHQL_DC_CHANNEL_RESOLVE = 'graphql:resolve';\n\nconst ORIGIN = 'auto.graphql.diagnostic_channel';\n\nconst SPAN_NAME_PARSE = 'graphql.parse';\nconst SPAN_NAME_VALIDATE = 'graphql.validate';\nconst SPAN_NAME_EXECUTE = 'graphql.execute';\nconst SPAN_NAME_SUBSCRIBE = 'graphql.subscribe';\nconst SPAN_NAME_RESOLVE = 'graphql.resolve';\n\n// Field-level attributes for resolver spans. Not in `@sentry/conventions`; these match the keys the\n// vendored OTel instrumentation emits so there is no drift between the two paths.\nconst GRAPHQL_FIELD_NAME = 'graphql.field.name';\nconst GRAPHQL_FIELD_PATH = 'graphql.field.path';\nconst GRAPHQL_FIELD_TYPE = 'graphql.field.type';\nconst GRAPHQL_PARENT_NAME = 'graphql.parent.name';\n\n/** Context published on the sync-only `graphql:parse` channel. */\nexport interface GraphqlParseData {\n source: string | { body?: string };\n result?: GraphqlDocumentNode;\n error?: unknown;\n}\n\n/** Context published on the sync-only `graphql:validate` channel. */\nexport interface GraphqlValidateData {\n document: GraphqlDocumentNode;\n /** Validation errors returned by validation; an empty array means the document is valid. */\n result?: ReadonlyArray<unknown>;\n error?: unknown;\n}\n\n/**\n * Context published on the `graphql:execute` and `graphql:subscribe` channels.\n *\n * `result` carries an `ExecutionResult` (or, for subscriptions, an async generator); GraphQL errors\n * collected during execution surface on `result.errors` rather than as the channel's `error`\n * lifecycle event, which only fires on an abrupt throw.\n */\nexport interface GraphqlOperationData {\n document: GraphqlDocumentNode;\n operationName?: string;\n operationType?: string;\n result?: unknown;\n error?: unknown;\n}\n\n/**\n * Context published on the per-field `graphql:resolve` channel.\n *\n * A resolver throw or rejection publishes the `error` lifecycle event here; the same failure also\n * surfaces in the enclosing execution result.\n */\nexport interface GraphqlResolveData {\n fieldName: string;\n parentType: string;\n fieldType: string;\n fieldPath: string;\n /** Whether the field is handled by graphql's default property resolver (vs. a user resolver). */\n isDefaultResolver: boolean;\n alias?: string;\n args?: unknown;\n result?: unknown;\n error?: unknown;\n}\n\n/** Options controlling which graphql channels the subscriber emits spans for. */\nexport interface GraphqlDiagnosticChannelsOptions {\n /**\n * Do not create spans for resolvers. Resolver spans are per-field and can be very high volume.\n * Defaults to `true`.\n */\n ignoreResolveSpans?: boolean;\n\n /**\n * When resolver spans are enabled, do not create them for graphql's default property resolver\n * (fields without a user-defined resolver), which are rarely interesting. Defaults to `true`.\n */\n ignoreTrivialResolveSpans?: boolean;\n\n /**\n * Rename the enclosing root span to include the operation name(s), e.g.\n * `GET /graphql` -> `GET /graphql (query GetUser)`. Defaults to `true`.\n */\n useOperationNameForRootSpan?: boolean;\n}\n\n/**\n * Platform-provided factory that creates a native tracing channel for the given name. The\n * subscriber binds the span and its lifecycle onto the channel via `bindTracingChannelToSpan`,\n * which propagates the active span through the runtime's async context.\n *\n * Node passes `node:diagnostics_channel`'s `tracingChannel` directly.\n */\nexport type GraphqlTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;\n\n/**\n * Subscribe Sentry span handlers to graphql's diagnostics-channel events\n * (`graphql:parse`, `:validate`, `:execute`, `:subscribe`), published by graphql >= 17.0.0.\n *\n * On older graphql versions the channels are never published to, so the subscribers are inert —\n * there is no double-instrumentation against the vendored OTel patcher, which is gated to `< 17`.\n *\n * The per-field `graphql:resolve` channel is only subscribed when `ignoreResolveSpans` is `false`:\n * resolver spans are per-field and can be extremely high-volume, so they are off by default (matching\n * the legacy OTel path). When enabled, `ignoreTrivialResolveSpans` (default `true`) additionally skips\n * graphql's default property resolver.\n */\nexport function subscribeGraphqlDiagnosticChannels(\n tracingChannel: GraphqlTracingChannelFactory,\n options: GraphqlDiagnosticChannelsOptions = {},\n): void {\n const ignoreResolveSpans = options.ignoreResolveSpans !== false;\n const ignoreTrivialResolveSpans = options.ignoreTrivialResolveSpans !== false;\n const useOperationNameForRootSpan = options.useOperationNameForRootSpan !== false;\n\n setupParseChannel(tracingChannel);\n setupValidateChannel(tracingChannel);\n setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_EXECUTE, SPAN_NAME_EXECUTE, useOperationNameForRootSpan);\n setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_SUBSCRIBE, SPAN_NAME_SUBSCRIBE, useOperationNameForRootSpan);\n\n if (!ignoreResolveSpans) {\n setupResolveChannel(tracingChannel, ignoreTrivialResolveSpans);\n }\n}\n\nfunction setupParseChannel(tracingChannel: GraphqlTracingChannelFactory): void {\n bindTracingChannelToSpan(tracingChannel<GraphqlParseData>(GRAPHQL_DC_CHANNEL_PARSE), () =>\n startInactiveSpan({\n name: SPAN_NAME_PARSE,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n },\n }),\n );\n}\n\nfunction setupValidateChannel(tracingChannel: GraphqlTracingChannelFactory): void {\n bindTracingChannelToSpan(\n tracingChannel<GraphqlValidateData>(GRAPHQL_DC_CHANNEL_VALIDATE),\n data => {\n return startInactiveSpan({\n name: SPAN_NAME_VALIDATE,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_DOCUMENT]: collectGraphqlDocument(data.document),\n },\n });\n },\n {\n beforeSpanEnd: (span, data) => {\n // Validation completes normally even when it returns errors, so flag the span here.\n if (Array.isArray(data.result) && data.result.length > 0) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'invalid_argument' });\n }\n },\n },\n );\n}\n\nfunction setupOperationChannel(\n tracingChannel: GraphqlTracingChannelFactory,\n channelName: string,\n fallbackName: string,\n useOperationNameForRootSpan: boolean,\n): void {\n bindTracingChannelToSpan(\n tracingChannel<GraphqlOperationData>(channelName),\n data => {\n const span = startInactiveSpan({\n name: getOperationSpanName(data.operationType, data.operationName, fallbackName),\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_OPERATION_TYPE]: data.operationType,\n [GRAPHQL_OPERATION_NAME]: data.operationName || undefined,\n [GRAPHQL_DOCUMENT]: collectGraphqlDocument(data.document),\n },\n });\n\n if (useOperationNameForRootSpan && data.operationType) {\n renameRootSpanWithOperation(span, data.operationType, data.operationName);\n }\n\n return span;\n },\n {\n beforeSpanEnd: (span, data) => {\n // GraphQL errors are returned on `result.errors`, not as a thrown error, so flag the span here.\n if (hasResultErrors(data.result)) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n },\n },\n );\n}\n\nfunction setupResolveChannel(tracingChannel: GraphqlTracingChannelFactory, ignoreTrivialResolveSpans: boolean): void {\n bindTracingChannelToSpan(tracingChannel<GraphqlResolveData>(GRAPHQL_DC_CHANNEL_RESOLVE), data => {\n // Returning `undefined` opts this field out: no span is created and the active context is left\n // untouched, so the field still resolves under its parent span.\n if (ignoreTrivialResolveSpans && data.isDefaultResolver) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `${SPAN_NAME_RESOLVE} ${data.fieldPath}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n [GRAPHQL_FIELD_NAME]: data.fieldName,\n [GRAPHQL_FIELD_PATH]: data.fieldPath,\n [GRAPHQL_FIELD_TYPE]: data.fieldType,\n [GRAPHQL_PARENT_NAME]: data.parentType,\n },\n });\n });\n}\n"],"names":["tracingChannel","bindTracingChannelToSpan","startInactiveSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","WEB_SERVER_GRAPHQL_SPAN_OP","GRAPHQL_DOCUMENT","collectGraphqlDocument","SPAN_STATUS_ERROR","getOperationSpanName","GRAPHQL_OPERATION_TYPE","GRAPHQL_OPERATION_NAME","renameRootSpanWithOperation","hasResultErrors"],"mappings":";;;;;;;;AAgBO,MAAM,wBAAA,GAA2B;AACjC,MAAM,2BAAA,GAA8B;AACpC,MAAM,0BAAA,GAA6B;AACnC,MAAM,4BAAA,GAA+B;AACrC,MAAM,0BAAA,GAA6B;AAE1C,MAAM,MAAA,GAAS,iCAAA;AAEf,MAAM,eAAA,GAAkB,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
|
|
81
|
+
function collectGraphqlDocument(document) {
|
|
82
|
+
if (core.getClient()?.getDataCollectionOptions().graphQL.document !== true) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
return redactGraphqlDocument(document);
|
|
86
|
+
}
|
|
81
87
|
|
|
88
|
+
exports.collectGraphqlDocument = collectGraphqlDocument;
|
|
82
89
|
exports.getOperationSpanName = getOperationSpanName;
|
|
83
90
|
exports.hasResultErrors = hasResultErrors;
|
|
84
|
-
exports.redactGraphqlDocument = redactGraphqlDocument;
|
|
85
91
|
exports.renameRootSpanWithOperation = renameRootSpanWithOperation;
|
|
86
92
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/graphql/utils.ts"],"sourcesContent":["import { SENTRY_GRAPHQL_OPERATION } from '@sentry/conventions/attributes';\nimport type { Span } from '@sentry/core';\nimport { isObjectLike, getRootSpan, spanToJSON } from '@sentry/core';\n\n// Same key the OTel path uses, so renames stay consistent across both.\nconst ORIGINAL_DESCRIPTION_ATTRIBUTE = 'original-description';\n\n// graphql-js token kinds whose values may carry user data (literal arguments). We\n// replace them in the serialized document so raw inline values can never reach\n// `graphql.document`. Mirrors the legacy OTel instrumentation's redaction set.\nconst REDACTED_LITERAL_KINDS = new Set(['Int', 'Float', 'String', 'BlockString']);\n\n/** Minimal shape of a graphql-js lexer token, enough to locate literal spans for redaction. */\ninterface GraphqlToken {\n kind: string;\n start: number;\n end: number;\n next?: GraphqlToken | null;\n}\n\n/** Minimal shape of a parsed graphql-js `DocumentNode`, enough to read its source and tokens. */\nexport interface GraphqlDocumentNode {\n loc?: {\n startToken?: GraphqlToken;\n source?: { body?: string };\n };\n}\n\n/**\n * Rename the enclosing root span to include the operation name(s), e.g. `GET /graphql (query GetUser)`.\n * Mirrors the legacy OTel `useOperationNameForRootSpan` behavior; `parseSpanDescription` reads the same\n * `sentry.graphql.operation` attribute on the OTel export path.\n */\nexport function renameRootSpanWithOperation(span: Span, operationType: string, operationName?: string): void {\n const rootSpan = getRootSpan(span);\n // Nothing to rename if the operation span is itself the root (graphql ran outside any span).\n if (rootSpan === span) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n const newOperation = operationName ? `${operationType} ${operationName}` : operationType;\n\n // A single operation is stored as a string, multiple as an array.\n const existingOperations = rootSpanJson.data[SENTRY_GRAPHQL_OPERATION];\n let operations: string | string[];\n if (Array.isArray(existingOperations)) {\n operations = [...(existingOperations as string[]), newOperation];\n } else if (typeof existingOperations === 'string') {\n operations = [existingOperations, newOperation];\n } else {\n operations = newOperation;\n }\n rootSpan.setAttribute(SENTRY_GRAPHQL_OPERATION, operations);\n\n // Keep the pre-rename name so repeated renames don't compound.\n const originalDescription =\n (rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE] as string | undefined) ?? rootSpanJson.description;\n if (!rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE]) {\n rootSpan.setAttribute(ORIGINAL_DESCRIPTION_ATTRIBUTE, originalDescription);\n }\n\n rootSpan.updateName(`${originalDescription} (${getGraphqlOperationNamesFromAttribute(operations)})`);\n}\n\n/** Format the accumulated operations for the root span name: up to 5 sorted names, then `+N`. */\nfunction getGraphqlOperationNamesFromAttribute(attr: string | string[]): string {\n if (Array.isArray(attr)) {\n // oxlint-disable-next-line typescript/require-array-sort-compare\n const sorted = attr.slice().sort();\n if (sorted.length <= 5) {\n return sorted.join(', ');\n }\n\n return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;\n }\n\n return attr;\n}\n\n/**\n * Span name follows the GraphQL semantic conventions: `<operation.type> <operation.name>` when both\n * are available, `<operation.type>` when only the type is, otherwise a static fallback.\n */\nexport function getOperationSpanName(\n operationType: string | undefined,\n operationName: string | undefined,\n fallbackName: string,\n): string {\n if (operationType && operationName) {\n return `${operationType} ${operationName}`;\n }\n if (operationType) {\n return operationType;\n }\n\n return fallbackName;\n}\n\n/** Whether a graphql execution result carries GraphQL errors (returned on `result.errors`). */\nexport function hasResultErrors(result: unknown): boolean {\n if (isObjectLike(result) && 'errors' in result) {\n const errors = (result as { errors?: unknown }).errors;\n\n return Array.isArray(errors) && errors.length > 0;\n }\n\n return false;\n}\n\n/**\n * Serialize a parsed document into `graphql.document` while redacting every literal argument value:\n * the original source text is preserved verbatim except that string/number literal spans are\n * replaced (`\"foo\"` -> `\"*\"`, `42` -> `*`). graphql does not sanitize its channel payload, so this\n * prevents raw inline values (potential PII) from leaving the process. Variable values are never\n * included. Returns `undefined` (rather than throwing) on anything it cannot serialize.\n */\
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/graphql/utils.ts"],"sourcesContent":["import { SENTRY_GRAPHQL_OPERATION } from '@sentry/conventions/attributes';\nimport type { Span } from '@sentry/core';\nimport { getClient, isObjectLike, getRootSpan, spanToJSON } from '@sentry/core';\n\n// Same key the OTel path uses, so renames stay consistent across both.\nconst ORIGINAL_DESCRIPTION_ATTRIBUTE = 'original-description';\n\n// graphql-js token kinds whose values may carry user data (literal arguments). We\n// replace them in the serialized document so raw inline values can never reach\n// `graphql.document`. Mirrors the legacy OTel instrumentation's redaction set.\nconst REDACTED_LITERAL_KINDS = new Set(['Int', 'Float', 'String', 'BlockString']);\n\n/** Minimal shape of a graphql-js lexer token, enough to locate literal spans for redaction. */\ninterface GraphqlToken {\n kind: string;\n start: number;\n end: number;\n next?: GraphqlToken | null;\n}\n\n/** Minimal shape of a parsed graphql-js `DocumentNode`, enough to read its source and tokens. */\nexport interface GraphqlDocumentNode {\n loc?: {\n startToken?: GraphqlToken;\n source?: { body?: string };\n };\n}\n\n/**\n * Rename the enclosing root span to include the operation name(s), e.g. `GET /graphql (query GetUser)`.\n * Mirrors the legacy OTel `useOperationNameForRootSpan` behavior; `parseSpanDescription` reads the same\n * `sentry.graphql.operation` attribute on the OTel export path.\n */\nexport function renameRootSpanWithOperation(span: Span, operationType: string, operationName?: string): void {\n const rootSpan = getRootSpan(span);\n // Nothing to rename if the operation span is itself the root (graphql ran outside any span).\n if (rootSpan === span) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n const newOperation = operationName ? `${operationType} ${operationName}` : operationType;\n\n // A single operation is stored as a string, multiple as an array.\n const existingOperations = rootSpanJson.data[SENTRY_GRAPHQL_OPERATION];\n let operations: string | string[];\n if (Array.isArray(existingOperations)) {\n operations = [...(existingOperations as string[]), newOperation];\n } else if (typeof existingOperations === 'string') {\n operations = [existingOperations, newOperation];\n } else {\n operations = newOperation;\n }\n rootSpan.setAttribute(SENTRY_GRAPHQL_OPERATION, operations);\n\n // Keep the pre-rename name so repeated renames don't compound.\n const originalDescription =\n (rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE] as string | undefined) ?? rootSpanJson.description;\n if (!rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE]) {\n rootSpan.setAttribute(ORIGINAL_DESCRIPTION_ATTRIBUTE, originalDescription);\n }\n\n rootSpan.updateName(`${originalDescription} (${getGraphqlOperationNamesFromAttribute(operations)})`);\n}\n\n/** Format the accumulated operations for the root span name: up to 5 sorted names, then `+N`. */\nfunction getGraphqlOperationNamesFromAttribute(attr: string | string[]): string {\n if (Array.isArray(attr)) {\n // oxlint-disable-next-line typescript/require-array-sort-compare\n const sorted = attr.slice().sort();\n if (sorted.length <= 5) {\n return sorted.join(', ');\n }\n\n return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;\n }\n\n return attr;\n}\n\n/**\n * Span name follows the GraphQL semantic conventions: `<operation.type> <operation.name>` when both\n * are available, `<operation.type>` when only the type is, otherwise a static fallback.\n */\nexport function getOperationSpanName(\n operationType: string | undefined,\n operationName: string | undefined,\n fallbackName: string,\n): string {\n if (operationType && operationName) {\n return `${operationType} ${operationName}`;\n }\n if (operationType) {\n return operationType;\n }\n\n return fallbackName;\n}\n\n/** Whether a graphql execution result carries GraphQL errors (returned on `result.errors`). */\nexport function hasResultErrors(result: unknown): boolean {\n if (isObjectLike(result) && 'errors' in result) {\n const errors = (result as { errors?: unknown }).errors;\n\n return Array.isArray(errors) && errors.length > 0;\n }\n\n return false;\n}\n\n/**\n * Serialize a parsed document into `graphql.document` while redacting every literal argument value:\n * the original source text is preserved verbatim except that string/number literal spans are\n * replaced (`\"foo\"` -> `\"*\"`, `42` -> `*`). graphql does not sanitize its channel payload, so this\n * prevents raw inline values (potential PII) from leaving the process. Variable values are never\n * included. Returns `undefined` (rather than throwing) on anything it cannot serialize.\n */\nfunction redactGraphqlDocument(document: GraphqlDocumentNode | undefined): string | undefined {\n const loc = document?.loc;\n const body = loc?.source?.body;\n if (typeof body !== 'string' || !loc?.startToken) {\n return undefined;\n }\n\n try {\n // Collect literal token spans, then splice them out back-to-front so earlier offsets stay valid.\n const ranges: Array<{ start: number; end: number; kind: string }> = [];\n for (let token: GraphqlToken | null | undefined = loc.startToken; token; token = token.next) {\n if (REDACTED_LITERAL_KINDS.has(token.kind)) {\n ranges.push({ start: token.start, end: token.end, kind: token.kind });\n }\n }\n\n let out = body;\n // Reverse index loop (not `for...of`) so we splice back-to-front; `i` is bounded by the loop, so\n // `ranges[i]` is always present and the `!` just satisfies `noUncheckedIndexedAccess`.\n for (let i = ranges.length - 1; i >= 0; i--) {\n const { start, end, kind } = ranges[i]!;\n const replacement = kind === 'String' || kind === 'BlockString' ? '\"*\"' : '*';\n out = out.slice(0, start) + replacement + out.slice(end);\n }\n\n return out;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns the redacted document if `dataCollection.graphQL.document` is enabled, `undefined` otherwise.\n */\nexport function collectGraphqlDocument(document: GraphqlDocumentNode | undefined): string | undefined {\n if (getClient()?.getDataCollectionOptions().graphQL.document !== true) {\n return undefined;\n }\n return redactGraphqlDocument(document);\n}\n"],"names":["getRootSpan","spanToJSON","SENTRY_GRAPHQL_OPERATION","isObjectLike","getClient"],"mappings":";;;;;AAKA,MAAM,8BAAA,GAAiC,sBAAA;AAKvC,MAAM,s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
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const index$1 = require('./graphql/index.js');
|
|
4
|
-
const index$
|
|
5
|
-
const index$
|
|
6
|
-
const index$
|
|
4
|
+
const index$3 = require('./mongoose/index.js');
|
|
5
|
+
const index$4 = require('./mysql2/index.js');
|
|
6
|
+
const index$2 = require('./prisma/index.js');
|
|
7
|
+
const index$5 = require('./redis/index.js');
|
|
7
8
|
const redisStatementSerializer = require('./redis/redis-statement-serializer.js');
|
|
8
9
|
const tracingChannel = require('./tracing-channel.js');
|
|
9
|
-
const index$
|
|
10
|
+
const index$6 = require('./vercel-ai/index.js');
|
|
10
11
|
const index = require('./integrations/tracing-channel/fastify/index.js');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
exports.graphqlIntegration = index$1.graphqlIntegration;
|
|
15
|
-
exports.mongooseIntegration = index$
|
|
16
|
-
exports.mysql2Integration = index$
|
|
17
|
-
exports.
|
|
16
|
+
exports.mongooseIntegration = index$3.mongooseIntegration;
|
|
17
|
+
exports.mysql2Integration = index$4.mysql2Integration;
|
|
18
|
+
exports.instrumentPrisma = index$2.instrumentPrisma;
|
|
19
|
+
exports.prismaIntegration = index$2.prismaIntegration;
|
|
20
|
+
exports.redisIntegration = index$5.redisIntegration;
|
|
18
21
|
exports.defaultDbStatementSerializer = redisStatementSerializer.defaultDbStatementSerializer;
|
|
19
22
|
exports.bindTracingChannelToSpan = tracingChannel.bindTracingChannelToSpan;
|
|
20
|
-
exports.vercelAiIntegration = index$
|
|
23
|
+
exports.vercelAiIntegration = index$6.vercelAiIntegration;
|
|
21
24
|
exports.fastifyIntegration = index.fastifyIntegration;
|
|
22
25
|
exports.handleFastifyError = index.handleFastifyError;
|
|
23
26
|
exports.instrumentFastify = index.instrumentFastify;
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const diagnosticsChannel = require('node:diagnostics_channel');
|
|
4
|
+
const core = require('@sentry/core');
|
|
5
|
+
const debugBuild = require('../../debug-build.js');
|
|
6
|
+
const channels = require('../../orchestrion/channels.js');
|
|
7
|
+
const tracingChannel = require('../../tracing-channel.js');
|
|
8
|
+
|
|
9
|
+
const INTEGRATION_NAME = "Dataloader";
|
|
10
|
+
const MODULE_NAME = "dataloader";
|
|
11
|
+
const ORIGIN = "auto.db.orchestrion.dataloader";
|
|
12
|
+
const CACHE_GET_OP = "cache.get";
|
|
13
|
+
const WRAPPED = /* @__PURE__ */ Symbol("sentry.dataloader.wrapped");
|
|
14
|
+
function getSpanName(loader, operation) {
|
|
15
|
+
const name = loader?.name;
|
|
16
|
+
return name ? `${MODULE_NAME}.${operation} ${name}` : `${MODULE_NAME}.${operation}`;
|
|
17
|
+
}
|
|
18
|
+
function makeSpanOptions(loader, operation) {
|
|
19
|
+
const isCacheGet = operation === "load" || operation === "loadMany" || operation === "batch";
|
|
20
|
+
return {
|
|
21
|
+
name: getSpanName(loader, operation),
|
|
22
|
+
// Every direct operation (`load`/`loadMany`/`prime`/`clear`/`clearAll`) is a client call, matching
|
|
23
|
+
// the vendored OTel instrumentation. The `batch` runs off a deferred tick with no obvious network
|
|
24
|
+
// peer, so it gets no kind.
|
|
25
|
+
kind: operation === "batch" ? void 0 : core.SPAN_KIND.CLIENT,
|
|
26
|
+
op: isCacheGet ? CACHE_GET_OP : void 0,
|
|
27
|
+
onlyIfParent: true,
|
|
28
|
+
attributes: {
|
|
29
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const _dataloaderChannelIntegration = (() => {
|
|
34
|
+
return {
|
|
35
|
+
name: INTEGRATION_NAME,
|
|
36
|
+
setupOnce() {
|
|
37
|
+
if (!diagnosticsChannel.tracingChannel) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
debugBuild.DEBUG_BUILD && core.debug.log("[orchestrion:dataloader] subscribing to dataloader tracing channels");
|
|
41
|
+
core.waitForTracingChannelBinding(() => {
|
|
42
|
+
subscribeConstruct();
|
|
43
|
+
subscribeLoad();
|
|
44
|
+
subscribeSimpleOperation(channels.CHANNELS.DATALOADER_LOAD_MANY, "loadMany");
|
|
45
|
+
subscribeSimpleOperation(channels.CHANNELS.DATALOADER_PRIME, "prime");
|
|
46
|
+
subscribeSimpleOperation(channels.CHANNELS.DATALOADER_CLEAR, "clear");
|
|
47
|
+
subscribeSimpleOperation(channels.CHANNELS.DATALOADER_CLEAR_ALL, "clearAll");
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
function subscribeConstruct() {
|
|
53
|
+
diagnosticsChannel.tracingChannel(channels.CHANNELS.DATALOADER_CONSTRUCT).start.subscribe((message) => {
|
|
54
|
+
const data = message;
|
|
55
|
+
const batchLoadFn = data.arguments[0];
|
|
56
|
+
if (typeof batchLoadFn !== "function" || batchLoadFn[WRAPPED]) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const original = batchLoadFn;
|
|
60
|
+
const wrapped = function(...args) {
|
|
61
|
+
return core.startSpan(
|
|
62
|
+
{ ...makeSpanOptions(this, "batch"), links: this._batch?.spanLinks },
|
|
63
|
+
() => original.apply(this, args)
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
wrapped[WRAPPED] = true;
|
|
67
|
+
data.arguments[0] = wrapped;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function subscribeLoad() {
|
|
71
|
+
const channel = diagnosticsChannel.tracingChannel(channels.CHANNELS.DATALOADER_LOAD);
|
|
72
|
+
tracingChannel.bindTracingChannelToSpan(channel, (data) => startInactiveSpanFor(data.self, "load"), { requiresParentSpan: true });
|
|
73
|
+
channel.end.subscribe((message) => {
|
|
74
|
+
const data = message;
|
|
75
|
+
const span = data._sentrySpan;
|
|
76
|
+
const batch = data.self?._batch;
|
|
77
|
+
if (span && batch && span.isRecording()) {
|
|
78
|
+
(batch.spanLinks ?? (batch.spanLinks = [])).push({ context: span.spanContext() });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function subscribeSimpleOperation(channelName, operation) {
|
|
83
|
+
tracingChannel.bindTracingChannelToSpan(
|
|
84
|
+
diagnosticsChannel.tracingChannel(channelName),
|
|
85
|
+
(data) => startInactiveSpanFor(data.self, operation),
|
|
86
|
+
{ requiresParentSpan: true }
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function startInactiveSpanFor(loader, operation) {
|
|
90
|
+
return core.startInactiveSpan(makeSpanOptions(loader, operation));
|
|
91
|
+
}
|
|
92
|
+
const dataloaderChannelIntegration = core.defineIntegration(_dataloaderChannelIntegration);
|
|
93
|
+
|
|
94
|
+
exports.dataloaderChannelIntegration = dataloaderChannelIntegration;
|
|
95
|
+
//# sourceMappingURL=dataloader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataloader.js","sources":["../../../../src/integrations/tracing-channel/dataloader.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn, Span, StartSpanOptions } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n startInactiveSpan,\n startSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type { ChannelName } from '../../orchestrion/channels';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport type { TracingChannelPayloadWithSpan } from '../../tracing-channel';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// NOTE: this uses the same name as the OTel integration by design.\n// When enabled, the OTel 'Dataloader' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Dataloader' as const;\n\nconst MODULE_NAME = 'dataloader';\nconst ORIGIN = 'auto.db.orchestrion.dataloader';\n\n// `load`, `loadMany` and `batch` are cache reads; the rest are cache mutations that get no `op`.\nconst CACHE_GET_OP = 'cache.get';\n\ntype Operation = 'load' | 'loadMany' | 'batch' | 'prime' | 'clear' | 'clearAll';\n\n// The link shape shared between a `load` span and the `batch` span it triggers.\ntype DataLoaderSpanLink = { context: ReturnType<Span['spanContext']> };\n\n// The private batch object `dataloader` stores on the loader. We stash the pending `load` span links\n// here (matching the vendored OTel instrumentation) so the batch span can link back to them.\ninterface DataLoaderBatch {\n spanLinks?: DataLoaderSpanLink[];\n}\n\ninterface DataLoaderInstance {\n name?: string | null;\n _batch?: DataLoaderBatch | null;\n}\n\n/**\n * The shape orchestrion's transform attaches to the tracing-channel `context`. Documented here rather\n * than imported because orchestrion's runtime doesn't export it.\n */\ninterface DataLoaderChannelContext {\n arguments: unknown[];\n self?: DataLoaderInstance;\n result?: unknown;\n error?: unknown;\n}\n\n// Marks a wrapped `batchLoadFn` so a re-used loader (or a double construct) isn't wrapped twice.\nconst WRAPPED = Symbol('sentry.dataloader.wrapped');\n\nfunction getSpanName(loader: DataLoaderInstance | undefined, operation: Operation): string {\n const name = loader?.name;\n\n return name ? `${MODULE_NAME}.${operation} ${name}` : `${MODULE_NAME}.${operation}`;\n}\n\nfunction makeSpanOptions(loader: DataLoaderInstance | undefined, operation: Operation): StartSpanOptions {\n const isCacheGet = operation === 'load' || operation === 'loadMany' || operation === 'batch';\n\n return {\n name: getSpanName(loader, operation),\n // Every direct operation (`load`/`loadMany`/`prime`/`clear`/`clearAll`) is a client call, matching\n // the vendored OTel instrumentation. The `batch` runs off a deferred tick with no obvious network\n // peer, so it gets no kind.\n kind: operation === 'batch' ? undefined : SPAN_KIND.CLIENT,\n op: isCacheGet ? CACHE_GET_OP : undefined,\n onlyIfParent: true,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n },\n };\n}\n\nconst _dataloaderChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD && debug.log('[orchestrion:dataloader] subscribing to dataloader tracing channels');\n\n waitForTracingChannelBinding(() => {\n subscribeConstruct();\n subscribeLoad();\n subscribeSimpleOperation(CHANNELS.DATALOADER_LOAD_MANY, 'loadMany');\n subscribeSimpleOperation(CHANNELS.DATALOADER_PRIME, 'prime');\n subscribeSimpleOperation(CHANNELS.DATALOADER_CLEAR, 'clear');\n subscribeSimpleOperation(CHANNELS.DATALOADER_CLEAR_ALL, 'clearAll');\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Wraps the user's `batchLoadFn` (constructor arg 0) so the batch span opens when it runs on the\n * deferred dispatch tick. The span links back to the `load` calls that populated the batch.\n */\nfunction subscribeConstruct(): void {\n diagnosticsChannel\n .tracingChannel<DataLoaderChannelContext>(CHANNELS.DATALOADER_CONSTRUCT)\n .start.subscribe(message => {\n const data = message as DataLoaderChannelContext;\n const batchLoadFn = data.arguments[0];\n if (typeof batchLoadFn !== 'function' || (batchLoadFn as { [WRAPPED]?: boolean })[WRAPPED]) {\n return;\n }\n\n const original = batchLoadFn as (...args: unknown[]) => unknown;\n const wrapped = function (this: DataLoaderInstance, ...args: unknown[]): unknown {\n return startSpan({ ...makeSpanOptions(this, 'batch'), links: this._batch?.spanLinks }, () =>\n original.apply(this, args),\n );\n };\n (wrapped as { [WRAPPED]?: boolean })[WRAPPED] = true;\n data.arguments[0] = wrapped;\n });\n}\n\n/**\n * `load` is a cache read that additionally records its span so the batch it feeds into can link back.\n *\n * The span itself is `Async` (ends on `asyncEnd`, so its duration covers the awaited load). But the\n * link has to be recorded earlier, on the synchronous `end` (fired when `load` returns): the batch\n * dispatches on a deferred tick and reads `spanLinks` at batch-span creation, which happens BEFORE\n * `load`'s promise resolves (`asyncEnd`) — so recording at span end would be too late and drop the\n * link. The sync `end` runs after `dataloader` has assigned `this._batch` in `load`'s body and before\n * the deferred dispatch, so the link lands in time.\n */\nfunction subscribeLoad(): void {\n const channel = diagnosticsChannel.tracingChannel<DataLoaderChannelContext>(CHANNELS.DATALOADER_LOAD);\n\n bindTracingChannelToSpan(channel, data => startInactiveSpanFor(data.self, 'load'), { requiresParentSpan: true });\n\n channel.end.subscribe(message => {\n const data = message as TracingChannelPayloadWithSpan<DataLoaderChannelContext>;\n const span = data._sentrySpan;\n const batch = data.self?._batch;\n if (span && batch && span.isRecording()) {\n (batch.spanLinks ??= []).push({ context: span.spanContext() });\n }\n });\n}\n\nfunction subscribeSimpleOperation(channelName: ChannelName, operation: Operation): void {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<DataLoaderChannelContext>(channelName),\n data => startInactiveSpanFor(data.self, operation),\n { requiresParentSpan: true },\n );\n}\n\nfunction startInactiveSpanFor(loader: DataLoaderInstance | undefined, operation: Operation): Span {\n return startInactiveSpan(makeSpanOptions(loader, operation));\n}\n\n/**\n * EXPERIMENTAL: orchestrion-driven `dataloader` integration.\n *\n * Subscribes to the `orchestrion:dataloader:*` diagnostics_channels that the orchestrion code\n * transform injects into `dataloader`'s constructor and prototype methods. Requires the orchestrion\n * runtime hook or bundler plugin to be active.\n */\nexport const dataloaderChannelIntegration = defineIntegration(_dataloaderChannelIntegration);\n"],"names":["SPAN_KIND","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","DEBUG_BUILD","debug","waitForTracingChannelBinding","CHANNELS","startSpan","bindTracingChannelToSpan","startInactiveSpan","defineIntegration"],"mappings":";;;;;;;;AAmBA,MAAM,gBAAA,GAAmB,YAAA;AAEzB,MAAM,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AAA,EAAM,MAAM,CAAA,EAAG,EAAE,kBAAA,EAAoB,IAAA,EAAM,CAAA;AAE/G,EAAA,OAAA,CAAQ,GAAA,CAAI,UAAU,CAAA,OAAA,KAAW;AAC/B,IAAA,MAAM,IAAA,GAAO,OAAA;AACb,IAAA,MAAM,OAAO,IAAA,CAAK,WAAA;AAClB,IAAA,MAAM,KAAA,GAAQ,KAAK,IAAA,EAAM,MAAA;AACzB,IAAA,IAAI,IAAA,IAAQ,KAAA,IAAS,IAAA,CAAK,WAAA,EAAY,EAAG;AACvC,MAAA,CAAC,KAAA,CAAM,SAAA,KAAN,KAAA,CAAM,SAAA,GAAc,EAAC,CAAA,EAAG,IAAA,CAAK,EAAE,OAAA,EAAS,IAAA,CAAK,WAAA,EAAY,EAAG,CAAA;AAAA,IAC/D;AAAA,EACF,CAAC,CAAA;AACH;AAEA,SAAS,wBAAA,CAAyB,aAA0B,SAAA,EAA4B;AACtF,EAAAA,uCAAA;AAAA,IACE,kBAAA,CAAmB,eAAyC,WAAW,CAAA;AAAA,IACvE,CAAA,IAAA,KAAQ,oBAAA,CAAqB,IAAA,CAAK,IAAA,EAAM,SAAS,CAAA;AAAA,IACjD,EAAE,oBAAoB,IAAA;AAAK,GAC7B;AACF;AAEA,SAAS,oBAAA,CAAqB,QAAwC,SAAA,EAA4B;AAChG,EAAA,OAAOC,sBAAA,CAAkB,eAAA,CAAgB,MAAA,EAAQ,SAAS,CAAC,CAAA;AAC7D;AASO,MAAM,4BAAA,GAA+BC,uBAAkB,6BAA6B;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const diagnosticsChannel = require('node:diagnostics_channel');
|
|
4
|
+
const core = require('@sentry/core');
|
|
5
|
+
const channels = require('../../orchestrion/channels.js');
|
|
6
|
+
const tracingChannel = require('../../tracing-channel.js');
|
|
7
|
+
|
|
8
|
+
const INTEGRATION_NAME = "GenericPool";
|
|
9
|
+
const _genericPoolChannelIntegration = (() => {
|
|
10
|
+
return {
|
|
11
|
+
name: INTEGRATION_NAME,
|
|
12
|
+
setupOnce() {
|
|
13
|
+
if (!diagnosticsChannel.tracingChannel) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
core.waitForTracingChannelBinding(() => instrumentGenericPool());
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
const genericPoolChannelIntegration = core.defineIntegration(_genericPoolChannelIntegration);
|
|
21
|
+
function instrumentGenericPool() {
|
|
22
|
+
tracingChannel.bindTracingChannelToSpan(
|
|
23
|
+
diagnosticsChannel.tracingChannel(channels.CHANNELS.GENERIC_POOL_ACQUIRE),
|
|
24
|
+
() => core.startInactiveSpan({
|
|
25
|
+
name: "generic-pool.acquire",
|
|
26
|
+
attributes: {
|
|
27
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.db.orchestrion.generic_pool"
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.genericPoolChannelIntegration = genericPoolChannelIntegration;
|
|
34
|
+
//# sourceMappingURL=generic-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-pool.js","sources":["../../../../src/integrations/tracing-channel/generic-pool.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn } from '@sentry/core';\nimport {\n defineIntegration,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Same name as the OTel integration by design — when enabled, the OTel\n// 'GenericPool' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'GenericPool' as const;\n\ninterface GenericPoolAcquireContext {\n arguments: unknown[];\n}\n\nconst _genericPoolChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19 so do nothing in that case.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n waitForTracingChannelBinding(() => instrumentGenericPool());\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * EXPERIMENTAL — orchestrion-driven generic-pool integration. Subscribes to\n * `orchestrion:generic-pool:acquire` (injected into `generic-pool/lib/Pool.js`'s\n * `Pool.prototype.acquire`). Creates a `generic-pool.acquire` span for each\n * acquisition. Requires the orchestrion runtime hook or bundler plugin.\n */\nexport const genericPoolChannelIntegration = defineIntegration(_genericPoolChannelIntegration);\n\nfunction instrumentGenericPool(): void {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<GenericPoolAcquireContext>(CHANNELS.GENERIC_POOL_ACQUIRE),\n () =>\n startInactiveSpan({\n name: 'generic-pool.acquire',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.orchestrion.generic_pool',\n },\n }),\n );\n}\n"],"names":["waitForTracingChannelBinding","defineIntegration","bindTracingChannelToSpan","CHANNELS","startInactiveSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;;;;AAaA,MAAM,gBAAA,GAAmB,aAAA;AAMzB,MAAM,kCAAkC,MAAM;AAC5C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAAC,mBAAmB,cAAA,EAAgB;AACtC,QAAA;AAAA,MACF;AAEA,MAAAA,iCAAA,CAA6B,MAAM,uBAAuB,CAAA;AAAA,IAC5D;AAAA,GACF;AACF,CAAA,CAAA;AAQO,MAAM,6BAAA,GAAgCC,uBAAkB,8BAA8B;AAE7F,SAAS,qBAAA,GAA8B;AACrC,EAAAC,uCAAA;AAAA,IACE,kBAAA,CAAmB,cAAA,CAA0CC,iBAAA,CAAS,oBAAoB,CAAA;AAAA,IAC1F,MACEC,sBAAA,CAAkB;AAAA,MAChB,IAAA,EAAM,sBAAA;AAAA,MACN,UAAA,EAAY;AAAA,QACV,CAACC,qCAAgC,GAAG;AAAA;AACtC,KACD;AAAA,GACL;AACF;;;;"}
|
|
@@ -17,7 +17,7 @@ function startParseSpan() {
|
|
|
17
17
|
function startValidateSpan(documentAST) {
|
|
18
18
|
return core.startInactiveSpan({
|
|
19
19
|
name: constants.SPAN_NAME_VALIDATE,
|
|
20
|
-
attributes: { ...BASE_ATTRIBUTES, [attributes.GRAPHQL_DOCUMENT]: utils.
|
|
20
|
+
attributes: { ...BASE_ATTRIBUTES, [attributes.GRAPHQL_DOCUMENT]: utils.collectGraphqlDocument(documentAST) }
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
function finalizeValidateSpan(span, result) {
|
|
@@ -78,7 +78,7 @@ function startExecuteSpan(argsArray, self, config, getConfig) {
|
|
|
78
78
|
...BASE_ATTRIBUTES,
|
|
79
79
|
[attributes.GRAPHQL_OPERATION_TYPE]: operationType,
|
|
80
80
|
[attributes.GRAPHQL_OPERATION_NAME]: operationName || void 0,
|
|
81
|
-
[attributes.GRAPHQL_DOCUMENT]: utils.
|
|
81
|
+
[attributes.GRAPHQL_DOCUMENT]: utils.collectGraphqlDocument(document)
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
if (config.useOperationNameForRootSpan && operationType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spans.js","sources":["../../../../../src/integrations/tracing-channel/graphql/spans.ts"],"sourcesContent":["/*\n * Span builders for the orchestrion graphql channels (v14–16). They emit the same spans as the native\n * `diagnostics_channel` subscriber (`../../../graphql/graphql-dc-subscriber.ts`, graphql >= 17) by\n * reusing its `utils` and conventions — only the data source differs: here the payloads are the raw\n * arguments of the injected `parse`/`validate`/`execute` calls rather than graphql's native events.\n */\n\nimport { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport type { Span } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { GraphqlDocumentNode } from '../../../graphql/utils';\nimport {\n getOperationSpanName,\n hasResultErrors,\n redactGraphqlDocument,\n renameRootSpanWithOperation,\n} from '../../../graphql/utils';\nimport { GRAPHQL_DATA_SYMBOL, ORIGIN, SPAN_NAME_EXECUTE, SPAN_NAME_PARSE, SPAN_NAME_VALIDATE } from './constants';\nimport { getOperation, wrapFields, wrapFieldResolver } from './resolvers';\nimport type {\n DocumentNode,\n GraphQLFieldResolver,\n GraphQLSchema,\n GraphqlResolvedConfig,\n Maybe,\n ObjectWithGraphQLData,\n} from './types';\n\nconst BASE_ATTRIBUTES = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n} as const;\n\nexport function startParseSpan(): Span {\n return startInactiveSpan({ name: SPAN_NAME_PARSE, attributes: { ...BASE_ATTRIBUTES } });\n}\n\n/** `documentAST` is the 2nd argument to `validate(schema, documentAST, …)`. */\nexport function startValidateSpan(documentAST: unknown): Span {\n return startInactiveSpan({\n name: SPAN_NAME_VALIDATE,\n attributes: { ...BASE_ATTRIBUTES, [GRAPHQL_DOCUMENT]: redactGraphqlDocument(documentAST as GraphqlDocumentNode) },\n });\n}\n\n/** `result` is validation's return value: a (possibly empty) array of errors. */\nexport function finalizeValidateSpan(span: Span, result: unknown): void {\n if (Array.isArray(result) && result.length > 0) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'invalid_argument' });\n }\n}\n\n/** Positional slots of a `graphql.execute(schema, document, …)` call (v14/v15 legacy signature). */\nconst enum ExecuteArg {\n SCHEMA = 0,\n DOCUMENT = 1,\n CONTEXT_VALUE = 3,\n OPERATION_NAME = 5,\n FIELD_RESOLVER = 6,\n}\n\ninterface NormalizedExecuteArgs {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue: ObjectWithGraphQLData;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n /** Writes `contextValue`/`fieldResolver` mutations back to the live channel `arguments`. */\n writeBack: (contextValue: ObjectWithGraphQLData, fieldResolver: Maybe<GraphQLFieldResolver>) => void;\n}\n\n/**\n * `execute` accepts either a single `ExecutionArgs` object (modern callers, always in v16) or\n * positional args (v14/v15). Both are normalized here; `writeBack` puts mutations onto the correct\n * slot so they reach the real call.\n */\nfunction normalizeExecuteArgs(argsArray: unknown[]): NormalizedExecuteArgs {\n if (argsArray.length >= 2) {\n return {\n schema: argsArray[ExecuteArg.SCHEMA] as GraphQLSchema | undefined,\n document: argsArray[ExecuteArg.DOCUMENT] as DocumentNode | undefined,\n contextValue: (argsArray[ExecuteArg.CONTEXT_VALUE] ?? {}) as ObjectWithGraphQLData,\n operationName: argsArray[ExecuteArg.OPERATION_NAME] as Maybe<string>,\n fieldResolver: argsArray[ExecuteArg.FIELD_RESOLVER] as Maybe<GraphQLFieldResolver>,\n writeBack: (contextValue, fieldResolver) => {\n argsArray[ExecuteArg.CONTEXT_VALUE] = contextValue;\n argsArray[ExecuteArg.FIELD_RESOLVER] = fieldResolver;\n },\n };\n }\n\n const obj = (argsArray[0] ?? {}) as {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue?: unknown;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n };\n return {\n schema: obj.schema,\n document: obj.document,\n contextValue: (obj.contextValue ?? {}) as ObjectWithGraphQLData,\n operationName: obj.operationName,\n fieldResolver: obj.fieldResolver,\n writeBack: (contextValue, fieldResolver) => {\n obj.contextValue = contextValue;\n obj.fieldResolver = fieldResolver;\n },\n };\n}\n\n/**\n * Opens the execute span and, unless resolver spans are disabled, swaps the schema's field resolvers\n * (and the default field resolver) for span-creating proxies — mutating the live `arguments` in place\n * so the wrapped `execute` call runs with them. Always returns a span; the caller guards against\n * throws (see `safe` in `index.ts`).\n */\nexport function startExecuteSpan(\n argsArray: unknown[],\n self: unknown,\n config: GraphqlResolvedConfig,\n getConfig: () => GraphqlResolvedConfig,\n): Span {\n const args = normalizeExecuteArgs(argsArray);\n const { schema, document } = args;\n let { contextValue, fieldResolver } = args;\n\n // Skip resolver wrapping when disabled or when a parent execute already set up this context\n // (nested execute reusing the same contextValue).\n const alreadyInstrumented = !!contextValue[GRAPHQL_DATA_SYMBOL];\n if (!config.ignoreResolveSpans && !alreadyInstrumented) {\n const isUsingDefaultResolver = fieldResolver == null;\n const defaultFieldResolver = (self as { defaultFieldResolver?: GraphQLFieldResolver } | undefined)\n ?.defaultFieldResolver;\n const fieldResolverForExecute = fieldResolver ?? defaultFieldResolver;\n if (fieldResolverForExecute) {\n fieldResolver = wrapFieldResolver(getConfig, fieldResolverForExecute, isUsingDefaultResolver);\n }\n\n if (schema) {\n wrapFields(schema.getQueryType(), getConfig);\n wrapFields(schema.getMutationType(), getConfig);\n }\n }\n\n // v14–16 channels carry only the raw args, so derive the operation from the document (native v17\n // provides `operationType`/`operationName` on the event directly).\n const operation = getOperation(document as DocumentNode, args.operationName);\n const operationType = operation?.operation;\n const operationName = operation?.name?.value ?? args.operationName ?? undefined;\n\n const span = startInactiveSpan({\n name: getOperationSpanName(operationType, operationName || undefined, SPAN_NAME_EXECUTE),\n attributes: {\n ...BASE_ATTRIBUTES,\n [GRAPHQL_OPERATION_TYPE]: operationType,\n [GRAPHQL_OPERATION_NAME]: operationName || undefined,\n [GRAPHQL_DOCUMENT]: redactGraphqlDocument(document as GraphqlDocumentNode | undefined),\n },\n });\n\n if (config.useOperationNameForRootSpan && operationType) {\n renameRootSpanWithOperation(span, operationType, operationName || undefined);\n }\n\n // The resolver proxies read the execute span (and their own bookkeeping) off this symbol.\n contextValue[GRAPHQL_DATA_SYMBOL] = { source: document, span, fields: {} };\n args.writeBack(contextValue, fieldResolver);\n\n return span;\n}\n\n/** `result` is the settled `ExecutionResult`; GraphQL errors surface on `result.errors`, not a throw. */\nexport function finalizeExecuteSpan(span: Span, result: unknown): void {\n if (hasResultErrors(result)) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n}\n"],"names":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","WEB_SERVER_GRAPHQL_SPAN_OP","startInactiveSpan","SPAN_NAME_PARSE","SPAN_NAME_VALIDATE","GRAPHQL_DOCUMENT","redactGraphqlDocument","SPAN_STATUS_ERROR","GRAPHQL_DATA_SYMBOL","wrapFieldResolver","wrapFields","getOperation","getOperationSpanName","SPAN_NAME_EXECUTE","GRAPHQL_OPERATION_TYPE","GRAPHQL_OPERATION_NAME","renameRootSpanWithOperation","hasResultErrors"],"mappings":";;;;;;;;;AAkCA,MAAM,eAAA,GAAkB;AAAA,EACtB,CAACA,qCAAgC,GAAGC,gBAAA;AAAA,EACpC,CAACC,iCAA4B,GAAGC;AAClC,CAAA;AAEO,SAAS,cAAA,GAAuB;AACrC,EAAA,OAAOC,sBAAA,CAAkB,EAAE,IAAA,EAAMC,yBAAA,EAAiB,YAAY,EAAE,GAAG,eAAA,EAAgB,EAAG,CAAA;AACxF;AAGO,SAAS,kBAAkB,WAAA,EAA4B;AAC5D,EAAA,OAAOD,sBAAA,CAAkB;AAAA,IACvB,IAAA,EAAME,4BAAA;AAAA,IACN,UAAA,EAAY,EAAE,GAAG,eAAA,EAAiB,CAACC,2BAAgB,GAAGC,2BAAA,CAAsB,WAAkC,CAAA;AAAE,GACjH,CAAA;AACH;AAGO,SAAS,oBAAA,CAAqB,MAAY,MAAA,EAAuB;AACtE,EAAA,IAAI,MAAM,OAAA,CAAQ,MAAM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AC3C,CAACV,2BAAgB,GAAGC,2BAAA,CAAsB,QAA2C;AAAA;AACvF,GACD,CAAA;AAED,EAAA,IAAI,MAAA,CAAO,+BAA+B,aAAA,EAAe;AACvD,IAAAU,iCAAA,CAA4B,IAAA,EAAM,aAAA,EAAe,aAAA,IAAiB,MAAS,CAAA;AAAA,EAC7E;AAGA,EAAA,YAAA,CAAaR,6BAAmB,IAAI,EAAE,MAAA,EAAQ,UAAU,IAAA,EAAM,MAAA,EAAQ,EAAC,EAAE;AACzE,EAAA,IAAA,CAAK,SAAA,CAAU,cAAc,aAAa,CAAA;AAE1C,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,mBAAA,CAAoB,MAAY,MAAA,EAAuB;AACrE,EAAA,IAAIS,qBAAA,CAAgB,MAAM,CAAA,EAAG;AAC3B,IAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAMV,sBAAA,EAAmB,OAAA,EAAS,kBAAkB,CAAA;AAAA,EACvE;AACF;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"spans.js","sources":["../../../../../src/integrations/tracing-channel/graphql/spans.ts"],"sourcesContent":["/*\n * Span builders for the orchestrion graphql channels (v14–16). They emit the same spans as the native\n * `diagnostics_channel` subscriber (`../../../graphql/graphql-dc-subscriber.ts`, graphql >= 17) by\n * reusing its `utils` and conventions — only the data source differs: here the payloads are the raw\n * arguments of the injected `parse`/`validate`/`execute` calls rather than graphql's native events.\n */\n\nimport { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';\nimport { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';\nimport type { Span } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { GraphqlDocumentNode } from '../../../graphql/utils';\nimport {\n collectGraphqlDocument,\n getOperationSpanName,\n hasResultErrors,\n renameRootSpanWithOperation,\n} from '../../../graphql/utils';\nimport { GRAPHQL_DATA_SYMBOL, ORIGIN, SPAN_NAME_EXECUTE, SPAN_NAME_PARSE, SPAN_NAME_VALIDATE } from './constants';\nimport { getOperation, wrapFields, wrapFieldResolver } from './resolvers';\nimport type {\n DocumentNode,\n GraphQLFieldResolver,\n GraphQLSchema,\n GraphqlResolvedConfig,\n Maybe,\n ObjectWithGraphQLData,\n} from './types';\n\nconst BASE_ATTRIBUTES = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,\n} as const;\n\nexport function startParseSpan(): Span {\n return startInactiveSpan({ name: SPAN_NAME_PARSE, attributes: { ...BASE_ATTRIBUTES } });\n}\n\n/** `documentAST` is the 2nd argument to `validate(schema, documentAST, …)`. */\nexport function startValidateSpan(documentAST: unknown): Span {\n return startInactiveSpan({\n name: SPAN_NAME_VALIDATE,\n attributes: { ...BASE_ATTRIBUTES, [GRAPHQL_DOCUMENT]: collectGraphqlDocument(documentAST as GraphqlDocumentNode) },\n });\n}\n\n/** `result` is validation's return value: a (possibly empty) array of errors. */\nexport function finalizeValidateSpan(span: Span, result: unknown): void {\n if (Array.isArray(result) && result.length > 0) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'invalid_argument' });\n }\n}\n\n/** Positional slots of a `graphql.execute(schema, document, …)` call (v14/v15 legacy signature). */\nconst enum ExecuteArg {\n SCHEMA = 0,\n DOCUMENT = 1,\n CONTEXT_VALUE = 3,\n OPERATION_NAME = 5,\n FIELD_RESOLVER = 6,\n}\n\ninterface NormalizedExecuteArgs {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue: ObjectWithGraphQLData;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n /** Writes `contextValue`/`fieldResolver` mutations back to the live channel `arguments`. */\n writeBack: (contextValue: ObjectWithGraphQLData, fieldResolver: Maybe<GraphQLFieldResolver>) => void;\n}\n\n/**\n * `execute` accepts either a single `ExecutionArgs` object (modern callers, always in v16) or\n * positional args (v14/v15). Both are normalized here; `writeBack` puts mutations onto the correct\n * slot so they reach the real call.\n */\nfunction normalizeExecuteArgs(argsArray: unknown[]): NormalizedExecuteArgs {\n if (argsArray.length >= 2) {\n return {\n schema: argsArray[ExecuteArg.SCHEMA] as GraphQLSchema | undefined,\n document: argsArray[ExecuteArg.DOCUMENT] as DocumentNode | undefined,\n contextValue: (argsArray[ExecuteArg.CONTEXT_VALUE] ?? {}) as ObjectWithGraphQLData,\n operationName: argsArray[ExecuteArg.OPERATION_NAME] as Maybe<string>,\n fieldResolver: argsArray[ExecuteArg.FIELD_RESOLVER] as Maybe<GraphQLFieldResolver>,\n writeBack: (contextValue, fieldResolver) => {\n argsArray[ExecuteArg.CONTEXT_VALUE] = contextValue;\n argsArray[ExecuteArg.FIELD_RESOLVER] = fieldResolver;\n },\n };\n }\n\n const obj = (argsArray[0] ?? {}) as {\n schema?: GraphQLSchema;\n document?: DocumentNode;\n contextValue?: unknown;\n operationName?: Maybe<string>;\n fieldResolver?: Maybe<GraphQLFieldResolver>;\n };\n return {\n schema: obj.schema,\n document: obj.document,\n contextValue: (obj.contextValue ?? {}) as ObjectWithGraphQLData,\n operationName: obj.operationName,\n fieldResolver: obj.fieldResolver,\n writeBack: (contextValue, fieldResolver) => {\n obj.contextValue = contextValue;\n obj.fieldResolver = fieldResolver;\n },\n };\n}\n\n/**\n * Opens the execute span and, unless resolver spans are disabled, swaps the schema's field resolvers\n * (and the default field resolver) for span-creating proxies — mutating the live `arguments` in place\n * so the wrapped `execute` call runs with them. Always returns a span; the caller guards against\n * throws (see `safe` in `index.ts`).\n */\nexport function startExecuteSpan(\n argsArray: unknown[],\n self: unknown,\n config: GraphqlResolvedConfig,\n getConfig: () => GraphqlResolvedConfig,\n): Span {\n const args = normalizeExecuteArgs(argsArray);\n const { schema, document } = args;\n let { contextValue, fieldResolver } = args;\n\n // Skip resolver wrapping when disabled or when a parent execute already set up this context\n // (nested execute reusing the same contextValue).\n const alreadyInstrumented = !!contextValue[GRAPHQL_DATA_SYMBOL];\n if (!config.ignoreResolveSpans && !alreadyInstrumented) {\n const isUsingDefaultResolver = fieldResolver == null;\n const defaultFieldResolver = (self as { defaultFieldResolver?: GraphQLFieldResolver } | undefined)\n ?.defaultFieldResolver;\n const fieldResolverForExecute = fieldResolver ?? defaultFieldResolver;\n if (fieldResolverForExecute) {\n fieldResolver = wrapFieldResolver(getConfig, fieldResolverForExecute, isUsingDefaultResolver);\n }\n\n if (schema) {\n wrapFields(schema.getQueryType(), getConfig);\n wrapFields(schema.getMutationType(), getConfig);\n }\n }\n\n // v14–16 channels carry only the raw args, so derive the operation from the document (native v17\n // provides `operationType`/`operationName` on the event directly).\n const operation = getOperation(document as DocumentNode, args.operationName);\n const operationType = operation?.operation;\n const operationName = operation?.name?.value ?? args.operationName ?? undefined;\n\n const span = startInactiveSpan({\n name: getOperationSpanName(operationType, operationName || undefined, SPAN_NAME_EXECUTE),\n attributes: {\n ...BASE_ATTRIBUTES,\n [GRAPHQL_OPERATION_TYPE]: operationType,\n [GRAPHQL_OPERATION_NAME]: operationName || undefined,\n [GRAPHQL_DOCUMENT]: collectGraphqlDocument(document as GraphqlDocumentNode | undefined),\n },\n });\n\n if (config.useOperationNameForRootSpan && operationType) {\n renameRootSpanWithOperation(span, operationType, operationName || undefined);\n }\n\n // The resolver proxies read the execute span (and their own bookkeeping) off this symbol.\n contextValue[GRAPHQL_DATA_SYMBOL] = { source: document, span, fields: {} };\n args.writeBack(contextValue, fieldResolver);\n\n return span;\n}\n\n/** `result` is the settled `ExecutionResult`; GraphQL errors surface on `result.errors`, not a throw. */\nexport function finalizeExecuteSpan(span: Span, result: unknown): void {\n if (hasResultErrors(result)) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n}\n"],"names":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","WEB_SERVER_GRAPHQL_SPAN_OP","startInactiveSpan","SPAN_NAME_PARSE","SPAN_NAME_VALIDATE","GRAPHQL_DOCUMENT","collectGraphqlDocument","SPAN_STATUS_ERROR","GRAPHQL_DATA_SYMBOL","wrapFieldResolver","wrapFields","getOperation","getOperationSpanName","SPAN_NAME_EXECUTE","GRAPHQL_OPERATION_TYPE","GRAPHQL_OPERATION_NAME","renameRootSpanWithOperation","hasResultErrors"],"mappings":";;;;;;;;;AAkCA,MAAM,eAAA,GAAkB;AAAA,EACtB,CAACA,qCAAgC,GAAGC,gBAAA;AAAA,EACpC,CAACC,iCAA4B,GAAGC;AAClC,CAAA;AAEO,SAAS,cAAA,GAAuB;AACrC,EAAA,OAAOC,sBAAA,CAAkB,EAAE,IAAA,EAAMC,yBAAA,EAAiB,YAAY,EAAE,GAAG,eAAA,EAAgB,EAAG,CAAA;AACxF;AAGO,SAAS,kBAAkB,WAAA,EAA4B;AAC5D,EAAA,OAAOD,sBAAA,CAAkB;AAAA,IACvB,IAAA,EAAME,4BAAA;AAAA,IACN,UAAA,EAAY,EAAE,GAAG,eAAA,EAAiB,CAACC,2BAAgB,GAAGC,4BAAA,CAAuB,WAAkC,CAAA;AAAE,GAClH,CAAA;AACH;AAGO,SAAS,oBAAA,CAAqB,MAAY,MAAA,EAAuB;AACtE,EAAA,IAAI,MAAM,OAAA,CAAQ,MAAM,CAAA,IAAK,MAAA,CAAO,SAAS,CAAA,EAAG;AAC9C,IAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAMC,sBAAA,EAAmB,OAAA,EAAS,oBAAoB,CAAA;AAAA,EACzE;AACF;AA0BA,SAAS,qBAAqB,SAAA,EAA6C;AACzE,EAAA,IAAI,SAAA,CAAU,UAAU,CAAA,EAAG;AACzB,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,UAAU,CAAA,c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AAA,EAAQ,EAAC,EAAE;AACzE,EAAA,IAAA,CAAK,SAAA,CAAU,cAAc,aAAa,CAAA;AAE1C,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,mBAAA,CAAoB,MAAY,MAAA,EAAuB;AACrE,EAAA,IAAIS,qBAAA,CAAgB,MAAM,CAAA,EAAG;AAC3B,IAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAMV,sBAAA,EAAmB,OAAA,EAAS,kBAAkB,CAAA;AAAA,EACvE;AACF;;;;;;;;"}
|
|
@@ -23,6 +23,24 @@ function connectionAttributes(host, port) {
|
|
|
23
23
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
const tracedCommands = /* @__PURE__ */ new WeakSet();
|
|
27
|
+
function startIORedisCommandSpan(data) {
|
|
28
|
+
const command = data.arguments?.[0];
|
|
29
|
+
if (!command || typeof command !== "object") {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
if (tracedCommands.has(command)) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
tracedCommands.add(command);
|
|
36
|
+
const { host, port } = getConnectionOptions(data.self);
|
|
37
|
+
const statement = redisStatementSerializer.defaultDbStatementSerializer(command.name, command.args ?? []);
|
|
38
|
+
return core.startInactiveSpan({
|
|
39
|
+
name: statement,
|
|
40
|
+
op: "db",
|
|
41
|
+
attributes: { ...connectionAttributes(host, port), [attributes.DB_STATEMENT]: statement }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
26
44
|
const _ioredisChannelIntegration = ((options = {}) => {
|
|
27
45
|
const responseHook = options.responseHook;
|
|
28
46
|
return {
|
|
@@ -39,35 +57,19 @@ const _ioredisChannelIntegration = ((options = {}) => {
|
|
|
39
57
|
channels.CHANNELS.IOREDIS_CONNECT
|
|
40
58
|
);
|
|
41
59
|
core.waitForTracingChannelBinding(() => {
|
|
42
|
-
tracingChannel.bindTracingChannelToSpan(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
60
|
+
tracingChannel.bindTracingChannelToSpan(commandChannel, startIORedisCommandSpan, {
|
|
61
|
+
// ioredis' `requireParentSpan` default: only create a span under an active span.
|
|
62
|
+
requiresParentSpan: true,
|
|
63
|
+
beforeSpanEnd(span, data) {
|
|
64
|
+
if ("error" in data || !responseHook) {
|
|
65
|
+
return;
|
|
48
66
|
}
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
name: statement,
|
|
53
|
-
op: "db",
|
|
54
|
-
attributes: { ...connectionAttributes(host, port), [attributes.DB_STATEMENT]: statement }
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
// ioredis' `requireParentSpan` default: only create a span under an active span.
|
|
59
|
-
requiresParentSpan: true,
|
|
60
|
-
beforeSpanEnd(span, data) {
|
|
61
|
-
if ("error" in data || !responseHook) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const command = data.arguments?.[0];
|
|
65
|
-
if (command) {
|
|
66
|
-
runResponseHook(responseHook, span, command, data.result);
|
|
67
|
-
}
|
|
67
|
+
const command = data.arguments?.[0];
|
|
68
|
+
if (command) {
|
|
69
|
+
runResponseHook(responseHook, span, command, data.result);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
|
-
);
|
|
72
|
+
});
|
|
71
73
|
tracingChannel.bindTracingChannelToSpan(
|
|
72
74
|
connectChannel,
|
|
73
75
|
(data) => {
|
|
@@ -93,4 +95,5 @@ function runResponseHook(hook, span, command, result) {
|
|
|
93
95
|
const ioredisChannelIntegration = core.defineIntegration(_ioredisChannelIntegration);
|
|
94
96
|
|
|
95
97
|
exports.ioredisChannelIntegration = ioredisChannelIntegration;
|
|
98
|
+
exports.startIORedisCommandSpan = startIORedisCommandSpan;
|
|
96
99
|
//# sourceMappingURL=ioredis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ioredis.js","sources":["../../../../src/integrations/tracing-channel/ioredis.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated -- we intentionally emit the OLD db/net semconv\n to match `@opentelemetry/instrumentation-ioredis` (and Sentry's `inferDbSpanData`, which keys off\n `db.statement`). TODO(v11): switch to the non-deprecated `db.system.name`/`db.query.text`/\n `server.address`/`server.port` conventions and drop this disable. */\nimport * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { DB_STATEMENT, DB_SYSTEM, NET_PEER_NAME, NET_PEER_PORT } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { defaultDbStatementSerializer } from '../../redis/redis-statement-serializer';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Distinct from the OTel `Redis` integration, which is composite (node-redis +\n// ioredis + the >=5.11.0 diagnostics_channel subscriber) and stays in the set;\n// only its ioredis monkey-patch is gated off in the node SDK when this is active.\nconst INTEGRATION_NAME = 'IORedis' as const;\n\nconst ORIGIN = 'auto.db.orchestrion.redis';\n\n// todo(v11): Let's drop this as this is already covered with host and port\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\n\n/** Mirrors `@opentelemetry/instrumentation-ioredis`' response hook. Not called for failed commands. */\nexport type IORedisResponseHook = (span: Span, command: string, args: Array<string | Buffer>, result: unknown) => void;\n\nexport interface IORedisChannelIntegrationOptions {\n responseHook?: IORedisResponseHook;\n}\n\n/** Structural type for the command object ioredis passes to `sendCommand`. */\ninterface RedisCommand {\n name: string;\n args: Array<string | Buffer>;\n}\n\ninterface RedisClientLike {\n options?: { host?: string; port?: number };\n}\n\ninterface IORedisCommandContext {\n arguments?: unknown[];\n self?: RedisClientLike;\n result?: unknown;\n error?: unknown;\n}\n\ntype IORedisConnectContext = Omit<IORedisCommandContext, 'arguments'>;\n\nfunction getConnectionOptions(self: RedisClientLike | undefined): { host?: string; port?: number } {\n return { host: self?.options?.host, port: self?.options?.port };\n}\n\nfunction connectionAttributes(host: string | undefined, port: number | undefined): Record<string, unknown> {\n return {\n [DB_SYSTEM]: 'redis',\n [ATTR_DB_CONNECTION_STRING]: `redis://${host}:${port}`,\n [NET_PEER_NAME]: host,\n [NET_PEER_PORT]: port,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n };\n}\n\nconst _ioredisChannelIntegration = ((options: IORedisChannelIntegrationOptions = {}) => {\n const responseHook = options.responseHook;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD &&\n debug.log(`[orchestrion:ioredis] subscribing to \"${CHANNELS.IOREDIS_COMMAND}\"/\"${CHANNELS.IOREDIS_CONNECT}\"`);\n\n const commandChannel = diagnosticsChannel.tracingChannel<IORedisCommandContext, IORedisCommandContext>(\n CHANNELS.IOREDIS_COMMAND,\n );\n const connectChannel = diagnosticsChannel.tracingChannel<IORedisConnectContext, IORedisConnectContext>(\n CHANNELS.IOREDIS_CONNECT,\n );\n\n // `bindTracingChannelToSpan` uses `bindStore`, which needs the async-context\n // binding that `initOpenTelemetry()` registers after integration `setupOnce` —\n // defer until it's available (matches the native redis diagnostics-channel subscriber).\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(
|
|
1
|
+
{"version":3,"file":"ioredis.js","sources":["../../../../src/integrations/tracing-channel/ioredis.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-deprecated -- we intentionally emit the OLD db/net semconv\n to match `@opentelemetry/instrumentation-ioredis` (and Sentry's `inferDbSpanData`, which keys off\n `db.statement`). TODO(v11): switch to the non-deprecated `db.system.name`/`db.query.text`/\n `server.address`/`server.port` conventions and drop this disable. */\nimport * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { DB_STATEMENT, DB_SYSTEM, NET_PEER_NAME, NET_PEER_PORT } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n debug,\n defineIntegration,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startInactiveSpan,\n waitForTracingChannelBinding,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { defaultDbStatementSerializer } from '../../redis/redis-statement-serializer';\nimport { bindTracingChannelToSpan } from '../../tracing-channel';\n\n// Distinct from the OTel `Redis` integration, which is composite (node-redis +\n// ioredis + the >=5.11.0 diagnostics_channel subscriber) and stays in the set;\n// only its ioredis monkey-patch is gated off in the node SDK when this is active.\nconst INTEGRATION_NAME = 'IORedis' as const;\n\nconst ORIGIN = 'auto.db.orchestrion.redis';\n\n// todo(v11): Let's drop this as this is already covered with host and port\nconst ATTR_DB_CONNECTION_STRING = 'db.connection_string';\n\n/** Mirrors `@opentelemetry/instrumentation-ioredis`' response hook. Not called for failed commands. */\nexport type IORedisResponseHook = (span: Span, command: string, args: Array<string | Buffer>, result: unknown) => void;\n\nexport interface IORedisChannelIntegrationOptions {\n responseHook?: IORedisResponseHook;\n}\n\n/** Structural type for the command object ioredis passes to `sendCommand`. */\ninterface RedisCommand {\n name: string;\n args: Array<string | Buffer>;\n}\n\ninterface RedisClientLike {\n options?: { host?: string; port?: number };\n}\n\ninterface IORedisCommandContext {\n arguments?: unknown[];\n self?: RedisClientLike;\n result?: unknown;\n error?: unknown;\n}\n\ntype IORedisConnectContext = Omit<IORedisCommandContext, 'arguments'>;\n\nfunction getConnectionOptions(self: RedisClientLike | undefined): { host?: string; port?: number } {\n return { host: self?.options?.host, port: self?.options?.port };\n}\n\nfunction connectionAttributes(host: string | undefined, port: number | undefined): Record<string, unknown> {\n return {\n [DB_SYSTEM]: 'redis',\n [ATTR_DB_CONNECTION_STRING]: `redis://${host}:${port}`,\n [NET_PEER_NAME]: host,\n [NET_PEER_PORT]: port,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n };\n}\n\n// ioredis re-enters `sendCommand` with the same command object when it drains\n// the offline queue on connect which leads to duplicate spans.\n// Track commands we've already traced so each logical command produces one span.\nconst tracedCommands = new WeakSet<object>();\n\n/**\n * Builds the db span for an `orchestrion:ioredis:command` payload, or returns `undefined` to skip\n * it: for a non-command payload, or the offline-queue re-send of an already-traced command.\n *\n * Exported for unit testing.\n */\nexport function startIORedisCommandSpan(data: IORedisCommandContext): Span | undefined {\n const command = data.arguments?.[0] as RedisCommand | undefined;\n if (!command || typeof command !== 'object') {\n return undefined;\n }\n // guard against duplicate spans\n if (tracedCommands.has(command)) {\n return undefined;\n }\n tracedCommands.add(command);\n const { host, port } = getConnectionOptions(data.self);\n const statement = defaultDbStatementSerializer(command.name, command.args ?? []);\n return startInactiveSpan({\n name: statement,\n op: 'db',\n attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: statement },\n });\n}\n\nconst _ioredisChannelIntegration = ((options: IORedisChannelIntegrationOptions = {}) => {\n const responseHook = options.responseHook;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // `tracingChannel` is unavailable before Node 18.19.\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD &&\n debug.log(`[orchestrion:ioredis] subscribing to \"${CHANNELS.IOREDIS_COMMAND}\"/\"${CHANNELS.IOREDIS_CONNECT}\"`);\n\n const commandChannel = diagnosticsChannel.tracingChannel<IORedisCommandContext, IORedisCommandContext>(\n CHANNELS.IOREDIS_COMMAND,\n );\n const connectChannel = diagnosticsChannel.tracingChannel<IORedisConnectContext, IORedisConnectContext>(\n CHANNELS.IOREDIS_CONNECT,\n );\n\n // `bindTracingChannelToSpan` uses `bindStore`, which needs the async-context\n // binding that `initOpenTelemetry()` registers after integration `setupOnce` —\n // defer until it's available (matches the native redis diagnostics-channel subscriber).\n waitForTracingChannelBinding(() => {\n bindTracingChannelToSpan(commandChannel, startIORedisCommandSpan, {\n // ioredis' `requireParentSpan` default: only create a span under an active span.\n requiresParentSpan: true,\n beforeSpanEnd(span, data) {\n if ('error' in data || !responseHook) {\n return;\n }\n const command = data.arguments?.[0] as RedisCommand | undefined;\n if (command) {\n runResponseHook(responseHook, span, command, data.result);\n }\n },\n });\n\n bindTracingChannelToSpan(\n connectChannel,\n data => {\n const { host, port } = getConnectionOptions(data.self);\n return startInactiveSpan({\n name: 'connect',\n op: 'db',\n attributes: { ...connectionAttributes(host, port), [DB_STATEMENT]: 'connect' },\n });\n },\n { requiresParentSpan: true },\n );\n });\n },\n };\n}) satisfies IntegrationFn;\n\nfunction runResponseHook(hook: IORedisResponseHook, span: Span, command: RedisCommand, result: unknown): void {\n try {\n hook(span, command.name, command.args, result);\n } catch {\n // never let a user-provided response hook break instrumentation\n }\n}\n\n/**\n * EXPERIMENTAL — orchestrion-driven ioredis integration. Subscribes to\n * `orchestrion:ioredis:command` / `:connect` (injected into ioredis' `<5.11.0`\n * `sendCommand`/`connect`) and creates db spans matching\n * `@opentelemetry/instrumentation-ioredis`. Requires the orchestrion runtime hook\n * or bundler plugin.\n */\nexport const ioredisChannelIntegration = defineIntegration(_ioredisChannelIntegration);\n"],"names":["DB_SYSTEM","NET_PEER_NAME","NET_PEER_PORT","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defaultDbStatementSerializer","startInactiveSpan","DB_STATEMENT","DEBUG_BUILD","debug","CHANNELS","waitForTracingChannelBinding","bindTracingChannelToSpan","defineIntegration"],"mappings":";;;;;;;;;;AAsBA,MAAM,gBAAA,GAAmB,SAAA;AAEzB,MAAM,MAAA,GAAS,2BAAA;AAGf,MAAM,yBAAA,GAA4B,sBAAA;AA4BlC,SAAS,qBAAqB,IAAA,EAAqE;AACjG,EAAA,OAAO,EAAE,MAAM,IAAA,EAAM,OAAA,E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