@sentry/server-utils 10.64.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 +123 -0
- package/build/cjs/graphql/graphql-dc-subscriber.js.map +1 -0
- package/build/cjs/graphql/index.js +23 -0
- package/build/cjs/graphql/index.js.map +1 -0
- package/build/cjs/graphql/utils.js +92 -0
- package/build/cjs/graphql/utils.js.map +1 -0
- package/build/cjs/index.js +13 -11
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/amqplib.js +420 -0
- package/build/cjs/integrations/tracing-channel/amqplib.js.map +1 -0
- 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/express/index.js +24 -0
- package/build/cjs/integrations/tracing-channel/express/index.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/express/instrumentation.js +173 -0
- package/build/cjs/integrations/tracing-channel/express/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/express/route.js +76 -0
- package/build/cjs/integrations/tracing-channel/express/route.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js +1 -1
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js.map +1 -1
- 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/google-genai.js +96 -0
- package/build/cjs/integrations/tracing-channel/google-genai.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/graphql/constants.js +26 -0
- package/build/cjs/integrations/tracing-channel/graphql/constants.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/graphql/index.js +66 -0
- package/build/cjs/integrations/tracing-channel/graphql/index.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/graphql/resolvers.js +168 -0
- package/build/cjs/integrations/tracing-channel/graphql/resolvers.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/graphql/spans.js +102 -0
- package/build/cjs/integrations/tracing-channel/graphql/spans.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/ioredis.js +35 -32
- 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/mysql.js +1 -1
- package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/mysql2.js +83 -0
- package/build/cjs/integrations/tracing-channel/mysql2.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/openai.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/postgres-js.js +191 -0
- package/build/cjs/integrations/tracing-channel/postgres-js.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/postgres.js +5 -5
- package/build/cjs/integrations/tracing-channel/postgres.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/redis.js +227 -0
- package/build/cjs/integrations/tracing-channel/redis.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/vercel-ai.js +2 -2
- package/build/cjs/integrations/tracing-channel/vercel-ai.js.map +1 -1
- package/build/cjs/mongoose/mongoose-dc-subscriber.js +1 -1
- package/build/cjs/mongoose/mongoose-dc-subscriber.js.map +1 -1
- package/build/cjs/mysql2/index.js +23 -0
- package/build/cjs/mysql2/index.js.map +1 -0
- package/build/cjs/mysql2/mysql2-dc-subscriber.js +68 -0
- package/build/cjs/mysql2/mysql2-dc-subscriber.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 +53 -11
- package/build/cjs/orchestrion/channels.js.map +1 -1
- package/build/cjs/orchestrion/config/amqplib.js +81 -0
- package/build/cjs/orchestrion/config/amqplib.js.map +1 -0
- package/build/cjs/orchestrion/config/dataloader.js +53 -0
- package/build/cjs/orchestrion/config/dataloader.js.map +1 -0
- package/build/cjs/orchestrion/config/express.js +76 -0
- package/build/cjs/orchestrion/config/express.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/google-genai.js +38 -0
- package/build/cjs/orchestrion/config/google-genai.js.map +1 -0
- package/build/cjs/orchestrion/config/graphql.js +28 -0
- package/build/cjs/orchestrion/config/graphql.js.map +1 -0
- package/build/cjs/orchestrion/config/index.js +59 -14
- 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/postgres.js +50 -0
- package/build/cjs/orchestrion/config/postgres.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/redis.js +76 -0
- package/build/cjs/orchestrion/config/redis.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/config/vercel-ai.js +18 -14
- package/build/cjs/orchestrion/config/vercel-ai.js.map +1 -1
- package/build/cjs/orchestrion/detect.js +12 -11
- package/build/cjs/orchestrion/detect.js.map +1 -1
- package/build/cjs/orchestrion/index.js +33 -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/redis/index.js +23 -0
- package/build/cjs/redis/index.js.map +1 -0
- package/build/cjs/redis/redis-dc-subscriber.js +23 -35
- package/build/cjs/redis/redis-dc-subscriber.js.map +1 -1
- package/build/cjs/tracing-channel.js +7 -6
- package/build/cjs/tracing-channel.js.map +1 -1
- package/build/cjs/vercel-ai/util.js +112 -0
- package/build/cjs/vercel-ai/util.js.map +1 -0
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +138 -74
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/cjs/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.js → vercel-ai-orchestrion-subscriber.js} +153 -23
- package/build/cjs/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -0
- package/build/esm/graphql/graphql-dc-subscriber.js +116 -0
- package/build/esm/graphql/graphql-dc-subscriber.js.map +1 -0
- package/build/esm/graphql/index.js +21 -0
- package/build/esm/graphql/index.js.map +1 -0
- package/build/esm/graphql/utils.js +87 -0
- package/build/esm/graphql/utils.js.map +1 -0
- package/build/esm/index.js +4 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/tracing-channel/amqplib.js +418 -0
- package/build/esm/integrations/tracing-channel/amqplib.js.map +1 -0
- package/build/esm/integrations/tracing-channel/anthropic.js +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/express/index.js +22 -0
- package/build/esm/integrations/tracing-channel/express/index.js.map +1 -0
- package/build/esm/integrations/tracing-channel/express/instrumentation.js +171 -0
- package/build/esm/integrations/tracing-channel/express/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing-channel/express/route.js +68 -0
- package/build/esm/integrations/tracing-channel/express/route.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js +2 -2
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js.map +1 -1
- 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/google-genai.js +94 -0
- package/build/esm/integrations/tracing-channel/google-genai.js.map +1 -0
- package/build/esm/integrations/tracing-channel/graphql/constants.js +14 -0
- package/build/esm/integrations/tracing-channel/graphql/constants.js.map +1 -0
- package/build/esm/integrations/tracing-channel/graphql/index.js +63 -0
- package/build/esm/integrations/tracing-channel/graphql/index.js.map +1 -0
- package/build/esm/integrations/tracing-channel/graphql/resolvers.js +164 -0
- package/build/esm/integrations/tracing-channel/graphql/resolvers.js.map +1 -0
- package/build/esm/integrations/tracing-channel/graphql/spans.js +96 -0
- package/build/esm/integrations/tracing-channel/graphql/spans.js.map +1 -0
- package/build/esm/integrations/tracing-channel/ioredis.js +36 -34
- 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/mysql.js +2 -2
- package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/esm/integrations/tracing-channel/mysql2.js +81 -0
- package/build/esm/integrations/tracing-channel/mysql2.js.map +1 -0
- package/build/esm/integrations/tracing-channel/openai.js +1 -1
- package/build/esm/integrations/tracing-channel/openai.js.map +1 -1
- package/build/esm/integrations/tracing-channel/postgres-js.js +189 -0
- package/build/esm/integrations/tracing-channel/postgres-js.js.map +1 -0
- package/build/esm/integrations/tracing-channel/postgres.js +6 -6
- package/build/esm/integrations/tracing-channel/postgres.js.map +1 -1
- package/build/esm/integrations/tracing-channel/redis.js +225 -0
- package/build/esm/integrations/tracing-channel/redis.js.map +1 -0
- package/build/esm/integrations/tracing-channel/vercel-ai.js +1 -1
- package/build/esm/integrations/tracing-channel/vercel-ai.js.map +1 -1
- package/build/esm/mongoose/mongoose-dc-subscriber.js +2 -2
- package/build/esm/mongoose/mongoose-dc-subscriber.js.map +1 -1
- package/build/esm/mysql2/index.js +21 -0
- package/build/esm/mysql2/index.js.map +1 -0
- package/build/esm/mysql2/mysql2-dc-subscriber.js +62 -0
- package/build/esm/mysql2/mysql2-dc-subscriber.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 +53 -11
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config/amqplib.js +78 -0
- package/build/esm/orchestrion/config/amqplib.js.map +1 -0
- package/build/esm/orchestrion/config/dataloader.js +50 -0
- package/build/esm/orchestrion/config/dataloader.js.map +1 -0
- package/build/esm/orchestrion/config/express.js +73 -0
- package/build/esm/orchestrion/config/express.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/google-genai.js +35 -0
- package/build/esm/orchestrion/config/google-genai.js.map +1 -0
- package/build/esm/orchestrion/config/graphql.js +25 -0
- package/build/esm/orchestrion/config/graphql.js.map +1 -0
- package/build/esm/orchestrion/config/index.js +59 -15
- 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/postgres.js +47 -0
- package/build/esm/orchestrion/config/postgres.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/redis.js +73 -0
- package/build/esm/orchestrion/config/redis.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/config/vercel-ai.js +18 -14
- package/build/esm/orchestrion/config/vercel-ai.js.map +1 -1
- package/build/esm/orchestrion/detect.js +13 -12
- package/build/esm/orchestrion/detect.js.map +1 -1
- package/build/esm/orchestrion/index.js +23 -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/redis/index.js +21 -0
- package/build/esm/redis/index.js.map +1 -0
- package/build/esm/redis/redis-dc-subscriber.js +24 -36
- package/build/esm/redis/redis-dc-subscriber.js.map +1 -1
- package/build/esm/tracing-channel.js +8 -7
- package/build/esm/tracing-channel.js.map +1 -1
- package/build/esm/vercel-ai/util.js +106 -0
- package/build/esm/vercel-ai/util.js.map +1 -0
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +121 -59
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/esm/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.js → vercel-ai-orchestrion-subscriber.js} +153 -23
- package/build/esm/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -0
- package/build/types/graphql/graphql-dc-subscriber.d.ts +94 -0
- package/build/types/graphql/graphql-dc-subscriber.d.ts.map +1 -0
- package/build/types/graphql/index.d.ts +12 -0
- package/build/types/graphql/index.d.ts.map +1 -0
- package/build/types/graphql/utils.d.ts +36 -0
- package/build/types/graphql/utils.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/amqplib.d.ts +11 -0
- package/build/types/integrations/tracing-channel/amqplib.d.ts.map +1 -0
- 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/express/index.d.ts +18 -0
- package/build/types/integrations/tracing-channel/express/index.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/express/instrumentation.d.ts +4 -0
- package/build/types/integrations/tracing-channel/express/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/express/route.d.ts +28 -0
- package/build/types/integrations/tracing-channel/express/route.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/express/types.d.ts +64 -0
- package/build/types/integrations/tracing-channel/express/types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts.map +1 -1
- 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/google-genai.d.ts +12 -0
- package/build/types/integrations/tracing-channel/google-genai.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/constants.d.ts +12 -0
- package/build/types/integrations/tracing-channel/graphql/constants.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/graphql-types.d.ts +135 -0
- package/build/types/integrations/tracing-channel/graphql/graphql-types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/index.d.ts +28 -0
- package/build/types/integrations/tracing-channel/graphql/index.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/resolvers.d.ts +13 -0
- package/build/types/integrations/tracing-channel/graphql/resolvers.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/spans.d.ts +17 -0
- package/build/types/integrations/tracing-channel/graphql/spans.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/graphql/types.d.ts +25 -0
- package/build/types/integrations/tracing-channel/graphql/types.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/mysql.d.ts.map +1 -1
- 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/integrations/tracing-channel/openai.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/postgres-js.d.ts +26 -0
- package/build/types/integrations/tracing-channel/postgres-js.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/postgres.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/redis.d.ts +16 -0
- package/build/types/integrations/tracing-channel/redis.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/vercel-ai.d.ts +1 -1
- package/build/types/mongoose/mongoose-dc-subscriber.d.ts.map +1 -1
- package/build/types/mysql2/index.d.ts +11 -0
- package/build/types/mysql2/index.d.ts.map +1 -0
- package/build/types/mysql2/mysql2-dc-subscriber.d.ts +59 -0
- package/build/types/mysql2/mysql2-dc-subscriber.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 +71 -10
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/amqplib.d.ts +66 -0
- package/build/types/orchestrion/config/amqplib.d.ts.map +1 -0
- 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/express.d.ts +32 -0
- package/build/types/orchestrion/config/express.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/google-genai.d.ts +30 -0
- package/build/types/orchestrion/config/google-genai.d.ts.map +1 -0
- package/build/types/orchestrion/config/graphql.d.ts +29 -0
- package/build/types/orchestrion/config/graphql.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/postgres.d.ts +9 -0
- package/build/types/orchestrion/config/postgres.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/redis.d.ts +37 -0
- package/build/types/orchestrion/config/redis.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/config/vercel-ai.d.ts +1 -0
- package/build/types/orchestrion/config/vercel-ai.d.ts.map +1 -1
- 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 +55 -4
- 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/redis/index.d.ts +18 -0
- package/build/types/redis/index.d.ts.map +1 -0
- package/build/types/redis/redis-dc-subscriber.d.ts +0 -5
- package/build/types/redis/redis-dc-subscriber.d.ts.map +1 -1
- package/build/types/tracing-channel.d.ts +5 -0
- package/build/types/tracing-channel.d.ts.map +1 -1
- package/build/types/vercel-ai/util.d.ts +30 -0
- package/build/types/vercel-ai/util.d.ts.map +1 -0
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +6 -2
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
- package/build/types/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.d.ts → vercel-ai-orchestrion-subscriber.d.ts} +1 -1
- package/build/types/vercel-ai/vercel-ai-orchestrion-subscriber.d.ts.map +1 -0
- package/build/types-ts3.8/graphql/graphql-dc-subscriber.d.ts +94 -0
- package/build/types-ts3.8/graphql/index.d.ts +12 -0
- package/build/types-ts3.8/graphql/utils.d.ts +36 -0
- package/build/types-ts3.8/index.d.ts +6 -2
- package/build/types-ts3.8/integrations/tracing-channel/amqplib.d.ts +11 -0
- package/build/types-ts3.8/integrations/tracing-channel/dataloader.d.ts +11 -0
- package/build/types-ts3.8/integrations/tracing-channel/express/index.d.ts +18 -0
- package/build/types-ts3.8/integrations/tracing-channel/express/instrumentation.d.ts +4 -0
- package/build/types-ts3.8/integrations/tracing-channel/express/route.d.ts +28 -0
- package/build/types-ts3.8/integrations/tracing-channel/express/types.d.ts +64 -0
- package/build/types-ts3.8/integrations/tracing-channel/generic-pool.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/google-genai.d.ts +12 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/constants.d.ts +12 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/graphql-types.d.ts +135 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/index.d.ts +30 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/resolvers.d.ts +13 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/spans.d.ts +17 -0
- package/build/types-ts3.8/integrations/tracing-channel/graphql/types.d.ts +25 -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/integrations/tracing-channel/postgres-js.d.ts +26 -0
- package/build/types-ts3.8/integrations/tracing-channel/redis.d.ts +16 -0
- package/build/types-ts3.8/integrations/tracing-channel/vercel-ai.d.ts +1 -1
- package/build/types-ts3.8/mysql2/index.d.ts +11 -0
- package/build/types-ts3.8/mysql2/mysql2-dc-subscriber.d.ts +59 -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 +71 -10
- package/build/types-ts3.8/orchestrion/config/amqplib.d.ts +66 -0
- package/build/types-ts3.8/orchestrion/config/dataloader.d.ts +46 -0
- package/build/types-ts3.8/orchestrion/config/express.d.ts +32 -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/google-genai.d.ts +30 -0
- package/build/types-ts3.8/orchestrion/config/graphql.d.ts +29 -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/postgres.d.ts +9 -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/redis.d.ts +37 -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/config/vercel-ai.d.ts +1 -0
- package/build/types-ts3.8/orchestrion/detect.d.ts +3 -10
- package/build/types-ts3.8/orchestrion/index.d.ts +57 -4
- 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/redis/index.d.ts +18 -0
- package/build/types-ts3.8/redis/redis-dc-subscriber.d.ts +0 -5
- package/build/types-ts3.8/tracing-channel.d.ts +5 -0
- package/build/types-ts3.8/vercel-ai/util.d.ts +30 -0
- package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +6 -2
- package/build/types-ts3.8/vercel-ai/{vercel-ai-orchestrion-v6-subscriber.d.ts → vercel-ai-orchestrion-subscriber.d.ts} +1 -1
- package/package.json +41 -8
- package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +0 -1
- package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +0 -1
- package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts.map +0 -1
|
@@ -5,14 +5,17 @@ const debugBuild = require('../debug-build.js');
|
|
|
5
5
|
const channels = require('../orchestrion/channels.js');
|
|
6
6
|
const tracingChannel = require('../tracing-channel.js');
|
|
7
7
|
const vercelAiDcSubscriber = require('./vercel-ai-dc-subscriber.js');
|
|
8
|
+
const util = require('./util.js');
|
|
8
9
|
|
|
9
10
|
const PATCHED = /* @__PURE__ */ Symbol("SentryVercelAiModelPatched");
|
|
11
|
+
const TOOL_PATCHED = /* @__PURE__ */ Symbol("SentryVercelAiToolPatched");
|
|
10
12
|
let callIdCounter = 0;
|
|
11
13
|
function nextCallId() {
|
|
12
14
|
return `v6-${++callIdCounter}`;
|
|
13
15
|
}
|
|
14
16
|
const messages = /* @__PURE__ */ new WeakMap();
|
|
15
17
|
const operationSpans = /* @__PURE__ */ new WeakSet();
|
|
18
|
+
const toolCallSpans = /* @__PURE__ */ new WeakSet();
|
|
16
19
|
const callIdBySpan = /* @__PURE__ */ new WeakMap();
|
|
17
20
|
const recordingBySpan = /* @__PURE__ */ new WeakMap();
|
|
18
21
|
const suppressedTelemetry = /* @__PURE__ */ new WeakSet();
|
|
@@ -25,6 +28,7 @@ function subscribeVercelAiOrchestrionChannels(tracingChannel, options = {}) {
|
|
|
25
28
|
try {
|
|
26
29
|
bindOperation(tracingChannel, channels.CHANNELS.VERCEL_AI_GENERATE_TEXT, buildTextMessage("generateText"), options);
|
|
27
30
|
bindOperation(tracingChannel, channels.CHANNELS.VERCEL_AI_STREAM_TEXT, buildTextMessage("streamText"), options);
|
|
31
|
+
bindOperation(tracingChannel, channels.CHANNELS.VERCEL_AI_GENERATE_OBJECT, buildTextMessage("generateObject"), options);
|
|
28
32
|
bindOperation(
|
|
29
33
|
tracingChannel,
|
|
30
34
|
channels.CHANNELS.VERCEL_AI_EMBED,
|
|
@@ -81,8 +85,8 @@ function subscribeVercelAiOrchestrionChannels(tracingChannel, options = {}) {
|
|
|
81
85
|
function bindOperation(tracingChannel$1, channelName, build, options) {
|
|
82
86
|
const channel = tracingChannel$1(channelName);
|
|
83
87
|
const buildOperationSpan = (data) => {
|
|
84
|
-
const callOptions =
|
|
85
|
-
const telemetry =
|
|
88
|
+
const callOptions = core.isObjectLike(data.arguments[0]) ? data.arguments[0] : {};
|
|
89
|
+
const telemetry = core.isObjectLike(callOptions.experimental_telemetry) ? callOptions.experimental_telemetry : {};
|
|
86
90
|
if (telemetry.isEnabled === false && !suppressedTelemetry.has(telemetry)) {
|
|
87
91
|
return void 0;
|
|
88
92
|
}
|
|
@@ -92,11 +96,20 @@ function bindOperation(tracingChannel$1, channelName, build, options) {
|
|
|
92
96
|
if (span) {
|
|
93
97
|
messages.set(data, message);
|
|
94
98
|
operationSpans.add(span);
|
|
95
|
-
|
|
99
|
+
if (message.type === "executeTool") {
|
|
100
|
+
toolCallSpans.add(span);
|
|
101
|
+
}
|
|
102
|
+
const callId = util.asString(message.event.callId);
|
|
96
103
|
if (callId) {
|
|
97
104
|
callIdBySpan.set(span, callId);
|
|
98
105
|
}
|
|
99
106
|
recordingBySpan.set(span, recording(telemetry));
|
|
107
|
+
if (core.isObjectLike(callOptions.tools)) {
|
|
108
|
+
patchOperationTools(callOptions.tools, options);
|
|
109
|
+
}
|
|
110
|
+
if (core.isObjectLike(callOptions.model) && callOptions.model.specificationVersion === "v1") {
|
|
111
|
+
patchModelMethods(callOptions.model, options);
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
114
|
return span;
|
|
102
115
|
};
|
|
@@ -117,10 +130,43 @@ function bindOperation(tracingChannel$1, channelName, build, options) {
|
|
|
117
130
|
vercelAiDcSubscriber.clearOperationId(message);
|
|
118
131
|
}
|
|
119
132
|
messages.delete(data);
|
|
120
|
-
}
|
|
133
|
+
},
|
|
134
|
+
// `streamText` returns synchronously, so its operation span would otherwise end before the stream
|
|
135
|
+
// drains — losing the aggregate usage/output. Defer the end and await the result's completion
|
|
136
|
+
// promises (`totalUsage`/`text`/…, which resolve on drain), mirroring how v7's channel defers the
|
|
137
|
+
// operation span on the SDK's total-usage promise.
|
|
138
|
+
deferSpanEnd: ({ data, end }) => deferStreamTextOperationEnd(data, end)
|
|
121
139
|
}
|
|
122
140
|
);
|
|
123
141
|
}
|
|
142
|
+
function deferStreamTextOperationEnd(data, end) {
|
|
143
|
+
if (messages.get(data)?.type !== "streamText" || "error" in data || !isStreamingResult(data.result)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const streamResult = data.result;
|
|
147
|
+
void (async () => {
|
|
148
|
+
try {
|
|
149
|
+
const [usage, text, toolCalls, finishReason, response] = await Promise.all([
|
|
150
|
+
streamResult.totalUsage ?? streamResult.usage,
|
|
151
|
+
streamResult.text,
|
|
152
|
+
streamResult.toolCalls,
|
|
153
|
+
streamResult.finishReason,
|
|
154
|
+
streamResult.response
|
|
155
|
+
]);
|
|
156
|
+
data.result = { usage, text, toolCalls, finishReason, response };
|
|
157
|
+
end();
|
|
158
|
+
} catch (error) {
|
|
159
|
+
end(error);
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
function isStreamingResult(result) {
|
|
165
|
+
return core.isObjectLike(result) && (isThenable(result.totalUsage) || isThenable(result.usage));
|
|
166
|
+
}
|
|
167
|
+
function isThenable(value) {
|
|
168
|
+
return core.isObjectLike(value) && typeof value.then === "function";
|
|
169
|
+
}
|
|
124
170
|
function suppressNativeTelemetry(callOptions, telemetry) {
|
|
125
171
|
if (telemetry.isEnabled !== true) {
|
|
126
172
|
return;
|
|
@@ -133,15 +179,10 @@ function subscribeResolveLanguageModel(tracingChannel, channelName, options) {
|
|
|
133
179
|
tracingChannel(channelName).subscribe({
|
|
134
180
|
end(rawCtx) {
|
|
135
181
|
const ctx = rawCtx;
|
|
136
|
-
if (!
|
|
182
|
+
if (!core.isObjectLike(ctx.result)) {
|
|
137
183
|
return;
|
|
138
184
|
}
|
|
139
|
-
|
|
140
|
-
if (!model[PATCHED]) {
|
|
141
|
-
model[PATCHED] = true;
|
|
142
|
-
patchModelMethod(model, "doGenerate", options);
|
|
143
|
-
patchModelMethod(model, "doStream", options);
|
|
144
|
-
}
|
|
185
|
+
patchModelMethods(ctx.result, options);
|
|
145
186
|
},
|
|
146
187
|
start() {
|
|
147
188
|
},
|
|
@@ -157,6 +198,14 @@ function resolveModelCallParent() {
|
|
|
157
198
|
const active = core.getActiveSpan();
|
|
158
199
|
return active && operationSpans.has(active) ? active : void 0;
|
|
159
200
|
}
|
|
201
|
+
function patchModelMethods(model, options) {
|
|
202
|
+
if (model[PATCHED]) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
model[PATCHED] = true;
|
|
206
|
+
patchModelMethod(model, "doGenerate", options);
|
|
207
|
+
patchModelMethod(model, "doStream", options);
|
|
208
|
+
}
|
|
160
209
|
function patchModelMethod(model, method, options) {
|
|
161
210
|
const original = model[method];
|
|
162
211
|
if (typeof original !== "function") {
|
|
@@ -167,7 +216,7 @@ function patchModelMethod(model, method, options) {
|
|
|
167
216
|
if (!parent) {
|
|
168
217
|
return Promise.resolve(original.apply(this, args));
|
|
169
218
|
}
|
|
170
|
-
const callArgs =
|
|
219
|
+
const callArgs = core.isObjectLike(args[0]) ? args[0] : {};
|
|
171
220
|
const callId = callIdBySpan.get(parent);
|
|
172
221
|
const message = {
|
|
173
222
|
type: "languageModelCall",
|
|
@@ -175,7 +224,9 @@ function patchModelMethod(model, method, options) {
|
|
|
175
224
|
callId,
|
|
176
225
|
provider: model.provider,
|
|
177
226
|
modelId: model.modelId,
|
|
178
|
-
|
|
227
|
+
// v4 nests the tool list under `mode.tools` (the `LanguageModelV1` call shape); v5+ passes a
|
|
228
|
+
// top-level `tools` array. Reading both keeps `available_tools` populated on the model-call span.
|
|
229
|
+
tools: callArgs.tools ?? (core.isObjectLike(callArgs.mode) ? callArgs.mode.tools : void 0),
|
|
179
230
|
messages: callArgs.prompt,
|
|
180
231
|
// Inherit the enclosing operation's per-call recording flags so inputs/tools/outputs are recorded on
|
|
181
232
|
// the model-call span whenever they are on the parent `invoke_agent` span.
|
|
@@ -200,6 +251,26 @@ function patchModelMethod(model, method, options) {
|
|
|
200
251
|
try {
|
|
201
252
|
const result = Promise.resolve(original.apply(this, args));
|
|
202
253
|
return result.then((value) => {
|
|
254
|
+
if (method === "doStream" && core.isObjectLike(value) && util.isReadableStream(value.stream)) {
|
|
255
|
+
value.stream = util.tapModelCallStream(
|
|
256
|
+
value.stream,
|
|
257
|
+
(final) => {
|
|
258
|
+
message.result = { ...value, ...vercelAiDcSubscriber.streamedResultToChannelResult(final) };
|
|
259
|
+
vercelAiDcSubscriber.enrichSpanOnEnd(span, message, options);
|
|
260
|
+
span.end();
|
|
261
|
+
clearStreamCallId();
|
|
262
|
+
},
|
|
263
|
+
(error) => {
|
|
264
|
+
span.setStatus({
|
|
265
|
+
code: core.SPAN_STATUS_ERROR,
|
|
266
|
+
message: error instanceof Error ? error.message : "unknown_error"
|
|
267
|
+
});
|
|
268
|
+
span.end();
|
|
269
|
+
clearStreamCallId();
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
203
274
|
message.result = value;
|
|
204
275
|
vercelAiDcSubscriber.enrichSpanOnEnd(span, message, options);
|
|
205
276
|
span.end();
|
|
@@ -211,15 +282,76 @@ function patchModelMethod(model, method, options) {
|
|
|
211
282
|
}
|
|
212
283
|
};
|
|
213
284
|
}
|
|
285
|
+
function patchOperationTools(tools, options) {
|
|
286
|
+
try {
|
|
287
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
288
|
+
if (core.isObjectLike(tool)) {
|
|
289
|
+
patchToolExecute(toolName, tool, tools, options);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch {
|
|
293
|
+
debugBuild.DEBUG_BUILD && core.debug.log("Vercel AI orchestrion tool patching failed.");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function patchToolExecute(toolName, tool, tools, options) {
|
|
297
|
+
const original = tool.execute;
|
|
298
|
+
if (typeof original !== "function" || tool[TOOL_PATCHED]) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
tool[TOOL_PATCHED] = true;
|
|
302
|
+
tool.execute = function(input, ...rest) {
|
|
303
|
+
const parent = resolveModelCallParent();
|
|
304
|
+
if (!parent || toolCallSpans.has(parent)) {
|
|
305
|
+
return original.apply(this, [input, ...rest]);
|
|
306
|
+
}
|
|
307
|
+
const callOptions = core.isObjectLike(rest[0]) ? rest[0] : {};
|
|
308
|
+
const message = {
|
|
309
|
+
type: "executeTool",
|
|
310
|
+
event: {
|
|
311
|
+
callId: callIdBySpan.get(parent),
|
|
312
|
+
toolCall: { toolName, toolCallId: util.asString(callOptions.toolCallId), input },
|
|
313
|
+
// The `tools` record (keyed by name) lets the shared core backfill the tool's `description`.
|
|
314
|
+
tools,
|
|
315
|
+
// Inherit the enclosing operation's per-call recording flags so tool inputs/outputs are recorded
|
|
316
|
+
// whenever they are on the parent `invoke_agent` span.
|
|
317
|
+
...recordingBySpan.get(parent)
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
const span = core.withActiveSpan(parent, () => vercelAiDcSubscriber.createSpanFromMessage(message, options));
|
|
321
|
+
if (!span) {
|
|
322
|
+
return original.apply(this, [input, ...rest]);
|
|
323
|
+
}
|
|
324
|
+
const failSpan = (error) => {
|
|
325
|
+
vercelAiDcSubscriber.captureToolError(span, message, error);
|
|
326
|
+
span.end();
|
|
327
|
+
throw error;
|
|
328
|
+
};
|
|
329
|
+
try {
|
|
330
|
+
const result = Promise.resolve(original.apply(this, [input, ...rest]));
|
|
331
|
+
return result.then((value) => {
|
|
332
|
+
message.result = { output: value };
|
|
333
|
+
vercelAiDcSubscriber.enrichSpanOnEnd(span, message, options);
|
|
334
|
+
span.end();
|
|
335
|
+
return value;
|
|
336
|
+
}, failSpan);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
return failSpan(error);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
214
342
|
function buildTextMessage(type) {
|
|
215
343
|
return (options, telemetry) => ({
|
|
216
344
|
type,
|
|
217
345
|
event: {
|
|
218
346
|
callId: nextCallId(),
|
|
219
347
|
operationId: `ai.${type}`,
|
|
220
|
-
functionId: asString(telemetry.functionId),
|
|
348
|
+
functionId: util.asString(telemetry.functionId),
|
|
221
349
|
...modelFields(options.model),
|
|
222
350
|
maxRetries: options.maxRetries,
|
|
351
|
+
// The `ai` SDK takes the system prompt as a top-level `system` option (all of v4/v5/v6); the
|
|
352
|
+
// shared core lifts `event.instructions` into the system-instructions attribute, matching v7's
|
|
353
|
+
// native channel (which carries it as a distinct field rather than inside the messages array).
|
|
354
|
+
instructions: util.asString(options.system),
|
|
223
355
|
// Normalize to the message-array shape the shared core (and v7's channel) expects: a bare string
|
|
224
356
|
// `prompt` becomes a single user message, matching the SDK's own normalization.
|
|
225
357
|
messages: normalizePromptMessages(options),
|
|
@@ -237,20 +369,18 @@ function normalizePromptMessages(options) {
|
|
|
237
369
|
return options.messages ?? options.prompt;
|
|
238
370
|
}
|
|
239
371
|
function recording(telemetry) {
|
|
240
|
-
|
|
372
|
+
const enabledDefault = telemetry.isEnabled === true ? true : void 0;
|
|
373
|
+
return {
|
|
374
|
+
recordInputs: telemetry.recordInputs ?? enabledDefault,
|
|
375
|
+
recordOutputs: telemetry.recordOutputs ?? enabledDefault
|
|
376
|
+
};
|
|
241
377
|
}
|
|
242
378
|
function modelFields(model) {
|
|
243
379
|
return { provider: modelField(model, "provider"), modelId: modelField(model, "modelId") };
|
|
244
380
|
}
|
|
245
381
|
function modelField(model, field) {
|
|
246
|
-
return
|
|
247
|
-
}
|
|
248
|
-
function asString(value) {
|
|
249
|
-
return typeof value === "string" ? value : void 0;
|
|
250
|
-
}
|
|
251
|
-
function isRecord(value) {
|
|
252
|
-
return typeof value === "object" && value !== null;
|
|
382
|
+
return core.isObjectLike(model) ? util.asString(model[field]) : void 0;
|
|
253
383
|
}
|
|
254
384
|
|
|
255
385
|
exports.subscribeVercelAiOrchestrionChannels = subscribeVercelAiOrchestrionChannels;
|
|
256
|
-
//# sourceMappingURL=vercel-ai-orchestrion-
|
|
386
|
+
//# sourceMappingURL=vercel-ai-orchestrion-subscriber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel-ai-orchestrion-subscriber.js","sources":["../../../src/vercel-ai/vercel-ai-orchestrion-subscriber.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport type { Span } from '@sentry/core';\nimport { debug, getActiveSpan, isObjectLike, SPAN_STATUS_ERROR, withActiveSpan } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { bindTracingChannelToSpan, type TracingChannelPayloadWithSpan } from '../tracing-channel';\nimport {\n captureToolError,\n clearOperationCallId,\n clearOperationId,\n createSpanFromMessage,\n enrichSpanOnEnd,\n streamedResultToChannelResult,\n type VercelAiChannelMessage,\n type VercelAiChannelOptions,\n type VercelAiTracingChannelFactory,\n} from './vercel-ai-dc-subscriber';\nimport { asString, isReadableStream, tapModelCallStream } from './util';\n\n/**\n * v4, v5 & v6 channel adapter for the Vercel AI (`ai`) SDK.\n *\n * `ai` >= 7 publishes a normalized `ai:telemetry` tracing channel natively\n * (consumed by `subscribeVercelAiTracingChannel`). v4/v5/v6 have no such channel, so\n * orchestrion injects `orchestrion:ai:*` channels around the top-level\n * functions (see `orchestrion/config/index.ts`). The injected channels carry only the\n * wrapped call's `{ arguments, result, error }` — NOT v7's normalized `event`\n * object — so this adapter reconstructs an equivalent {@link VercelAiChannelMessage}\n * from each version's argument/result shapes and delegates to the SAME span-building core\n * (`createSpanFromMessage` / `enrichSpanOnEnd`) the v7 subscriber uses, so the\n * emitted spans are identical between v4, v5, v6 and v7. The shared core reads both v4-style\n * (`promptTokens`/`completionTokens`) and v5+-style (`inputTokens`/`outputTokens`) token names.\n *\n * The model call (`languageModelCall` / `generate_content` span) has no\n * injectable definition in `ai`. On v5/v6 we wrap `resolveLanguageModel` (the\n * single chokepoint every model call flows through) and monkey-patch\n * `doGenerate`/`doStream` on the returned model. v4 has no `resolveLanguageModel`\n * — the passed `LanguageModelV1` (`specificationVersion: 'v1'`) is called directly —\n * so we patch its `doGenerate`/`doStream` at the operation start instead (see\n * `buildOperationSpan`), gated on `'v1'` so it never touches v5/v6 models.\n *\n * Tool-call spans differ by version: v6 exposes a per-call `executeToolCall`\n * function orchestrion wraps into its own channel. v4/v5 have no such export (only a\n * batch `executeTools`), so instead we monkey-patch each tool's `execute` from\n * the operation's `tools`. On v6 that patch is inert: `executeToolCall` runs\n * `execute` inside its own tool-call span (the active async context), so the\n * patch sees that span as its parent and skips — only v4/v5 (where the parent is\n * the enclosing `invoke_agent` span) emit the patched span, so v6 never\n * double-counts tool spans.\n */\n\n/** Shape orchestrion's transform attaches to the tracing-channel context. */\ninterface OrchestrionContext {\n arguments: unknown[];\n result?: unknown;\n error?: unknown;\n}\n\n/** Builds the normalized message for a channel from the wrapped call's first-arg options. */\ntype MessageBuilder = (options: Record<string, unknown>, telemetry: Record<string, unknown>) => VercelAiChannelMessage;\n\n/** A resolved `ai` language model — has `doGenerate`/`doStream` and identity fields. */\ninterface ResolvedModel {\n modelId?: string;\n provider?: string;\n doGenerate?: (...args: unknown[]) => Promise<unknown>;\n doStream?: (...args: unknown[]) => Promise<unknown>;\n}\n\nconst PATCHED = Symbol('SentryVercelAiModelPatched');\nconst TOOL_PATCHED = Symbol('SentryVercelAiToolPatched');\n\n/** A resolved model with our patch bookkeeping (idempotency flag). */\ntype PatchableModel = ResolvedModel & { [PATCHED]?: boolean };\n\n/** A tool definition off an operation's `tools`, with our patch bookkeeping. */\ntype PatchableTool = { execute?: (...args: unknown[]) => unknown; [TOOL_PATCHED]?: boolean };\n\n// Per-operation correlation id. No Date/random (unavailable / non-deterministic) — a counter is enough.\nlet callIdCounter = 0;\nfunction nextCallId(): string {\n return `v6-${++callIdCounter}`;\n}\n\n// The message built on `start` for each operation, keyed by the (stable-identity) channel context, so\n// the `beforeSpanEnd` handler can enrich the span from the settled result and clear the `callId` maps.\nconst messages = new WeakMap<object, VercelAiChannelMessage>();\n// The spans we opened for top-level operations, and each one's `callId`. A model call resolves its\n// parent against this set (so it never mis-attributes to the enclosing `main`/user span) and reads the\n// parent's `callId` so its span can be named after the operation (e.g. `ai.streamText.doStream`).\nconst operationSpans = new WeakSet<Span>();\n// Tool-call spans — only v6's `executeToolCall` channel opens these. The v5 tool-`execute` patch\n// consults this to avoid double-counting: `executeToolCall` runs `execute` inside its span (which is\n// therefore the active parent), so a resolved parent in this set means v6 already spanned the call.\nconst toolCallSpans = new WeakSet<Span>();\nconst callIdBySpan = new WeakMap<Span, string>();\n// The operation's per-call recording flags (`experimental_telemetry.recordInputs/recordOutputs`), keyed by\n// its span. A model call carries no telemetry of its own, so it inherits the enclosing operation's flags —\n// otherwise a per-call `recordInputs: true` would record inputs on the `invoke_agent` span but not on the\n// child `generate_content` span (whose event would fall back to the global default). v7's channel forwards\n// these flags on every event, so this keeps v6 identical.\nconst recordingBySpan = new WeakMap<Span, ReturnType<typeof recording>>();\n\n// The `experimental_telemetry` objects we swapped in to suppress `ai`'s native OTel spans (see\n// `suppressNativeTelemetry`). Our skip logic treats `isEnabled === false` as \"user disabled telemetry,\n// emit no span\"; without this set, a call whose options object we already neutralized — or a user-shared\n// telemetry object we replaced on a prior call — would be misread as user-disabled and lose its span.\nconst suppressedTelemetry = new WeakSet<object>();\n\nlet subscribed = false;\n\n/**\n * Subscribe the v6 orchestrion channel adapter. Safe to always call: inert on\n * `ai` >= 7 (those channels are never published) and when orchestrion injection\n * isn't active. Idempotent.\n *\n * `tracingChannel` is the platform-provided factory (the same one passed to\n * `subscribeVercelAiTracingChannel`); `options` pins the recording settings at\n * subscribe time so we never look the integration up per event.\n */\nexport function subscribeVercelAiOrchestrionChannels(\n tracingChannel: VercelAiTracingChannelFactory,\n options: VercelAiChannelOptions = {},\n): void {\n if (subscribed) {\n return;\n }\n subscribed = true;\n\n try {\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_TEXT, buildTextMessage('generateText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_STREAM_TEXT, buildTextMessage('streamText'), options);\n bindOperation(tracingChannel, CHANNELS.VERCEL_AI_GENERATE_OBJECT, buildTextMessage('generateObject'), options);\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED,\n (callOptions, telemetry) => ({\n type: 'embed',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n value: callOptions.value,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EMBED_MANY,\n // `embedMany` takes a `values` array (vs `embed`'s single `value`); the shared core reads it as the\n // embeddings input, matching the OTel path's batch `ai.embedMany` span.\n (callOptions, telemetry) => ({\n type: 'embedMany',\n event: {\n callId: nextCallId(),\n ...modelFields(callOptions.model),\n maxRetries: callOptions.maxRetries,\n values: callOptions.values,\n ...recording(telemetry),\n },\n }),\n options,\n );\n bindOperation(\n tracingChannel,\n CHANNELS.VERCEL_AI_EXECUTE_TOOL_CALL,\n (callOptions, telemetry) => ({\n type: 'executeTool',\n // v6 carries the tool definitions on the executeToolCall args (a record keyed by name);\n // the shared core reads the matching tool's `description` for the span.\n event: {\n callId: nextCallId(),\n toolCall: callOptions.toolCall,\n tools: callOptions.tools,\n ...recording(telemetry),\n },\n }),\n options,\n );\n subscribeResolveLanguageModel(tracingChannel, CHANNELS.VERCEL_AI_RESOLVE_LANGUAGE_MODEL, options);\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI orchestrion channel subscription failed.');\n }\n}\n\n/**\n * Bind one operation channel: `getSpan` opens a span from the message reconstructed out of the wrapped\n * call's first argument; `beforeSpanEnd` enriches it from the settled result (tokens, output messages,\n * finish reasons, …) before the helper ends the span.\n *\n * An operation whose `experimental_telemetry.isEnabled` is explicitly `false` is skipped entirely (no\n * span): the orchestrion channel fires regardless of that flag, whereas v7's native `ai:telemetry`\n * channel is simply not published in that case — so we reproduce v7's \"no telemetry → no span\".\n */\nfunction bindOperation(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n build: MessageBuilder,\n options: VercelAiChannelOptions,\n): void {\n const channel = tracingChannel<OrchestrionContext>(channelName);\n\n // Build the operation span from the wrapped call's first argument and track it (so a model call can\n // resolve it as its parent). `bindTracingChannelToSpan` calls this once at channel `start` and makes\n // the returned span the active async context for the operation's duration — that active span is what\n // `resolveModelCallParent` reads. It also sets `data._sentrySpan`, so we don't here.\n const buildOperationSpan = (data: TracingChannelPayloadWithSpan<OrchestrionContext>): Span | undefined => {\n const callOptions = isObjectLike(data.arguments[0]) ? data.arguments[0] : {};\n const telemetry = isObjectLike(callOptions.experimental_telemetry) ? callOptions.experimental_telemetry : {};\n // `isEnabled === false` means the user opted out — emit no span. But `isEnabled` is also `false` on\n // the telemetry object we swap in to suppress native spans, so don't mistake our own object for a\n // user opt-out (which would drop the span on a call whose options we already neutralized).\n if (telemetry.isEnabled === false && !suppressedTelemetry.has(telemetry)) {\n return undefined;\n }\n const message = build(callOptions, telemetry);\n // Stop `ai` from emitting its own native OTel spans for this call — we build the equivalent spans\n // from the channels, so the SDK's would be duplicates. Reads above have already captured everything\n // we need off `telemetry`.\n suppressNativeTelemetry(callOptions, telemetry);\n const span = createSpanFromMessage(message, options);\n if (span) {\n messages.set(data, message);\n operationSpans.add(span);\n // v6's `executeToolCall` span: tracked so the v5 tool-`execute` patch can recognize (and skip)\n // tool calls it runs, since that patch sees this span as its active parent (see `patchToolExecute`).\n if (message.type === 'executeTool') {\n toolCallSpans.add(span);\n }\n const callId = asString(message.event.callId);\n if (callId) {\n callIdBySpan.set(span, callId);\n }\n recordingBySpan.set(span, recording(telemetry));\n // v5 has no `executeToolCall` channel, so patch each tool's `execute` to emit the tool-call span.\n // Inert on v6 (guarded inside `patchToolExecute` when the parent is `executeToolCall`'s own span).\n if (isObjectLike(callOptions.tools)) {\n patchOperationTools(callOptions.tools, options);\n }\n // v4 has no `resolveLanguageModel` chokepoint — the passed `LanguageModelV1`\n // (`specificationVersion: 'v1'`) is called directly — so patch its `doGenerate`/`doStream`\n // here, at the operation start, instead. v5/v6 models are `'v2'` and are patched via\n // `resolveLanguageModel`, so restricting to `'v1'` keeps this strictly additive and avoids\n // double-patching. Embedding models are also `'v1'` but expose no `doGenerate`/`doStream`, so\n // the patch is a no-op for `embed`/`embedMany`.\n if (isObjectLike(callOptions.model) && callOptions.model.specificationVersion === 'v1') {\n patchModelMethods(callOptions.model as PatchableModel, options);\n }\n }\n return span;\n };\n\n bindTracingChannelToSpan(\n channel,\n (data: TracingChannelPayloadWithSpan<OrchestrionContext>) => buildOperationSpan(data),\n {\n beforeSpanEnd: (span, data) => {\n const message = messages.get(data);\n if (!message) {\n return;\n }\n // The helper's `error` handler already set the span status; only enrich from a successful result.\n if (!('error' in data)) {\n // v6's `executeToolCall` returns the tool result/error object directly, whereas the shared core\n // (matching v7) expects it nested under `output`; wrap it so tool-error detection works.\n message.result = message.type === 'executeTool' ? { output: data.result } : data.result;\n enrichSpanOnEnd(span, message, options);\n }\n // A `streamText` model call runs after this (synchronously-returning) operation's span has\n // already ended, so its `callId` entry must outlive the operation — it's cleared once the model\n // call settles (see `patchModelMethod`). Every other operation can clear here.\n if (message.type !== 'streamText') {\n clearOperationId(message);\n }\n messages.delete(data);\n },\n // `streamText` returns synchronously, so its operation span would otherwise end before the stream\n // drains — losing the aggregate usage/output. Defer the end and await the result's completion\n // promises (`totalUsage`/`text`/…, which resolve on drain), mirroring how v7's channel defers the\n // operation span on the SDK's total-usage promise.\n deferSpanEnd: ({ data, end }) => deferStreamTextOperationEnd(data, end),\n },\n );\n}\n\n/**\n * Keep a streamed `streamText` operation span open until the stream drains, then enrich it from the\n * `StreamTextResult`'s completion promises (usage/output/finish reason) and end it. Returns `false` for\n * anything that isn't a streamed `streamText` result, so the helper ends the span as usual.\n */\nfunction deferStreamTextOperationEnd(\n data: TracingChannelPayloadWithSpan<OrchestrionContext>,\n end: (error?: unknown) => void,\n): boolean {\n if (messages.get(data)?.type !== 'streamText' || 'error' in data || !isStreamingResult(data.result)) {\n return false;\n }\n\n const streamResult = data.result;\n void (async () => {\n try {\n const [usage, text, toolCalls, finishReason, response] = await Promise.all([\n streamResult.totalUsage ?? streamResult.usage,\n streamResult.text,\n streamResult.toolCalls,\n streamResult.finishReason,\n streamResult.response,\n ]);\n // Feed the resolved values back through the shared enrichment: `beforeSpanEnd` reads `data.result`.\n data.result = { usage, text, toolCalls, finishReason, response };\n end();\n } catch (error) {\n end(error);\n }\n })();\n\n return true;\n}\n\n/** A `StreamTextResult` exposes its aggregates as promises (`totalUsage`/`usage`); a settled result does not. */\nfunction isStreamingResult(result: unknown): result is Record<string, PromiseLike<unknown> | undefined> {\n return isObjectLike(result) && (isThenable(result.totalUsage) || isThenable(result.usage));\n}\n\nfunction isThenable(value: unknown): boolean {\n return isObjectLike(value) && typeof value.then === 'function';\n}\n\n/**\n * Neutralize `ai`'s native OpenTelemetry instrumentation for this call by pointing\n * `experimental_telemetry` at a copy with `isEnabled: false`. `ai`'s `getTracer` then returns its\n * internal no-op tracer, so it never creates (nor sets active) the duplicate `ai.*` spans we'd\n * otherwise have to drop.\n *\n * Only a call that explicitly enabled telemetry emits native spans — otherwise `ai` already uses its\n * no-op tracer, so there's nothing to suppress and we leave the user's options untouched. When\n * `isEnabled === true`, `telemetry` is `callOptions.experimental_telemetry` and `callOptions` is the\n * real first argument the SDK will read, so the reassignment takes effect for the wrapped call. We\n * replace rather than mutate in place, so a telemetry object the user shares across calls keeps its own\n * `isEnabled: true`; the replacement is tracked in `suppressedTelemetry` so our skip logic doesn't\n * later read it back as a user opt-out.\n */\nfunction suppressNativeTelemetry(callOptions: Record<string, unknown>, telemetry: Record<string, unknown>): void {\n if (telemetry.isEnabled !== true) {\n return;\n }\n const suppressed = { ...telemetry, isEnabled: false };\n suppressedTelemetry.add(suppressed);\n callOptions.experimental_telemetry = suppressed;\n}\n\n/**\n * `resolveLanguageModel` returns the model every call flows through. We don't span it — on `end` we\n * monkey-patch `doGenerate`/`doStream` on the returned model so each invocation produces a\n * `languageModelCall` span parented to the enclosing invoke_agent span.\n */\nfunction subscribeResolveLanguageModel(\n tracingChannel: VercelAiTracingChannelFactory,\n channelName: string,\n options: VercelAiChannelOptions,\n): void {\n tracingChannel<OrchestrionContext>(channelName).subscribe({\n end(rawCtx) {\n const ctx = rawCtx as OrchestrionContext;\n if (!isObjectLike(ctx.result)) {\n return;\n }\n // Patch the model's `doGenerate`/`doStream` once. The model call recovers its parent from the\n // active async context at call time (the operation span `bindTracingChannelToSpan` bound), which\n // propagates into the model call for `streamText` too, so there is nothing to capture on the model here.\n patchModelMethods(ctx.result as PatchableModel, options);\n },\n start() {\n /* no-op */\n },\n asyncStart() {\n /* no-op */\n },\n asyncEnd() {\n /* no-op */\n },\n error() {\n /* no-op */\n },\n });\n}\n\n/**\n * Pick the invoke_agent span a model call should hang under: the operation span that\n * `bindTracingChannelToSpan` planted as the active async context for the enclosing operation.\n *\n * Because we suppress `ai`'s native telemetry (so it never installs its own span as active), the active\n * span inside `doGenerate`/`doStream` is our operation span. The `operationSpans` gate makes this return\n * `undefined` when the active span isn't one of ours — e.g. telemetry was disabled for the call so we\n * opened no operation span and the active span is the user's enclosing span — so the model call is\n * skipped rather than mis-parented.\n *\n * This covers `generateText`/`embed` (whose model call is awaited inside the operation body) and\n * `streamText` alike — `ai` initiates the stream synchronously within the operation's bound context, so\n * the later `doStream` continuation restores the same active span even though the operation's span has\n * already ended. The per-operation binding also disambiguates concurrent calls that share one model\n * instance (a single mutable slot on the shared model could not — it would hold whichever operation\n * resolved the model last).\n */\nfunction resolveModelCallParent(): Span | undefined {\n const active = getActiveSpan();\n return active && operationSpans.has(active) ? active : undefined;\n}\n\n/**\n * Idempotently patch a resolved model's `doGenerate`/`doStream` so each invocation emits a\n * `languageModelCall` span. Shared by the v5/v6 `resolveLanguageModel` path and the v4 path (which\n * patches the passed model at the operation start, as v4 has no `resolveLanguageModel`).\n */\nfunction patchModelMethods(model: PatchableModel, options: VercelAiChannelOptions): void {\n if (model[PATCHED]) {\n return;\n }\n model[PATCHED] = true;\n patchModelMethod(model, 'doGenerate', options);\n patchModelMethod(model, 'doStream', options);\n}\n\nfunction patchModelMethod(\n model: PatchableModel,\n method: 'doGenerate' | 'doStream',\n options: VercelAiChannelOptions,\n): void {\n const original = model[method];\n if (typeof original !== 'function') {\n return;\n }\n model[method] = function (this: unknown, ...args: unknown[]): Promise<unknown> {\n const parent = resolveModelCallParent();\n // No enclosing operation span (e.g. telemetry disabled for the call) → don't open a model-call span.\n if (!parent) {\n return Promise.resolve(original.apply(this, args));\n }\n\n const callArgs = isObjectLike(args[0]) ? args[0] : {};\n // Carry the operation's `callId` so the shared core can name the span after it\n // (`ai.generateText.doGenerate` / `ai.streamText.doStream`).\n const callId = callIdBySpan.get(parent);\n const message: VercelAiChannelMessage = {\n type: 'languageModelCall',\n event: {\n callId,\n provider: model.provider,\n modelId: model.modelId,\n // v4 nests the tool list under `mode.tools` (the `LanguageModelV1` call shape); v5+ passes a\n // top-level `tools` array. Reading both keeps `available_tools` populated on the model-call span.\n tools: callArgs.tools ?? (isObjectLike(callArgs.mode) ? callArgs.mode.tools : undefined),\n messages: callArgs.prompt,\n // Inherit the enclosing operation's per-call recording flags so inputs/tools/outputs are recorded on\n // the model-call span whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `languageModelCall` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return Promise.resolve(original.apply(this, args));\n }\n\n // `streamText` ends its operation span synchronously, so its `callId` entry was deliberately left in\n // place for this later model call; drop it now that we've used it.\n const clearStreamCallId = (): void => {\n if (method === 'doStream' && callId) {\n clearOperationCallId(callId);\n }\n };\n\n // Both the synchronous throw and the async rejection of the model call must end the span with an\n // error status (an `async` `doGenerate`/`doStream` that throws rejects rather than throwing here).\n const failSpan = (error: unknown): never => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error instanceof Error ? error.message : 'unknown_error' });\n span.end();\n clearStreamCallId();\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, args));\n return result.then(value => {\n // A streamed model call resolves to `{ stream, ... }` before the stream is consumed, so its\n // usage/finish/output only arrive as the stream drains. Tap it (same helper as the v7 path) and\n // defer ending this model-call span until then. The parent `invoke_agent` span is enriched\n // separately by `deferStreamTextOperationEnd`, which awaits the operation's own result promises.\n if (method === 'doStream' && isObjectLike(value) && isReadableStream(value.stream)) {\n value.stream = tapModelCallStream(\n value.stream,\n final => {\n message.result = { ...value, ...streamedResultToChannelResult(final) };\n enrichSpanOnEnd(span, message, options);\n span.end();\n clearStreamCallId();\n },\n error => {\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: error instanceof Error ? error.message : 'unknown_error',\n });\n span.end();\n clearStreamCallId();\n },\n );\n\n return value;\n }\n // `doGenerate` (and any non-stream result) settles with the full result; end here, start/end\n // bracket the call to match the channel timing.\n message.result = value;\n enrichSpanOnEnd(span, message, options);\n span.end();\n clearStreamCallId();\n\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\n/**\n * Patch every executable tool on an operation's `tools` (a record keyed by tool name) so each\n * invocation emits a `gen_ai.execute_tool` span. v5 routes tool execution through the batch\n * `executeTools`, which binds `tool.execute` at call time — so replacing the `execute` property here\n * (before the call runs) is picked up. Tools without an `execute` (client-side tools) are skipped,\n * matching `executeTools`.\n */\nfunction patchOperationTools(tools: Record<string, unknown>, options: VercelAiChannelOptions): void {\n // This runs inside the channel `start` transform (no upstream try/catch), so a throw here would break\n // the user's `ai` call. Instrumentation must never do that — degrade to no tool span instead.\n try {\n for (const [toolName, tool] of Object.entries(tools)) {\n if (isObjectLike(tool)) {\n patchToolExecute(toolName, tool as PatchableTool, tools, options);\n }\n }\n } catch {\n DEBUG_BUILD && debug.log('Vercel AI orchestrion tool patching failed.');\n }\n}\n\nfunction patchToolExecute(\n toolName: string,\n tool: PatchableTool,\n tools: Record<string, unknown>,\n options: VercelAiChannelOptions,\n): void {\n const original = tool.execute;\n if (typeof original !== 'function' || tool[TOOL_PATCHED]) {\n return;\n }\n tool[TOOL_PATCHED] = true;\n tool.execute = function (this: unknown, input: unknown, ...rest: unknown[]): unknown {\n // Skip if there's no enclosing operation span (telemetry disabled for the call), or if that parent\n // is itself a tool-call span — the latter means v6's `executeToolCall` already opened a span for\n // this call and is running `execute` inside it, so spanning again here would double-count. On v5\n // the parent is the enclosing `invoke_agent` operation span, so we proceed.\n const parent = resolveModelCallParent();\n if (!parent || toolCallSpans.has(parent)) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5 passes `{ toolCallId, messages, abortSignal, ... }` as the second argument to `execute`.\n const callOptions = isObjectLike(rest[0]) ? rest[0] : {};\n const message: VercelAiChannelMessage = {\n type: 'executeTool',\n event: {\n callId: callIdBySpan.get(parent),\n toolCall: { toolName, toolCallId: asString(callOptions.toolCallId), input },\n // The `tools` record (keyed by name) lets the shared core backfill the tool's `description`.\n tools,\n // Inherit the enclosing operation's per-call recording flags so tool inputs/outputs are recorded\n // whenever they are on the parent `invoke_agent` span.\n ...recordingBySpan.get(parent),\n },\n };\n const span = withActiveSpan(parent, () => createSpanFromMessage(message, options));\n // `executeTool` always opens a span; the guard just keeps the wrapper safe if that changes.\n if (!span) {\n return original.apply(this, [input, ...rest]);\n }\n\n // v5's `executeTools` catches a thrown tool error and turns it into `tool-error` content rather\n // than rejecting, so the user never sees a rejection — we must capture it here. Rethrow so\n // `executeTools` still produces its `tool-error` result and the operation continues normally.\n const failSpan = (error: unknown): never => {\n captureToolError(span, message, error);\n span.end();\n throw error;\n };\n\n try {\n const result = Promise.resolve(original.apply(this, [input, ...rest]));\n return result.then(value => {\n // The shared core (matching v6/v7) expects the tool result nested under `output`.\n message.result = { output: value };\n enrichSpanOnEnd(span, message, options);\n span.end();\n return value;\n }, failSpan);\n } catch (error) {\n return failSpan(error);\n }\n };\n}\n\nfunction buildTextMessage(type: 'generateText' | 'streamText' | 'generateObject'): MessageBuilder {\n return (options, telemetry) => ({\n type,\n event: {\n callId: nextCallId(),\n operationId: `ai.${type}`,\n functionId: asString(telemetry.functionId),\n ...modelFields(options.model),\n maxRetries: options.maxRetries,\n // The `ai` SDK takes the system prompt as a top-level `system` option (all of v4/v5/v6); the\n // shared core lifts `event.instructions` into the system-instructions attribute, matching v7's\n // native channel (which carries it as a distinct field rather than inside the messages array).\n instructions: asString(options.system),\n // Normalize to the message-array shape the shared core (and v7's channel) expects: a bare string\n // `prompt` becomes a single user message, matching the SDK's own normalization.\n messages: normalizePromptMessages(options),\n ...recording(telemetry),\n },\n });\n}\n\nfunction normalizePromptMessages(options: Record<string, unknown>): unknown {\n if (Array.isArray(options.messages)) {\n return options.messages;\n }\n if (typeof options.prompt === 'string') {\n return [{ role: 'user', content: options.prompt }];\n }\n return options.messages ?? options.prompt;\n}\n\nfunction recording(telemetry: Record<string, unknown>): { recordInputs: unknown; recordOutputs: unknown } {\n // Match the OTel integration's per-call default: an explicit `recordInputs`/`recordOutputs` wins, but a\n // call that merely enables telemetry (`isEnabled: true`, no explicit flags) defaults both to `true`.\n // Unlike v7's native `ai:telemetry` channel, the orchestrion channels expose `isEnabled`, so — as noted\n // in `resolveRecording` — we CAN reproduce that default here (the native-channel subscriber cannot).\n const enabledDefault = telemetry.isEnabled === true ? true : undefined;\n return {\n recordInputs: telemetry.recordInputs ?? enabledDefault,\n recordOutputs: telemetry.recordOutputs ?? enabledDefault,\n };\n}\n\nfunction modelFields(model: unknown): { provider?: string; modelId?: string } {\n return { provider: modelField(model, 'provider'), modelId: modelField(model, 'modelId') };\n}\n\nfunction modelField(model: unknown, field: 'modelId' | 'provider'): string | undefined {\n return isObjectLike(model) ? asString(model[field]) : undefined;\n}\n"],"names":["CHANNELS","DEBUG_BUILD","debug","tracingChannel","isObjectLike","createSpanFromMessage","asString","bindTracingChannelToSpan","enrichSpanOnEnd","clearOperationId","getActiveSpan","withActiveSpan","clearOperationCallId","SPAN_STATUS_ERROR","isReadableStream","tapModelCallStream","streamedResultToChannelResult","captureToolError"],"mappings":";;;;;;;;;AAqEA,MAAM,OAAA,0BAAiB,4BAA4B,CAAA;AACnD,MAAM,YAAA,0BAAsB,2BAA2B,CAAA;AASvD,IAAI,aAAA,GAAgB,CAAA;AACpB,SAAS,UAAA,GAAqB;AAC5B,EAAA,OAAO,CAAA,GAAA,EAAM,EAAE,aAAa,CAAA,CAAA;AAC9B;AAIA,MAAM,QAAA,uBAAe,OAAA,EAAwC;AAI7D,MAAM,cAAA,uBAAqB,OAAA,EAAc;AAIzC,MAAM,aAAA,uBAAoB,OAAA,EAAc;AACxC,MAAM,YAAA,uBAAmB,OAAA,EAAsB;AAM/C,MAAM,eAAA,uBAAsB,OAAA,EAA4C;AAMxE,MAAM,mBAAA,uBAA0B,OAAA,EAAgB;AAEhD,IAAI,UAAA,GAAa,KAAA;AAWV,SAAS,oCAAA,CACd,cAAA,EACA,OAAA,GAAkC,EAAC,EAC7B;AACN,EAAA,IAAI,UAAA,EAAY;AACd,IAAA;AAAA,EACF;AACA,EAAA,UAAA,GAAa,IAAA;AAEb,EAAA,IAAI;AACF,IAAA,aAAA,CAAc,gBAAgBA,iBAAA,CAAS,uBAAA,EAAyB,gBAAA,CAAiB,cAAc,GAAG,OAAO,CAAA;AACzG,IAAA,aAAA,CAAc,gBAAgBA,iBAAA,CAAS,qBAAA,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A,CAAQ,MAAA,KAAW,QAAA,EAAU;AACtC,IAAA,OAAO,CAAC,EAAE,IAAA,EAAM,QAAQ,OAAA,EAAS,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,OAAA,CAAQ,YAAY,OAAA,CAAQ,MAAA;AACrC;AAEA,SAAS,UAAU,SAAA,EAAuF;AAKxG,EAAA,MAAM,cAAA,GAAiB,SAAA,CAAU,SAAA,KAAc,IAAA,GAAO,IAAA,GAAO,MAAA;AAC7D,EAAA,OAAO;AAAA,IACL,YAAA,EAAc,UAAU,YAAA,IAAgB,cAAA;AAAA,IACxC,aAAA,EAAe,UAAU,aAAA,IAAiB;AAAA,GAC5C;AACF;AAEA,SAAS,YAAY,KAAA,EAAyD;AAC5E,EAAA,OAAO,EAAE,QAAA,EAAU,UAAA,CAAW,KAAA,EAAO,UAAU,GAAG,OAAA,EAAS,UAAA,CAAW,KAAA,EAAO,SAAS,CAAA,EAAE;AAC1F;AAEA,SAAS,UAAA,CAAW,OAAgB,KAAA,EAAmD;AACrF,EAAA,OAAOF,kBAAa,KAAK,CAAA,GAAIE,cAAS,KAAA,CAAM,KAAK,CAAC,CAAA,GAAI,MAAA;AACxD;;;;"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { GRAPHQL_DOCUMENT, GRAPHQL_OPERATION_NAME, GRAPHQL_OPERATION_TYPE } from '@sentry/conventions/attributes';
|
|
2
|
+
import { WEB_SERVER_GRAPHQL_SPAN_OP } from '@sentry/conventions/op';
|
|
3
|
+
import { startInactiveSpan, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR } from '@sentry/core';
|
|
4
|
+
import { bindTracingChannelToSpan } from '../tracing-channel.js';
|
|
5
|
+
import { collectGraphqlDocument, hasResultErrors, getOperationSpanName, renameRootSpanWithOperation } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const GRAPHQL_DC_CHANNEL_PARSE = "graphql:parse";
|
|
8
|
+
const GRAPHQL_DC_CHANNEL_VALIDATE = "graphql:validate";
|
|
9
|
+
const GRAPHQL_DC_CHANNEL_EXECUTE = "graphql:execute";
|
|
10
|
+
const GRAPHQL_DC_CHANNEL_SUBSCRIBE = "graphql:subscribe";
|
|
11
|
+
const GRAPHQL_DC_CHANNEL_RESOLVE = "graphql:resolve";
|
|
12
|
+
const ORIGIN = "auto.graphql.diagnostic_channel";
|
|
13
|
+
const SPAN_NAME_PARSE = "graphql.parse";
|
|
14
|
+
const SPAN_NAME_VALIDATE = "graphql.validate";
|
|
15
|
+
const SPAN_NAME_EXECUTE = "graphql.execute";
|
|
16
|
+
const SPAN_NAME_SUBSCRIBE = "graphql.subscribe";
|
|
17
|
+
const SPAN_NAME_RESOLVE = "graphql.resolve";
|
|
18
|
+
const GRAPHQL_FIELD_NAME = "graphql.field.name";
|
|
19
|
+
const GRAPHQL_FIELD_PATH = "graphql.field.path";
|
|
20
|
+
const GRAPHQL_FIELD_TYPE = "graphql.field.type";
|
|
21
|
+
const GRAPHQL_PARENT_NAME = "graphql.parent.name";
|
|
22
|
+
function subscribeGraphqlDiagnosticChannels(tracingChannel, options = {}) {
|
|
23
|
+
const ignoreResolveSpans = options.ignoreResolveSpans !== false;
|
|
24
|
+
const ignoreTrivialResolveSpans = options.ignoreTrivialResolveSpans !== false;
|
|
25
|
+
const useOperationNameForRootSpan = options.useOperationNameForRootSpan !== false;
|
|
26
|
+
setupParseChannel(tracingChannel);
|
|
27
|
+
setupValidateChannel(tracingChannel);
|
|
28
|
+
setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_EXECUTE, SPAN_NAME_EXECUTE, useOperationNameForRootSpan);
|
|
29
|
+
setupOperationChannel(tracingChannel, GRAPHQL_DC_CHANNEL_SUBSCRIBE, SPAN_NAME_SUBSCRIBE, useOperationNameForRootSpan);
|
|
30
|
+
if (!ignoreResolveSpans) {
|
|
31
|
+
setupResolveChannel(tracingChannel, ignoreTrivialResolveSpans);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function setupParseChannel(tracingChannel) {
|
|
35
|
+
bindTracingChannelToSpan(
|
|
36
|
+
tracingChannel(GRAPHQL_DC_CHANNEL_PARSE),
|
|
37
|
+
() => startInactiveSpan({
|
|
38
|
+
name: SPAN_NAME_PARSE,
|
|
39
|
+
attributes: {
|
|
40
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
41
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function setupValidateChannel(tracingChannel) {
|
|
47
|
+
bindTracingChannelToSpan(
|
|
48
|
+
tracingChannel(GRAPHQL_DC_CHANNEL_VALIDATE),
|
|
49
|
+
(data) => {
|
|
50
|
+
return startInactiveSpan({
|
|
51
|
+
name: SPAN_NAME_VALIDATE,
|
|
52
|
+
attributes: {
|
|
53
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
54
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,
|
|
55
|
+
[GRAPHQL_DOCUMENT]: collectGraphqlDocument(data.document)
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
beforeSpanEnd: (span, data) => {
|
|
61
|
+
if (Array.isArray(data.result) && data.result.length > 0) {
|
|
62
|
+
span.setStatus({ code: SPAN_STATUS_ERROR, message: "invalid_argument" });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function setupOperationChannel(tracingChannel, channelName, fallbackName, useOperationNameForRootSpan) {
|
|
69
|
+
bindTracingChannelToSpan(
|
|
70
|
+
tracingChannel(channelName),
|
|
71
|
+
(data) => {
|
|
72
|
+
const span = startInactiveSpan({
|
|
73
|
+
name: getOperationSpanName(data.operationType, data.operationName, fallbackName),
|
|
74
|
+
attributes: {
|
|
75
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
76
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,
|
|
77
|
+
[GRAPHQL_OPERATION_TYPE]: data.operationType,
|
|
78
|
+
[GRAPHQL_OPERATION_NAME]: data.operationName || void 0,
|
|
79
|
+
[GRAPHQL_DOCUMENT]: collectGraphqlDocument(data.document)
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (useOperationNameForRootSpan && data.operationType) {
|
|
83
|
+
renameRootSpanWithOperation(span, data.operationType, data.operationName);
|
|
84
|
+
}
|
|
85
|
+
return span;
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
beforeSpanEnd: (span, data) => {
|
|
89
|
+
if (hasResultErrors(data.result)) {
|
|
90
|
+
span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
function setupResolveChannel(tracingChannel, ignoreTrivialResolveSpans) {
|
|
97
|
+
bindTracingChannelToSpan(tracingChannel(GRAPHQL_DC_CHANNEL_RESOLVE), (data) => {
|
|
98
|
+
if (ignoreTrivialResolveSpans && data.isDefaultResolver) {
|
|
99
|
+
return void 0;
|
|
100
|
+
}
|
|
101
|
+
return startInactiveSpan({
|
|
102
|
+
name: `${SPAN_NAME_RESOLVE} ${data.fieldPath}`,
|
|
103
|
+
attributes: {
|
|
104
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
105
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: WEB_SERVER_GRAPHQL_SPAN_OP,
|
|
106
|
+
[GRAPHQL_FIELD_NAME]: data.fieldName,
|
|
107
|
+
[GRAPHQL_FIELD_PATH]: data.fieldPath,
|
|
108
|
+
[GRAPHQL_FIELD_TYPE]: data.fieldType,
|
|
109
|
+
[GRAPHQL_PARENT_NAME]: data.parentType
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { GRAPHQL_DC_CHANNEL_EXECUTE, GRAPHQL_DC_CHANNEL_PARSE, GRAPHQL_DC_CHANNEL_RESOLVE, GRAPHQL_DC_CHANNEL_SUBSCRIBE, GRAPHQL_DC_CHANNEL_VALIDATE, subscribeGraphqlDiagnosticChannels };
|
|
116
|
+
//# sourceMappingURL=graphql-dc-subscriber.js.map
|
|
@@ -0,0 +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 { 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":[],"mappings":";;;;;;AAgBO,MAAM,wBAAA,GAA2B;AACjC,MAAM,2BAAA,GAA8B;AACpC,MAAM,0BAAA,GAA6B;AACnC,MA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
+
import { defineIntegration, waitForTracingChannelBinding } from '@sentry/core';
|
|
2
|
+
import * as diagnosticsChannel from 'node:diagnostics_channel';
|
|
3
|
+
import { subscribeGraphqlDiagnosticChannels } from './graphql-dc-subscriber.js';
|
|
4
|
+
|
|
5
|
+
const _graphqlIntegration = ((options = {}) => {
|
|
6
|
+
return {
|
|
7
|
+
name: "Graphql",
|
|
8
|
+
setupOnce() {
|
|
9
|
+
if (!diagnosticsChannel.tracingChannel) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
waitForTracingChannelBinding(() => {
|
|
13
|
+
subscribeGraphqlDiagnosticChannels(diagnosticsChannel.tracingChannel, options);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
const graphqlIntegration = defineIntegration(_graphqlIntegration);
|
|
19
|
+
|
|
20
|
+
export { graphqlIntegration };
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/graphql/index.ts"],"sourcesContent":["import { defineIntegration, type IntegrationFn, waitForTracingChannelBinding } from '@sentry/core';\nimport * as dc from 'node:diagnostics_channel';\nimport { type GraphqlDiagnosticChannelsOptions, subscribeGraphqlDiagnosticChannels } from './graphql-dc-subscriber';\n\nconst _graphqlIntegration = ((options: GraphqlDiagnosticChannelsOptions = {}) => {\n return {\n name: 'Graphql' as const,\n setupOnce() {\n // Bail on Node <= 18.18.0, where `tracingChannel` does not exist.\n if (!dc.tracingChannel) {\n return;\n }\n\n // Subscribe to graphql's native tracing channels (graphql >= 17).\n // This is a no-op on versions that don't publish to the channels, so it is always safe to call.\n waitForTracingChannelBinding(() => {\n subscribeGraphqlDiagnosticChannels(dc.tracingChannel, options);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Auto-instrument the [graphql](https://www.npmjs.com/package/graphql) library via its native\n * `node:diagnostics_channel` tracing channels (graphql >= 17).\n *\n * On older graphql versions the channels are never published to, so this integration is inert and\n * the vendored OTel instrumentation (gated to `< 17`) handles instrumentation instead.\n */\nexport const graphqlIntegration = defineIntegration(_graphqlIntegration);\n"],"names":["dc"],"mappings":";;;;AAIA,MAAM,mBAAA,IAAuB,CAAC,OAAA,GAA4C,EAAC,KAAM;AAC/E,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAA,IAAI,CAACA,mBAAG,cAAA,EAAgB;AACtB,QAAA;AAAA,MACF;AAIA,MAAA,4BAAA,CAA6B,MAAM;AACjC,QAAA,kCAAA,CAAmCA,kBAAA,CAAG,gBAAgB,OAAO,CAAA;AAAA,MAC/D,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AASO,MAAM,kBAAA,GAAqB,kBAAkB,mBAAmB;;;;"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SENTRY_GRAPHQL_OPERATION } from '@sentry/conventions/attributes';
|
|
2
|
+
import { getClient, isObjectLike, getRootSpan, spanToJSON } from '@sentry/core';
|
|
3
|
+
|
|
4
|
+
const ORIGINAL_DESCRIPTION_ATTRIBUTE = "original-description";
|
|
5
|
+
const REDACTED_LITERAL_KINDS = /* @__PURE__ */ new Set(["Int", "Float", "String", "BlockString"]);
|
|
6
|
+
function renameRootSpanWithOperation(span, operationType, operationName) {
|
|
7
|
+
const rootSpan = getRootSpan(span);
|
|
8
|
+
if (rootSpan === span) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const rootSpanJson = spanToJSON(rootSpan);
|
|
12
|
+
const newOperation = operationName ? `${operationType} ${operationName}` : operationType;
|
|
13
|
+
const existingOperations = rootSpanJson.data[SENTRY_GRAPHQL_OPERATION];
|
|
14
|
+
let operations;
|
|
15
|
+
if (Array.isArray(existingOperations)) {
|
|
16
|
+
operations = [...existingOperations, newOperation];
|
|
17
|
+
} else if (typeof existingOperations === "string") {
|
|
18
|
+
operations = [existingOperations, newOperation];
|
|
19
|
+
} else {
|
|
20
|
+
operations = newOperation;
|
|
21
|
+
}
|
|
22
|
+
rootSpan.setAttribute(SENTRY_GRAPHQL_OPERATION, operations);
|
|
23
|
+
const originalDescription = rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE] ?? rootSpanJson.description;
|
|
24
|
+
if (!rootSpanJson.data[ORIGINAL_DESCRIPTION_ATTRIBUTE]) {
|
|
25
|
+
rootSpan.setAttribute(ORIGINAL_DESCRIPTION_ATTRIBUTE, originalDescription);
|
|
26
|
+
}
|
|
27
|
+
rootSpan.updateName(`${originalDescription} (${getGraphqlOperationNamesFromAttribute(operations)})`);
|
|
28
|
+
}
|
|
29
|
+
function getGraphqlOperationNamesFromAttribute(attr) {
|
|
30
|
+
if (Array.isArray(attr)) {
|
|
31
|
+
const sorted = attr.slice().sort();
|
|
32
|
+
if (sorted.length <= 5) {
|
|
33
|
+
return sorted.join(", ");
|
|
34
|
+
}
|
|
35
|
+
return `${sorted.slice(0, 5).join(", ")}, +${sorted.length - 5}`;
|
|
36
|
+
}
|
|
37
|
+
return attr;
|
|
38
|
+
}
|
|
39
|
+
function getOperationSpanName(operationType, operationName, fallbackName) {
|
|
40
|
+
if (operationType && operationName) {
|
|
41
|
+
return `${operationType} ${operationName}`;
|
|
42
|
+
}
|
|
43
|
+
if (operationType) {
|
|
44
|
+
return operationType;
|
|
45
|
+
}
|
|
46
|
+
return fallbackName;
|
|
47
|
+
}
|
|
48
|
+
function hasResultErrors(result) {
|
|
49
|
+
if (isObjectLike(result) && "errors" in result) {
|
|
50
|
+
const errors = result.errors;
|
|
51
|
+
return Array.isArray(errors) && errors.length > 0;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function redactGraphqlDocument(document) {
|
|
56
|
+
const loc = document?.loc;
|
|
57
|
+
const body = loc?.source?.body;
|
|
58
|
+
if (typeof body !== "string" || !loc?.startToken) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const ranges = [];
|
|
63
|
+
for (let token = loc.startToken; token; token = token.next) {
|
|
64
|
+
if (REDACTED_LITERAL_KINDS.has(token.kind)) {
|
|
65
|
+
ranges.push({ start: token.start, end: token.end, kind: token.kind });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let out = body;
|
|
69
|
+
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
70
|
+
const { start, end, kind } = ranges[i];
|
|
71
|
+
const replacement = kind === "String" || kind === "BlockString" ? '"*"' : "*";
|
|
72
|
+
out = out.slice(0, start) + replacement + out.slice(end);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
} catch {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function collectGraphqlDocument(document) {
|
|
80
|
+
if (getClient()?.getDataCollectionOptions().graphQL.document !== true) {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
return redactGraphqlDocument(document);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { collectGraphqlDocument, getOperationSpanName, hasResultErrors, renameRootSpanWithOperation };
|
|
87
|
+
//# sourceMappingURL=utils.js.map
|