@sentry/server-utils 11.21.0 → 11.23.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/THIRD-PARTY-LICENSES.txt +10 -10
- package/build/cjs/chunks/config.js +4 -2
- package/build/cjs/chunks/config.js.map +1 -1
- package/build/cjs/chunks/core.js +0 -1
- package/build/cjs/chunks/exports.js +76 -28
- package/build/cjs/chunks/exports.js.map +1 -1
- package/build/cjs/chunks/module-details-from-path.js +427 -428
- package/build/cjs/chunks/module-details-from-path.js.map +1 -1
- package/build/cjs/chunks/moduleInjectedTransform.js +419 -421
- package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
- package/build/cjs/chunks/rolldown-runtime.js +8 -6
- package/build/cjs/index.js +95 -41
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/index.request-handler.js +2 -2
- package/build/cjs/orchestrion/bundler/bun.js +1 -1
- package/build/cjs/orchestrion/bundler/esbuild.js +1 -1
- package/build/cjs/orchestrion/bundler/rollup.js +1 -1
- package/build/cjs/orchestrion/bundler/vite.js +2 -2
- package/build/cjs/orchestrion/bundler/webpack-loader.js +2 -2
- package/build/cjs/orchestrion/bundler/webpack.js +4 -4
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/defineProperty.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/assertClassBrand.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/checkPrivateRedeclaration.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldGet2.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldInitSpec.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldSet2.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateMethodInitSpec.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/defineProperty.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPrimitive.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPropertyKey.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/typeof.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPrimitive.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPropertyKey.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/typeof.js +1 -1
- package/build/esm/_virtual/_rolldown/runtime.js +8 -6
- package/build/esm/ai/anthropic-ai/index.js +2 -2
- package/build/esm/ai/anthropic-ai/streaming.js +11 -2
- package/build/esm/ai/anthropic-ai/streaming.js.map +1 -1
- package/build/esm/ai/anthropic-ai/tool-runner.js +3 -3
- package/build/esm/ai/anthropic-ai/utils.js +2 -2
- package/build/esm/ai/core/span-hooks.js +1 -1
- package/build/esm/ai/core/time-to-first-chunk.js +1 -1
- package/build/esm/ai/core/utils.js +2 -2
- package/build/esm/ai/flue/index.js +2 -2
- package/build/esm/ai/flue/utils.js +2 -2
- package/build/esm/ai/google-genai/decisions.js +1 -1
- package/build/esm/ai/google-genai/index.js +2 -2
- package/build/esm/ai/google-genai/streaming.js +9 -2
- package/build/esm/ai/google-genai/streaming.js.map +1 -1
- package/build/esm/ai/google-genai/utils.js +1 -1
- package/build/esm/ai/langchain/embeddings.js +3 -3
- package/build/esm/ai/langchain/index.js +15 -9
- package/build/esm/ai/langchain/index.js.map +1 -1
- package/build/esm/ai/langchain/typesafe-classifier.js +2 -2
- package/build/esm/ai/langchain/utils.js +3 -4
- package/build/esm/ai/langchain/utils.js.map +1 -1
- package/build/esm/ai/langgraph/agent-span.js +3 -3
- package/build/esm/ai/langgraph/index.js +1 -1
- package/build/esm/ai/langgraph/stream.js +2 -2
- package/build/esm/ai/langgraph/utils.js +3 -3
- package/build/esm/ai/mastra/index.js +2 -2
- package/build/esm/ai/mastra/span-registry.js +1 -1
- package/build/esm/ai/mastra/utils.js +2 -2
- package/build/esm/ai/mistral/index.js +2 -2
- package/build/esm/ai/mistral/streaming.js +18 -9
- package/build/esm/ai/mistral/streaming.js.map +1 -1
- package/build/esm/ai/openai/index.js +2 -2
- package/build/esm/ai/openai/mapping.js +1 -1
- package/build/esm/ai/openai/streaming.js +15 -2
- package/build/esm/ai/openai/streaming.js.map +1 -1
- package/build/esm/ai/openai/utils.js +2 -2
- package/build/esm/ai/pi-ai/chat.js +12 -4
- package/build/esm/ai/pi-ai/chat.js.map +1 -1
- package/build/esm/ai/pi-ai/providers.js +1 -1
- package/build/esm/ai/pi-ai/recording.js +1 -1
- package/build/esm/ai/pi-durable/index.js +2 -2
- package/build/esm/ai/pi-durable/runs.js +3 -3
- package/build/esm/ai/pi-durable/tools.js +3 -3
- package/build/esm/ai/tanstack-ai/index.js +2 -2
- package/build/esm/ai/tanstack-ai/utils.js +2 -2
- package/build/esm/ai/typesafe/index.js +3 -3
- package/build/esm/ai/workers-ai/index.js +2 -2
- package/build/esm/ai/workers-ai/streaming.js +7 -5
- package/build/esm/ai/workers-ai/streaming.js.map +1 -1
- package/build/esm/ai/workers-ai/utils.js +7 -4
- package/build/esm/ai/workers-ai/utils.js.map +1 -1
- package/build/esm/async-context.js +1 -1
- package/build/esm/cron/common.js +1 -1
- package/build/esm/cron/cron.js +1 -1
- package/build/esm/cron/node-cron.js +1 -1
- package/build/esm/cron/node-schedule.js +1 -1
- package/build/esm/eve.js +1 -1
- package/build/esm/integrations/amqplib.js +3 -3
- package/build/esm/integrations/anthropic.js +3 -4
- package/build/esm/integrations/anthropic.js.map +1 -1
- package/build/esm/integrations/aws-sdk/index.js +3 -3
- package/build/esm/integrations/aws-sdk/services/MessageAttributes.js +1 -1
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime-content.js +2 -2
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js +3 -3
- package/build/esm/integrations/aws-sdk/services/dynamodb.js +1 -1
- package/build/esm/integrations/aws-sdk/services/lambda.js +2 -2
- package/build/esm/integrations/aws-sdk/services/sns.js +3 -3
- package/build/esm/integrations/aws-sdk/services/sqs.js +2 -2
- package/build/esm/integrations/bullmq/meter.js +2 -2
- package/build/esm/integrations/bullmq/tracer.js +2 -2
- package/build/esm/integrations/clickhouse.js +3 -3
- package/build/esm/integrations/cron.js +1 -1
- package/build/esm/integrations/dataloader.js +3 -3
- package/build/esm/integrations/express/error-handler.js +1 -1
- package/build/esm/integrations/express/index.js +1 -1
- package/build/esm/integrations/express/instrumentation.js +3 -3
- package/build/esm/integrations/fastify/errors.js +1 -1
- package/build/esm/integrations/fastify/index.js +1 -1
- package/build/esm/integrations/fastify/instrumentation.js +8 -4
- package/build/esm/integrations/fastify/instrumentation.js.map +1 -1
- package/build/esm/integrations/firebase/firestore.js +2 -2
- package/build/esm/integrations/firebase/functions.js +1 -1
- package/build/esm/integrations/firebase/index.js +1 -1
- package/build/esm/integrations/flue.js +1 -1
- package/build/esm/integrations/generic-pool.js +3 -3
- package/build/esm/integrations/google-genai.js +2 -2
- package/build/esm/integrations/graphql/graphql-dc-subscriber.js +3 -3
- package/build/esm/integrations/graphql/index.js +1 -1
- package/build/esm/integrations/graphql/resolvers.js +2 -2
- package/build/esm/integrations/graphql/spans.js +3 -3
- package/build/esm/integrations/groq.js +1 -1
- package/build/esm/integrations/hapi/hapi-error-handler.js +1 -1
- package/build/esm/integrations/hapi/hapi-utils.js +4 -5
- package/build/esm/integrations/hapi/hapi-utils.js.map +1 -1
- package/build/esm/integrations/hapi/index.js +1 -1
- package/build/esm/integrations/hono/applyPatches.js +1 -1
- package/build/esm/integrations/hono/createHonoMiddleware.js +1 -1
- package/build/esm/integrations/hono/honoIntegration.js +3 -3
- package/build/esm/integrations/hono/matchResult.js +1 -1
- package/build/esm/integrations/hono/middlewareHandlers.js +2 -2
- package/build/esm/integrations/hono/patchAppRequest.js +3 -3
- package/build/esm/integrations/hono/patchAppUse.js +1 -1
- package/build/esm/integrations/hono/patchRoute.js +1 -1
- package/build/esm/integrations/hono/wrapMiddlewareSpan.js +3 -3
- package/build/esm/integrations/kafkajs/consumer.js +2 -2
- package/build/esm/integrations/kafkajs/index.js +1 -1
- package/build/esm/integrations/kafkajs/spans.js +2 -2
- package/build/esm/integrations/knex.js +3 -3
- package/build/esm/integrations/koa/index.js +3 -3
- package/build/esm/integrations/langchain.js +1 -1
- package/build/esm/integrations/langgraph.js +1 -1
- package/build/esm/integrations/lru-memoizer.js +1 -1
- package/build/esm/integrations/mastra-classifier.js +2 -2
- package/build/esm/integrations/mastra.js +4 -4
- package/build/esm/integrations/mcp-server.js +2 -2
- package/build/esm/integrations/mistral.js +2 -2
- package/build/esm/integrations/mongodb/index.js +1 -1
- package/build/esm/integrations/mongodb/mongodb-span.js +1 -1
- package/build/esm/integrations/mongoose/index.js +1 -1
- package/build/esm/integrations/mongoose/mongoose-dc-subscriber.js +3 -3
- package/build/esm/integrations/mongoose/mongoose-legacy-span.js +1 -1
- package/build/esm/integrations/mysql.js +3 -3
- package/build/esm/integrations/mysql2/index.js +1 -1
- package/build/esm/integrations/mysql2/mysql2-dc-subscriber.js +3 -3
- package/build/esm/integrations/neon.js +13 -5
- package/build/esm/integrations/neon.js.map +1 -1
- package/build/esm/integrations/nitro/captureStorageEvents.js +3 -3
- package/build/esm/integrations/nitro/captureTracingEvents.js +3 -3
- package/build/esm/integrations/nitro/index.js +1 -1
- package/build/esm/integrations/nitro/setServerTimingHeaders.js +1 -1
- package/build/esm/integrations/node-cron.js +1 -1
- package/build/esm/integrations/node-schedule.js +1 -1
- package/build/esm/integrations/openai-compatible.js +2 -2
- package/build/esm/integrations/openai.js +2 -2
- package/build/esm/integrations/pg.js +43 -16
- package/build/esm/integrations/pg.js.map +1 -1
- package/build/esm/integrations/pi-ai.js +1 -1
- package/build/esm/integrations/pi-durable.js +1 -1
- package/build/esm/integrations/pino.js +1 -1
- package/build/esm/integrations/pino.js.map +1 -1
- package/build/esm/integrations/postgresjs/index.js +3 -3
- package/build/esm/integrations/postgresjs/postgresjs-dc-subscriber.js +3 -3
- package/build/esm/integrations/postgresjs-wrapper.js +1 -1
- package/build/esm/integrations/prisma/index.js +1 -1
- package/build/esm/integrations/prisma/orchestrion.js +8 -12
- package/build/esm/integrations/prisma/orchestrion.js.map +1 -1
- package/build/esm/integrations/prisma/tracing-helper.js +2 -2
- package/build/esm/integrations/redis/index.js +3 -3
- package/build/esm/integrations/redis/ioredis-channel-subscriber.js +3 -3
- package/build/esm/integrations/redis/redis-cache.js +1 -1
- package/build/esm/integrations/redis/redis-dc-subscriber.js +3 -3
- package/build/esm/integrations/serveTunnel.js +2 -2
- package/build/esm/integrations/tanstack-ai.js +1 -1
- package/build/esm/integrations/tedious.js +4 -4
- package/build/esm/integrations/together-ai.js +1 -1
- package/build/esm/integrations/typesafe.js +1 -1
- package/build/esm/integrations/vercel-ai/extract.js +2 -3
- package/build/esm/integrations/vercel-ai/extract.js.map +1 -1
- package/build/esm/integrations/vercel-ai/index.js +1 -1
- package/build/esm/integrations/vercel-ai/util.js +21 -2
- package/build/esm/integrations/vercel-ai/util.js.map +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +3 -3
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-tool-telemetry.js +3 -3
- package/build/esm/integrations/winston.js +1 -1
- package/build/esm/opentelemetry.js +1 -1
- package/build/esm/orchestrion/bundler/esbuild.js +1 -1
- package/build/esm/orchestrion/bundler/externalRequire.js +1 -1
- package/build/esm/orchestrion/bundler/rollup.js +1 -1
- package/build/esm/orchestrion/bundler/webpack-loader.js +1 -1
- package/build/esm/orchestrion/bundler/webpack.js +1 -1
- package/build/esm/orchestrion/config/index.js +1 -1
- package/build/esm/orchestrion/config/mistral.js +1 -1
- package/build/esm/orchestrion/config/mistral.js.map +1 -1
- package/build/esm/orchestrion/config/prisma.js +2 -0
- package/build/esm/orchestrion/config/prisma.js.map +1 -1
- package/build/esm/orchestrion/detect.js +1 -1
- package/build/esm/orchestrion/instrumentation.js +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tracing-channel.js +1 -2
- package/build/esm/tracing-channel.js.map +1 -1
- package/build/esm/utils/cronMonitoring.js +1 -1
- package/build/esm/utils/diagnosticsChannel.js +1 -1
- package/build/esm/utils/module.js +2 -2
- package/build/esm/utils/module.js.map +1 -1
- package/build/esm/utils/monitorStream.js +1 -1
- package/build/esm/utils/serverTimingTraceHeader.js +1 -1
- package/build/esm/utils/tunnelServer.js +1 -1
- package/build/esm/utils/wrapServerRequestHandler.js +4 -4
- package/build/esm/vendored/@apm-js-collab/code-transformer/lib/matcher.js +3 -3
- package/build/esm/vendored/@apm-js-collab/code-transformer/lib/transformer.js +5 -5
- package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/core-BiWIBBjf.js +1 -1
- package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/webpack-loader-factory.js +1 -1
- package/build/esm/vendored/esquery/dist/esquery.min.js +1 -0
- package/build/esm/vendored/esquery/dist/esquery.min.js.map +1 -1
- package/build/esm/vendored/meriyah/dist/meriyah.js +416 -418
- package/build/esm/vendored/meriyah/dist/meriyah.js.map +1 -1
- package/build/esm/vendored/meriyah/dist/meriyah2.js +416 -418
- package/build/esm/vendored/meriyah/dist/meriyah2.js.map +1 -1
- package/build/esm/vendored/source-map/lib/base64-vlq.js +1 -1
- package/build/esm/vendored/source-map/lib/base64-vlq.js.map +1 -1
- package/build/types/ai/anthropic-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/types.d.ts +1 -0
- package/build/types/ai/anthropic-ai/types.d.ts.map +1 -1
- package/build/types/ai/google-genai/streaming.d.ts.map +1 -1
- package/build/types/ai/langchain/index.d.ts.map +1 -1
- package/build/types/ai/mistral/streaming.d.ts.map +1 -1
- package/build/types/ai/openai/streaming.d.ts.map +1 -1
- package/build/types/ai/pi-ai/chat.d.ts.map +1 -1
- package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/workers-ai/utils.d.ts.map +1 -1
- package/build/types/integrations/fastify/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/neon.d.ts.map +1 -1
- package/build/types/integrations/pg.d.ts +6 -1
- package/build/types/integrations/pg.d.ts.map +1 -1
- package/build/types/integrations/pino.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/extract.d.ts +2 -5
- package/build/types/integrations/vercel-ai/extract.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/util.d.ts.map +1 -1
- package/build/types/orchestrion/channels.d.ts +1 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/mistral.d.ts +3 -3
- package/build/types/orchestrion/config/prisma.d.ts +2 -1
- package/build/types/orchestrion/config/prisma.d.ts.map +1 -1
- package/build/types/tracing-channel.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.js","names":[],"sources":["../../../src/integrations/pino.ts"],"sourcesContent":["import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, LogSeverityLevel } from '@sentry/core';\nimport {\n captureLogEvent,\n addExceptionMechanism,\n captureException,\n captureMessage,\n defineIntegration,\n isObjectLike,\n severityLevelFromString,\n withScope,\n} from '@sentry/core';\nimport { tracingChannel } from '../utils/diagnosticsChannel';\n\nconst SENTRY_TRACK_SYMBOL = Symbol('sentry-track-pino-logger');\n\ntype LevelMapping = {\n // Fortunately pino uses the same levels as Sentry\n labels: { [level: number]: LogSeverityLevel };\n};\n\ntype Pino = {\n [key: symbol]: unknown;\n levels: LevelMapping;\n [SENTRY_TRACK_SYMBOL]?: 'track' | 'ignore';\n};\n\n/**\n * Gets a custom Pino key from a logger instance by searching for the symbol.\n * Pino uses non-global symbols like Symbol('pino.messageKey'): https://github.com/pinojs/pino/blob/8a816c0b1f72de5ae9181f3bb402109b66f7d812/lib/symbols.js\n */\nfunction getPinoKey(logger: Pino, symbolName: string, defaultKey: string): string {\n const symbols = Object.getOwnPropertySymbols(logger);\n const symbolString = `Symbol(${symbolName})`;\n for (const sym of symbols) {\n if (sym.toString() === symbolString) {\n const value = logger[sym];\n return typeof value === 'string' ? value : defaultKey;\n }\n }\n return defaultKey;\n}\n\ntype MergeObject = {\n [key: string]: unknown;\n err?: Error;\n};\n\ntype PinoHookArgs = [MergeObject, string, number];\n\ntype PinoOptions = {\n /**\n * Automatically instrument all Pino loggers.\n *\n * When set to `false`, only loggers marked with `pinoIntegration.trackLogger(logger)` will be captured.\n *\n * @default true\n */\n autoInstrument: boolean;\n /**\n * Options to enable capturing of error events.\n */\n error: {\n /**\n * Levels that trigger capturing of events.\n *\n * @default []\n */\n levels: LogSeverityLevel[];\n /**\n * By default, Sentry will mark captured errors as handled.\n * Set this to `false` if you want to mark them as unhandled instead.\n *\n * @default true\n */\n handled: boolean;\n };\n /**\n * Options to enable capturing of logs.\n */\n log: {\n /**\n * Levels that trigger capturing of logs.\n *\n * @default [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"]\n */\n levels: LogSeverityLevel[];\n };\n};\n\nconst DEFAULT_OPTIONS: PinoOptions = {\n autoInstrument: true,\n error: { levels: [], handled: true },\n log: { levels: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] },\n};\n\ntype DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? Partial<T[P]> : T[P];\n};\n\ntype PinoResult = {\n level?: string;\n time?: string;\n pid?: number;\n hostname?: string;\n} & Record<string, unknown>;\n\nfunction stripIgnoredFields(result: PinoResult): PinoResult {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { level, time, pid, hostname, ...rest } = result;\n return rest;\n}\n\nconst _pinoIntegration = defineIntegration((userOptions: DeepPartial<PinoOptions> = {}) => {\n const options: PinoOptions = {\n autoInstrument: userOptions.autoInstrument !== false,\n error: { ...DEFAULT_OPTIONS.error, ...userOptions.error },\n log: { ...DEFAULT_OPTIONS.log, ...userOptions.log },\n };\n\n function shouldTrackLogger(logger: Pino): boolean {\n const override = logger[SENTRY_TRACK_SYMBOL];\n return override === 'track' || (override !== 'ignore' && options.autoInstrument);\n }\n\n return {\n name: 'Pino',\n setup: () => {\n const integratedChannel = tracingChannel('pino_asJson');\n\n function onPinoStart(self: Pino, args: PinoHookArgs, result: PinoResult): void {\n if (!shouldTrackLogger(self)) {\n return;\n }\n\n const resultObj = stripIgnoredFields(result);\n\n const [captureObj, message, levelNumber] = args;\n const level = self?.levels?.labels?.[levelNumber] || 'info';\n const messageKey = getPinoKey(self, 'pino.messageKey', 'msg');\n const logMessage = message || (resultObj?.[messageKey] as string | undefined) || '';\n\n if (options.log.levels.includes(level)) {\n const attributes: Record<string, unknown> = {\n ...resultObj,\n [SENTRY_ORIGIN]: 'auto.log.pino',\n 'pino.logger.level': levelNumber,\n };\n\n captureLogEvent({ level, message: logMessage, attributes });\n }\n\n if (options.error.levels.includes(level)) {\n const errorKey = getPinoKey(self, 'pino.errorKey', 'err');\n\n // Attach the log message and remaining log fields (e.g. child logger\n // bindings, merge object fields) to the event. The serialized error is\n // excluded since it is captured as the event exception itself.\n const pinoContext: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(resultObj)) {\n if (key !== errorKey && key !== messageKey) {\n pinoContext[key] = value;\n }\n }\n if (logMessage) {\n pinoContext[messageKey] = logMessage;\n }\n\n const captureContext = {\n level: severityLevelFromString(level),\n contexts: { pino: pinoContext },\n };\n\n withScope(scope => {\n scope.addEventProcessor(event => {\n event.logger = 'pino';\n\n addExceptionMechanism(event, {\n handled: options.error.handled,\n type: 'auto.log.pino',\n });\n\n return event;\n });\n\n const error = captureObj[errorKey];\n if (error) {\n captureException(error, captureContext);\n return;\n }\n\n captureMessage(logMessage, captureContext);\n });\n }\n }\n\n integratedChannel.end.subscribe(data => {\n const {\n instance,\n arguments: args,\n result,\n } = data as { instance: Pino; arguments: PinoHookArgs; result: string };\n onPinoStart(instance, args, JSON.parse(result));\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Integration for Pino logging library.\n * Captures Pino logs as Sentry logs and optionally captures some log levels as events.\n *\n * By default, all Pino loggers will be captured. To ignore a specific logger, use `pinoIntegration.untrackLogger(logger)`.\n *\n * If you disable automatic instrumentation with `autoInstrument: false`, you can mark specific loggers to be tracked with `pinoIntegration.trackLogger(logger)`.\n *\n * Requires Pino >=v8.0.0\n */\nexport const pinoIntegration = Object.assign(_pinoIntegration, {\n trackLogger(logger: unknown): void {\n if (isObjectLike(logger) && 'levels' in logger) {\n (logger as Pino)[SENTRY_TRACK_SYMBOL] = 'track';\n }\n },\n untrackLogger(logger: unknown): void {\n if (isObjectLike(logger) && 'levels' in logger) {\n (logger as Pino)[SENTRY_TRACK_SYMBOL] = 'ignore';\n }\n },\n});\n"],"mappings":";;;;AAcA,MAAM,sBAAsB,OAAO,0BAA0B;;;;;AAiB7D,SAAS,WAAW,QAAc,YAAoB,YAA4B;CAChF,MAAM,UAAU,OAAO,sBAAsB,MAAM;CACnD,MAAM,eAAe,UAAU,WAAW;CAC1C,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,MAAM,cAAc;EACnC,MAAM,QAAQ,OAAO;EACr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AAW,MAAM,iBAAiB,KAAK;KAKxD,MAAM,cAAuC,CAAC;KAC9C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GACjD,IAAI,QAAQ,YAAY,QAAQ,YAC9B,YAAY,OAAO;KAGvB,IAAI,YACF,YAAY,cAAc;KAG5B,MAAM,iBAAiB;MACrB,OAAO,wBAAwB,KAAK;MACpC,UAAU,EAAE,MAAM,YAAY;KAChC;KAEA,WAAU,UAAS;MACjB,MAAM,mBAAkB,UAAS;OAC/B,MAAM,SAAS;OAEf,sBAAsB,OAAO;QAC3B,SAAS,QAAQ,MAAM;QACvB,MAAM;OACR,CAAC;OAED,OAAO;MACT,CAAC;MAED,MAAM,QAAQ,WAAW;MACzB,IAAI,OAAO;
|
|
1
|
+
{"version":3,"file":"pino.js","names":[],"sources":["../../../src/integrations/pino.ts"],"sourcesContent":["import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, LogSeverityLevel } from '@sentry/core';\nimport {\n captureLogEvent,\n addExceptionMechanism,\n captureException,\n captureMessage,\n defineIntegration,\n isObjectLike,\n severityLevelFromString,\n withScope,\n} from '@sentry/core';\nimport { tracingChannel } from '../utils/diagnosticsChannel';\n\nconst SENTRY_TRACK_SYMBOL = Symbol('sentry-track-pino-logger');\n\ntype LevelMapping = {\n // Fortunately pino uses the same levels as Sentry\n labels: { [level: number]: LogSeverityLevel };\n};\n\ntype Pino = {\n [key: symbol]: unknown;\n levels: LevelMapping;\n [SENTRY_TRACK_SYMBOL]?: 'track' | 'ignore';\n};\n\n/**\n * Gets a custom Pino key from a logger instance by searching for the symbol.\n * Pino uses non-global symbols like Symbol('pino.messageKey'): https://github.com/pinojs/pino/blob/8a816c0b1f72de5ae9181f3bb402109b66f7d812/lib/symbols.js\n */\nfunction getPinoKey(logger: Pino, symbolName: string, defaultKey: string): string {\n const symbols = Object.getOwnPropertySymbols(logger);\n const symbolString = `Symbol(${symbolName})`;\n for (const sym of symbols) {\n if (sym.toString() === symbolString) {\n const value = logger[sym];\n return typeof value === 'string' ? value : defaultKey;\n }\n }\n return defaultKey;\n}\n\ntype MergeObject = {\n [key: string]: unknown;\n err?: Error;\n};\n\ntype PinoHookArgs = [MergeObject, string, number];\n\ntype PinoOptions = {\n /**\n * Automatically instrument all Pino loggers.\n *\n * When set to `false`, only loggers marked with `pinoIntegration.trackLogger(logger)` will be captured.\n *\n * @default true\n */\n autoInstrument: boolean;\n /**\n * Options to enable capturing of error events.\n */\n error: {\n /**\n * Levels that trigger capturing of events.\n *\n * @default []\n */\n levels: LogSeverityLevel[];\n /**\n * By default, Sentry will mark captured errors as handled.\n * Set this to `false` if you want to mark them as unhandled instead.\n *\n * @default true\n */\n handled: boolean;\n };\n /**\n * Options to enable capturing of logs.\n */\n log: {\n /**\n * Levels that trigger capturing of logs.\n *\n * @default [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"]\n */\n levels: LogSeverityLevel[];\n };\n};\n\nconst DEFAULT_OPTIONS: PinoOptions = {\n autoInstrument: true,\n error: { levels: [], handled: true },\n log: { levels: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] },\n};\n\ntype DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? Partial<T[P]> : T[P];\n};\n\ntype PinoResult = {\n level?: string;\n time?: string;\n pid?: number;\n hostname?: string;\n} & Record<string, unknown>;\n\nfunction stripIgnoredFields(result: PinoResult): PinoResult {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { level, time, pid, hostname, ...rest } = result;\n return rest;\n}\n\nconst _pinoIntegration = defineIntegration((userOptions: DeepPartial<PinoOptions> = {}) => {\n const options: PinoOptions = {\n autoInstrument: userOptions.autoInstrument !== false,\n error: { ...DEFAULT_OPTIONS.error, ...userOptions.error },\n log: { ...DEFAULT_OPTIONS.log, ...userOptions.log },\n };\n\n function shouldTrackLogger(logger: Pino): boolean {\n const override = logger[SENTRY_TRACK_SYMBOL];\n return override === 'track' || (override !== 'ignore' && options.autoInstrument);\n }\n\n return {\n name: 'Pino',\n setup: () => {\n const integratedChannel = tracingChannel('pino_asJson');\n\n function onPinoStart(self: Pino, args: PinoHookArgs, result: PinoResult): void {\n if (!shouldTrackLogger(self)) {\n return;\n }\n\n const resultObj = stripIgnoredFields(result);\n\n const [captureObj, message, levelNumber] = args;\n const level = self?.levels?.labels?.[levelNumber] || 'info';\n const messageKey = getPinoKey(self, 'pino.messageKey', 'msg');\n const logMessage = message || (resultObj?.[messageKey] as string | undefined) || '';\n\n if (options.log.levels.includes(level)) {\n const attributes: Record<string, unknown> = {\n ...resultObj,\n [SENTRY_ORIGIN]: 'auto.log.pino',\n 'pino.logger.level': levelNumber,\n };\n\n captureLogEvent({ level, message: logMessage, attributes });\n }\n\n if (options.error.levels.includes(level)) {\n const errorKey = getPinoKey(self, 'pino.errorKey', 'err');\n\n // Attach the log message and remaining log fields (e.g. child logger\n // bindings, merge object fields) to the event. The serialized error is\n // excluded since it is captured as the event exception itself.\n const pinoContext: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(resultObj)) {\n if (key !== errorKey && key !== messageKey) {\n pinoContext[key] = value;\n }\n }\n if (logMessage) {\n pinoContext[messageKey] = logMessage;\n }\n\n const captureContext = {\n level: severityLevelFromString(level),\n contexts: { pino: pinoContext },\n };\n\n withScope(scope => {\n scope.addEventProcessor(event => {\n event.logger = 'pino';\n\n addExceptionMechanism(event, {\n handled: options.error.handled,\n type: 'auto.log.pino',\n });\n\n return event;\n });\n\n const error = captureObj[errorKey];\n if (error) {\n // oxlint-disable-next-line sdk/require-exception-mechanism -- mechanism is set by the event processor above\n captureException(error, captureContext);\n return;\n }\n\n captureMessage(logMessage, captureContext);\n });\n }\n }\n\n integratedChannel.end.subscribe(data => {\n const {\n instance,\n arguments: args,\n result,\n } = data as { instance: Pino; arguments: PinoHookArgs; result: string };\n onPinoStart(instance, args, JSON.parse(result));\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Integration for Pino logging library.\n * Captures Pino logs as Sentry logs and optionally captures some log levels as events.\n *\n * By default, all Pino loggers will be captured. To ignore a specific logger, use `pinoIntegration.untrackLogger(logger)`.\n *\n * If you disable automatic instrumentation with `autoInstrument: false`, you can mark specific loggers to be tracked with `pinoIntegration.trackLogger(logger)`.\n *\n * Requires Pino >=v8.0.0\n */\nexport const pinoIntegration = Object.assign(_pinoIntegration, {\n trackLogger(logger: unknown): void {\n if (isObjectLike(logger) && 'levels' in logger) {\n (logger as Pino)[SENTRY_TRACK_SYMBOL] = 'track';\n }\n },\n untrackLogger(logger: unknown): void {\n if (isObjectLike(logger) && 'levels' in logger) {\n (logger as Pino)[SENTRY_TRACK_SYMBOL] = 'ignore';\n }\n },\n});\n"],"mappings":";;;;AAcA,MAAM,sBAAsB,OAAO,0BAA0B;;;;;AAiB7D,SAAS,WAAW,QAAc,YAAoB,YAA4B;CAChF,MAAM,UAAU,OAAO,sBAAsB,MAAM;CACnD,MAAM,eAAe,UAAU,WAAW;CAC1C,KAAK,MAAM,OAAO,SAChB,IAAI,IAAI,SAAS,MAAM,cAAc;EACnC,MAAM,QAAQ,OAAO;EACrB,OAAO,OAAO,UAAU,WAAW,QAAQ;CAC7C;CAEF,OAAO;AACT;AAiDA,MAAM,kBAA+B;CACnC,gBAAgB;CAChB,OAAO;EAAE,QAAQ,CAAC;EAAG,SAAS;CAAK;CACnC,KAAK,EAAE,QAAQ;EAAC;EAAS;EAAS;EAAQ;EAAQ;EAAS;CAAO,EAAE;AACtE;AAaA,SAAS,mBAAmB,QAAgC;CAE1D,MAAM,EAAE,OAAO,MAAM,KAAK,UAAU,GAAG,SAAS;CAChD,OAAO;AACT;AAEA,MAAM,mBAAmB,mBAAmB,cAAwC,CAAC,MAAM;CACzF,MAAM,UAAuB;EAC3B,gBAAgB,YAAY,mBAAmB;EAC/C,OAAO;GAAE,GAAG,gBAAgB;GAAO,GAAG,YAAY;EAAM;EACxD,KAAK;GAAE,GAAG,gBAAgB;GAAK,GAAG,YAAY;EAAI;C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,CAAC;IACH;GACF;GAEA,kBAAkB,IAAI,WAAU,SAAQ;IACtC,MAAM,EACJ,UACA,WAAW,MACX,WACE;IACJ,YAAY,UAAU,MAAM,KAAK,MAAM,MAAM,CAAC;GAChD,CAAC;EACH;CACF;AACF,CAAC;;;;;;;;;;;AAYD,MAAa,kBAAkB,OAAO,OAAO,kBAAkB;CAC7D,YAAY,QAAuB;EACjC,IAAI,aAAa,MAAM,KAAK,YAAY,QACrC,OAAgB,uBAAuB;CAE5C;CACA,cAAc,QAAuB;EACnC,IAAI,aAAa,MAAM,KAAK,YAAY,QACrC,OAAgB,uBAAuB;CAE5C;AACF,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
2
|
+
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
3
|
+
import { DB } from "@sentry/conventions/op";
|
|
4
|
+
import { debug, defineIntegration, startInactiveSpan, waitForTracingChannelBinding } from "@sentry/core";
|
|
2
5
|
import { DEBUG_BUILD } from "../../debug-build.js";
|
|
3
6
|
import { getSqlQueryAttributes, getSqlSpanName } from "../../utils/sql.js";
|
|
4
7
|
import { _buildConnectionContext, _getConnectionAttributes, _reconstructQuery, _wrapQuerySettlement } from "../postgresjs-wrapper.js";
|
|
@@ -7,9 +10,6 @@ import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
|
7
10
|
import { postgresJsModuleNames } from "../../orchestrion/config/postgres.js";
|
|
8
11
|
import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
|
|
9
12
|
import { subscribePostgresJsDiagnosticChannels } from "./postgresjs-dc-subscriber.js";
|
|
10
|
-
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
11
|
-
import { debug, defineIntegration, startInactiveSpan, waitForTracingChannelBinding } from "@sentry/core";
|
|
12
|
-
import { DB } from "@sentry/conventions/op";
|
|
13
13
|
// src/integrations/postgresjs/index.ts
|
|
14
14
|
const INTEGRATION_NAME = "PostgresJs";
|
|
15
15
|
const ORIGIN = "auto.db.postgresjs";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_RESPONSE_STATUS_CODE, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
2
|
+
import { DB } from "@sentry/conventions/op";
|
|
3
|
+
import { debug, getActiveSpan, isObjectLike, startInactiveSpan } from "@sentry/core";
|
|
1
4
|
import { DEBUG_BUILD } from "../../debug-build.js";
|
|
2
5
|
import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
3
6
|
import { getSqlQueryAttributes, getSqlSpanName } from "../../utils/sql.js";
|
|
4
7
|
import { _getConnectionAttributes, _isPostgresJsWrapperSpan } from "../postgresjs-wrapper.js";
|
|
5
|
-
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_RESPONSE_STATUS_CODE, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
6
|
-
import { debug, getActiveSpan, isObjectLike, startInactiveSpan } from "@sentry/core";
|
|
7
|
-
import { DB } from "@sentry/conventions/op";
|
|
8
8
|
// src/integrations/postgresjs/postgresjs-dc-subscriber.ts
|
|
9
9
|
/**
|
|
10
10
|
* Tracing channel published by `postgres` >= 4.0.0 for every query (see postgres `src/diagnostics.js`).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { SPAN_STATUS_ERROR, addNonEnumerableProperty, debug, getActiveSpan, isObjectLike, startSpanManual } from "@sentry/core";
|
|
1
2
|
import { DEBUG_BUILD } from "../debug-build.js";
|
|
2
3
|
import { getSqlQueryAttributes, getSqlSpanName } from "../utils/sql.js";
|
|
3
4
|
import { DB_NAMESPACE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_RESPONSE_STATUS_CODE, DB_SYSTEM_NAME, ERROR_TYPE, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
4
|
-
import { SPAN_STATUS_ERROR, addNonEnumerableProperty, debug, getActiveSpan, isObjectLike, startSpanManual } from "@sentry/core";
|
|
5
5
|
import { DB } from "@sentry/conventions/op";
|
|
6
6
|
// src/integrations/postgresjs-wrapper.ts
|
|
7
7
|
const CONNECTION_CONTEXT_SYMBOL = Symbol("sentryPostgresConnectionContext");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { defineIntegration } from "@sentry/core";
|
|
1
2
|
import { prismaModuleNames } from "../../orchestrion/config/prisma.js";
|
|
2
3
|
import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
|
|
3
4
|
import { setGlobalTracingHelper } from "./global.js";
|
|
4
5
|
import { instrumentPrismaV8 } from "./orchestrion.js";
|
|
5
6
|
import { ActiveTracingHelper } from "./tracing-helper.js";
|
|
6
|
-
import { defineIntegration } from "@sentry/core";
|
|
7
7
|
// src/integrations/prisma/index.ts
|
|
8
8
|
const INTEGRATION_NAME = "Prisma";
|
|
9
9
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
2
|
+
import { getActiveSpan, startInactiveSpan, withActiveSpan } from "@sentry/core";
|
|
3
|
+
import { DB_COLLECTION_NAME, DB_OPERATION_NAME, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
4
|
+
import { DB } from "@sentry/conventions/op";
|
|
2
5
|
import { PRISMA_LAZY_TERMINALS, prismaChannels } from "../../orchestrion/config/prisma.js";
|
|
3
6
|
import { bindTracingChannelToSpan, safeChannelCallback } from "../../tracing-channel.js";
|
|
4
7
|
import { shouldIgnoreSpan } from "./tracing-helper.js";
|
|
5
|
-
import { DB_COLLECTION_NAME, DB_OPERATION_NAME, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
6
|
-
import { getActiveSpan, getRootSpan, spanIsIgnored, startInactiveSpan, withActiveSpan } from "@sentry/core";
|
|
7
|
-
import { DB } from "@sentry/conventions/op";
|
|
8
8
|
// src/integrations/prisma/orchestrion.ts
|
|
9
9
|
const OPERATION_SPAN_NAME = "prisma:client:operation";
|
|
10
10
|
const PRISMA_ORIGIN = "auto.db.prisma";
|
|
@@ -52,7 +52,7 @@ function patchConsumption(result, span, end) {
|
|
|
52
52
|
const toArray = result.toArray;
|
|
53
53
|
const asyncIterator = result[Symbol.asyncIterator];
|
|
54
54
|
const patchedToArray = function() {
|
|
55
|
-
return
|
|
55
|
+
return withActiveSpan(span, () => toArray.call(this)).then((value) => {
|
|
56
56
|
end();
|
|
57
57
|
return value;
|
|
58
58
|
}, (error) => {
|
|
@@ -61,16 +61,12 @@ function patchConsumption(result, span, end) {
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
const patchedAsyncIterator = function() {
|
|
64
|
-
return wrapIterator(
|
|
64
|
+
return wrapIterator(withActiveSpan(span, () => asyncIterator.call(this)), span, end);
|
|
65
65
|
};
|
|
66
66
|
result.toArray = patchedToArray;
|
|
67
67
|
result[Symbol.asyncIterator] = patchedAsyncIterator;
|
|
68
68
|
return true;
|
|
69
69
|
}
|
|
70
|
-
function runUnderSpan(span, callback) {
|
|
71
|
-
if (spanIsIgnored(span) && getRootSpan(span) !== span) return callback();
|
|
72
|
-
return withActiveSpan(span, callback);
|
|
73
|
-
}
|
|
74
70
|
function wrapIterator(iterator, span, end) {
|
|
75
71
|
const settle = (step) => step.then((result) => {
|
|
76
72
|
if (result.done) end();
|
|
@@ -80,7 +76,7 @@ function wrapIterator(iterator, span, end) {
|
|
|
80
76
|
throw error;
|
|
81
77
|
});
|
|
82
78
|
return {
|
|
83
|
-
next: (...args) => settle(
|
|
79
|
+
next: (...args) => settle(withActiveSpan(span, () => iterator.next(...args))),
|
|
84
80
|
return: (value) => {
|
|
85
81
|
const iteratorReturn = iterator.return?.bind(iterator);
|
|
86
82
|
if (!iteratorReturn) {
|
|
@@ -90,7 +86,7 @@ function wrapIterator(iterator, span, end) {
|
|
|
90
86
|
value
|
|
91
87
|
});
|
|
92
88
|
}
|
|
93
|
-
return settle(
|
|
89
|
+
return settle(withActiveSpan(span, () => iteratorReturn(value)));
|
|
94
90
|
},
|
|
95
91
|
throw: (error) => {
|
|
96
92
|
const iteratorThrow = iterator.throw?.bind(iterator);
|
|
@@ -98,7 +94,7 @@ function wrapIterator(iterator, span, end) {
|
|
|
98
94
|
end(error);
|
|
99
95
|
return Promise.reject(error);
|
|
100
96
|
}
|
|
101
|
-
return settle(
|
|
97
|
+
return settle(withActiveSpan(span, () => iteratorThrow(error)));
|
|
102
98
|
},
|
|
103
99
|
[Symbol.asyncIterator]() {
|
|
104
100
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrion.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../../src/integrations/prisma/orchestrion.ts"],"sourcesContent":["import * as diagnosticsChannel from '../../utils/diagnosticsChannel';\nimport type { Span } from '@sentry/core';\nimport { getActiveSpan,
|
|
1
|
+
{"version":3,"file":"orchestrion.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../../src/integrations/prisma/orchestrion.ts"],"sourcesContent":["import * as diagnosticsChannel from '../../utils/diagnosticsChannel';\nimport type { Span } from '@sentry/core';\nimport { getActiveSpan, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { DB_COLLECTION_NAME, DB_OPERATION_NAME, SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport { DB } from '@sentry/conventions/op';\nimport type { OrchestrionChannelContext } from '../../orchestrion/types';\nimport { prismaChannels, PRISMA_LAZY_TERMINALS } from '../../orchestrion/config/prisma';\nimport type { TracingChannelLifeCycleOptions } from '../../tracing-channel';\nimport { bindTracingChannelToSpan, safeChannelCallback } from '../../tracing-channel';\nimport { shouldIgnoreSpan } from './tracing-helper';\n\n// Same span name as Prisma v5–v7's own operation span, so the tree looks the same across majors.\nconst OPERATION_SPAN_NAME = 'prisma:client:operation';\nconst PRISMA_ORIGIN = 'auto.db.prisma';\n\n// Terminals call each other (`delete` reads the row through `first`); only the outermost call is the operation.\nconst operationSpans = new WeakSet<Span>();\n\ninterface PrismaCollection {\n modelName?: unknown;\n tableName?: unknown;\n}\n\ninterface PrismaTerminalChannelContext extends OrchestrionChannelContext {\n self?: PrismaCollection;\n}\n\n// Prisma's `AsyncIterableResult`: `await`, `.then()` and `.first()` all funnel through `toArray()`; only\n// `for await` goes through the iterator.\ninterface LazyResult {\n toArray: () => Promise<unknown>;\n [Symbol.asyncIterator]: () => AsyncIterator<unknown>;\n}\n\ninterface PrismaV8InstrumentationOptions {\n ignoreSpanTypes: (string | RegExp)[];\n}\n\n/**\n * Opens a `prisma:client:operation` span per ORM call, kept active while the terminal runs so the `pg`\n * query spans nest under it like the `db_query` spans did on v5–v7.\n */\nexport function instrumentPrismaV8(options: PrismaV8InstrumentationOptions): void {\n if (shouldIgnoreSpan(OPERATION_SPAN_NAME, options.ignoreSpanTypes)) {\n return;\n }\n\n for (const channelName of Object.values(prismaChannels)) {\n const method = channelName.slice(channelName.lastIndexOf(':') + 1);\n const isLazy = (PRISMA_LAZY_TERMINALS as readonly string[]).includes(method);\n\n bindTracingChannelToSpan<PrismaTerminalChannelContext>(\n diagnosticsChannel.tracingChannel<PrismaTerminalChannelContext>(channelName),\n data => startOperationSpan(method, data),\n isLazy ? { deferSpanEnd: deferSpanEndUntilConsumed } : undefined,\n );\n }\n}\n\nfunction startOperationSpan(method: string, data: PrismaTerminalChannelContext): Span | undefined {\n const parentSpan = getActiveSpan();\n if (parentSpan && operationSpans.has(parentSpan)) {\n return undefined;\n }\n\n const model = stringOrUndefined(data.self?.modelName);\n const table = stringOrUndefined(data.self?.tableName);\n\n const span = startInactiveSpan({\n name: OPERATION_SPAN_NAME,\n onlyIfParent: true,\n parentSpan,\n attributes: {\n [SENTRY_ORIGIN]: PRISMA_ORIGIN,\n [SENTRY_OP]: DB,\n [DB_OPERATION_NAME]: method,\n [DB_COLLECTION_NAME]: table ?? model,\n // Prisma v5–v7's own attributes, kept so existing queries keep matching across the major.\n method,\n model,\n name: model ? `${model}.${method}` : method,\n },\n });\n operationSpans.add(span);\n return span;\n}\n\n// A lazy terminal returns before anything is queried, so the span stays open until the result is consumed,\n// with consumption re-routed through the span's context so the driver call lands under it. A result that is\n// never consumed never ran a query; its span is simply never ended.\nconst deferSpanEndUntilConsumed: NonNullable<\n TracingChannelLifeCycleOptions<PrismaTerminalChannelContext>['deferSpanEnd']\n> = ({ span, data, end }) => {\n const result = data.result;\n if (!isLazyResult(result)) {\n return false;\n }\n\n // A throw in a channel subscriber is an uncaught exception; an unpatchable (frozen) result ends the span now.\n return safeChannelCallback(() => patchConsumption(result, span, end)) ?? false;\n};\n\nfunction patchConsumption(result: LazyResult, span: Span, end: (error?: unknown) => void): boolean {\n const toArray = result.toArray;\n const asyncIterator = result[Symbol.asyncIterator];\n\n // Built before either is installed, so a failed assignment can't leave a half-patched result.\n const patchedToArray = function (this: LazyResult): Promise<unknown> {\n const rows: Promise<unknown> = withActiveSpan(span, () => toArray.call(this));\n // Chained, not side-observed, so a rejected fire-and-forget `toArray()` still surfaces as unhandled.\n return rows.then(\n value => {\n end();\n return value;\n },\n (error: unknown) => {\n end(error);\n throw error;\n },\n );\n };\n const patchedAsyncIterator = function (this: LazyResult): AsyncIterableIterator<unknown> {\n return wrapIterator(\n withActiveSpan(span, () => asyncIterator.call(this)),\n span,\n end,\n );\n };\n\n result.toArray = patchedToArray;\n result[Symbol.asyncIterator] = patchedAsyncIterator;\n\n return true;\n}\n\nfunction wrapIterator(\n iterator: AsyncIterator<unknown>,\n span: Span,\n end: (error?: unknown) => void,\n): AsyncIterableIterator<unknown> {\n const settle = (step: Promise<IteratorResult<unknown>>): Promise<IteratorResult<unknown>> =>\n step.then(\n result => {\n if (result.done) {\n end();\n }\n return result;\n },\n error => {\n end(error);\n throw error;\n },\n );\n\n return {\n next: (...args) => settle(withActiveSpan(span, () => iterator.next(...args))),\n return: value => {\n const iteratorReturn = iterator.return?.bind(iterator);\n if (!iteratorReturn) {\n end();\n return Promise.resolve({ done: true, value });\n }\n return settle(withActiveSpan(span, () => iteratorReturn(value)));\n },\n throw: error => {\n const iteratorThrow = iterator.throw?.bind(iterator);\n if (!iteratorThrow) {\n end(error);\n return Promise.reject(error);\n }\n return settle(withActiveSpan(span, () => iteratorThrow(error)));\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n };\n}\n\nfunction stringOrUndefined(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction isLazyResult(value: unknown): value is LazyResult {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as LazyResult).toArray === 'function' &&\n typeof (value as LazyResult)[Symbol.asyncIterator] === 'function'\n );\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AAGtB,MAAM,iCAAiB,IAAI,QAAc;;;;;AA0BzC,SAAgB,mBAAmB,SAA+C;CAChF,IAAI,iBAAiB,qBAAqB,QAAQ,eAAe,GAC/D;CAGF,KAAK,MAAM,eAAe,OAAO,OAAO,cAAc,GAAG;EACvD,MAAM,SAAS,YAAY,MAAM,YAAY,YAAY,GAAG,IAAI,CAAC;EACjE,MAAM,SAAU,sBAA4C,SAAS,MAAM;EAE3E,yBACEA,eAAgE,WAAW,IAC3E,SAAQ,mBAAmB,QAAQ,IAAI,GACvC,SAAS,EAAE,cAAc,0BAA0B,IAAI,KAAA,CACzD;CACF;AACF;AAEA,SAAS,mBAAmB,QAAgB,MAAsD;CAChG,MAAM,aAAa,cAAc;CACjC,IAAI,cAAc,eAAe,IAAI,UAAU,G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S;GACf,MAAM,iBAAiB,SAAS,QAAQ,KAAK,QAAQ;GACrD,IAAI,CAAC,gBAAgB;IACnB,IAAI;IACJ,OAAO,QAAQ,QAAQ;KAAE,MAAM;KAAM;IAAM,CAAC;GAC9C;GACA,OAAO,OAAO,eAAe,YAAY,eAAe,KAAK,CAAC,CAAC;EACjE;EACA,QAAO,UAAS;GACd,MAAM,gBAAgB,SAAS,OAAO,KAAK,QAAQ;GACnD,IAAI,CAAC,eAAe;IAClB,IAAI,KAAK;IACT,OAAO,QAAQ,OAAO,KAAK;GAC7B;GACA,OAAO,OAAO,eAAe,YAAY,cAAc,KAAK,CAAC,CAAC;EAChE;EACA,CAAC,OAAO,iBAAiB;GACvB,OAAO;EACT;CACF;AACF;AAEA,SAAS,kBAAkB,OAAoC;CAC7D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,aAAa,OAAqC;CACzD,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAqB,YAAY,cACzC,OAAQ,MAAqB,OAAO,mBAAmB;AAE3D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LRUMap, debug, getActiveSpan, startInactiveSpan, startSpanManual } from "@sentry/core";
|
|
1
2
|
import { DEBUG_BUILD } from "../../debug-build.js";
|
|
2
|
-
import { getSqlQueryAttributes, getSqlSpanName, toSqlDialect } from "../../utils/sql.js";
|
|
3
3
|
import { DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_STATEMENT, DB_SYSTEM, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
4
|
-
import {
|
|
4
|
+
import { getSqlQueryAttributes, getSqlSpanName, toSqlDialect } from "../../utils/sql.js";
|
|
5
5
|
// src/integrations/prisma/tracing-helper.ts
|
|
6
6
|
const showAllTraces = (() => {
|
|
7
7
|
try {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
2
|
+
import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
3
|
+
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
4
|
+
import { SPAN_STATUS_ERROR, defineIntegration, getActiveSpan, isObjectLike, startInactiveSpan, waitForTracingChannelBinding, withActiveSpan } from "@sentry/core";
|
|
2
5
|
import { CHANNELS } from "../../orchestrion/channels.js";
|
|
3
6
|
import { getRedisQueryNaming } from "./redis-span-name.js";
|
|
4
7
|
import { defaultDbStatementSerializer } from "./redis-statement-serializer.js";
|
|
@@ -9,9 +12,6 @@ import { ioredisModuleNames } from "../../orchestrion/config/ioredis.js";
|
|
|
9
12
|
import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
|
|
10
13
|
import { subscribeRedisDiagnosticChannels } from "./redis-dc-subscriber.js";
|
|
11
14
|
import { instrumentIoredis } from "./ioredis-channel-subscriber.js";
|
|
12
|
-
import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
13
|
-
import { SPAN_STATUS_ERROR, defineIntegration, getActiveSpan, isObjectLike, startInactiveSpan, waitForTracingChannelBinding, withActiveSpan } from "@sentry/core";
|
|
14
|
-
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
15
15
|
// src/integrations/redis/index.ts
|
|
16
16
|
const INTEGRATION_NAME = "Redis";
|
|
17
17
|
const ORIGIN = "auto.db.redis";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
2
|
+
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
3
|
+
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
4
|
+
import { startInactiveSpan } from "@sentry/core";
|
|
2
5
|
import { CHANNELS } from "../../orchestrion/channels.js";
|
|
3
6
|
import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
4
7
|
import { applyCacheResponseAttributes, getRedisCacheAttributes } from "./redis-cache.js";
|
|
5
8
|
import { getRedisQueryNaming } from "./redis-span-name.js";
|
|
6
9
|
import { defaultDbStatementSerializer } from "./redis-statement-serializer.js";
|
|
7
|
-
import { DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
8
|
-
import { startInactiveSpan } from "@sentry/core";
|
|
9
|
-
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
10
10
|
// src/integrations/redis/ioredis-channel-subscriber.ts
|
|
11
11
|
const ORIGIN = "auto.db.redis";
|
|
12
12
|
const DB_SYSTEM_VALUE_REDIS = "redis";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CACHE_HIT, CACHE_ITEM_SIZE, CACHE_KEY, CACHE_OPERATION, NETWORK_PEER_ADDRESS, NETWORK_PEER_PORT, SENTRY_OP, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
2
|
-
import { CACHE_OPERATION_NAMES, getClient, hasSpanStreamingEnabled, spanToJSON, truncate } from "@sentry/core";
|
|
3
2
|
import { CACHE_GET, CACHE_PUT, CACHE_REMOVE } from "@sentry/conventions/op";
|
|
3
|
+
import { CACHE_OPERATION_NAMES, getClient, hasSpanStreamingEnabled, spanToJSON, truncate } from "@sentry/core";
|
|
4
4
|
// src/integrations/redis/redis-cache.ts
|
|
5
5
|
const SINGLE_ARG_COMMANDS = [
|
|
6
6
|
"get",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
2
|
+
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
3
|
+
import { startInactiveSpan } from "@sentry/core";
|
|
1
4
|
import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
2
5
|
import { applyCacheResponseAttributes, getRedisCacheAttributes } from "./redis-cache.js";
|
|
3
6
|
import { getRedisQueryNaming } from "./redis-span-name.js";
|
|
4
|
-
import { DB_OPERATION_BATCH_SIZE, DB_OPERATION_NAME, DB_QUERY_TEXT, DB_SYSTEM_NAME, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
5
|
-
import { startInactiveSpan } from "@sentry/core";
|
|
6
|
-
import { DB, DB_QUERY } from "@sentry/conventions/op";
|
|
7
7
|
// src/integrations/redis/redis-dc-subscriber.ts
|
|
8
8
|
const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
|
|
9
9
|
const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { subscribe } from "../utils/diagnosticsChannel.js";
|
|
2
|
-
import { instrumentTunnelServer } from "../utils/tunnelServer.js";
|
|
3
1
|
import { defineIntegration } from "@sentry/core";
|
|
4
2
|
import { HTTP_ON_SERVER_REQUEST, handleServedNodeTunnelRequest, serveTunnelIntegration, setNodeTunnelHandler } from "@sentry/core/server";
|
|
3
|
+
import { subscribe } from "../utils/diagnosticsChannel.js";
|
|
4
|
+
import { instrumentTunnelServer } from "../utils/tunnelServer.js";
|
|
5
5
|
// src/integrations/serveTunnel.ts
|
|
6
6
|
let isSubscribed = false;
|
|
7
7
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
+
import { consoleSandbox, defineIntegration, isObjectLike } from "@sentry/core";
|
|
2
3
|
import { createTanstackAIMiddleware } from "../ai/tanstack-ai/index.js";
|
|
3
4
|
import { TANSTACK_AI_INTEGRATION_NAME, TANSTACK_AI_MIDDLEWARE_BRAND } from "../ai/tanstack-ai/constants.js";
|
|
4
5
|
import { CHANNELS } from "../orchestrion/channels.js";
|
|
5
6
|
import { tanstackAiModuleNames } from "../orchestrion/config/tanstack-ai.js";
|
|
6
7
|
import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
|
|
7
8
|
import { safeChannelCallback } from "../tracing-channel.js";
|
|
8
|
-
import { consoleSandbox, defineIntegration, isObjectLike } from "@sentry/core";
|
|
9
9
|
// src/integrations/tanstack-ai.ts
|
|
10
10
|
const _tanstackAIIntegration = ((options = {}) => {
|
|
11
11
|
return {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
1
2
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
3
|
+
import { SPAN_STATUS_ERROR, defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
|
|
4
|
+
import { DB_NAMESPACE, DB_OPERATION_NAME, DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
5
|
+
import { DB } from "@sentry/conventions/op";
|
|
2
6
|
import { CHANNELS } from "../orchestrion/channels.js";
|
|
3
7
|
import { tediousModuleNames } from "../orchestrion/config/tedious.js";
|
|
4
8
|
import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
|
|
5
9
|
import { getSqlQueryAttributes } from "../utils/sql.js";
|
|
6
|
-
import { DB_NAMESPACE, DB_OPERATION_NAME, DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_SYSTEM_NAME, DB_USER, SENTRY_KIND, SENTRY_OP, SENTRY_ORIGIN, SERVER_ADDRESS, SERVER_PORT } from "@sentry/conventions/attributes";
|
|
7
|
-
import { SPAN_STATUS_ERROR, defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from "@sentry/core";
|
|
8
|
-
import { DB } from "@sentry/conventions/op";
|
|
9
|
-
import { EventEmitter } from "node:events";
|
|
10
10
|
// src/integrations/tedious.ts
|
|
11
11
|
const INTEGRATION_NAME = "Tedious";
|
|
12
12
|
const ORIGIN = "auto.db.tedious";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { defineIntegration } from "@sentry/core";
|
|
1
2
|
import { CHANNELS } from "../orchestrion/channels.js";
|
|
2
3
|
import { togetherAiModuleNames } from "../orchestrion/config/together-ai.js";
|
|
3
4
|
import { createOpenAiCompatibleIntegration } from "./openai-compatible.js";
|
|
4
|
-
import { defineIntegration } from "@sentry/core";
|
|
5
5
|
// src/integrations/together-ai.ts
|
|
6
6
|
/**
|
|
7
7
|
* Instruments the `together-ai` client (chat completions and embeddings). Together speaks the OpenAI wire
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
+
import { defineIntegration } from "@sentry/core";
|
|
2
3
|
import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
|
|
3
4
|
import { resolveGenAiCallRecording } from "../ai/core/utils.js";
|
|
4
5
|
import { addResponseAttributes, onSystemOneResponse, startDecideSpan } from "../ai/typesafe/index.js";
|
|
@@ -7,7 +8,6 @@ import { CHANNELS } from "../orchestrion/channels.js";
|
|
|
7
8
|
import { typesafeModuleNames } from "../orchestrion/config/typesafe.js";
|
|
8
9
|
import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
|
|
9
10
|
import { bindTracingChannelToSpan } from "../tracing-channel.js";
|
|
10
|
-
import { defineIntegration } from "@sentry/core";
|
|
11
11
|
// src/integrations/typesafe.ts
|
|
12
12
|
const _typesafeIntegration = ((options = {}) => {
|
|
13
13
|
return {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { mapObjectValues } from "./util.js";
|
|
2
1
|
import { isObjectLike, stringify } from "@sentry/core";
|
|
2
|
+
import { asNumber, mapObjectValues } from "./util.js";
|
|
3
3
|
// src/integrations/vercel-ai/extract.ts
|
|
4
|
-
/** Maps the AI SDK `experimental_extract` input and output to the Clairic shape of the `gen_ai.extract` schemas. */
|
|
5
4
|
/**
|
|
6
5
|
* Joins the text of the AI SDK state parts into one Clairic `state` string. The gateway does this join on
|
|
7
6
|
* the server and does not show its separator, so this one is our choice. It only makes the recorded text
|
|
@@ -62,7 +61,7 @@ function toExtractAnswers(answers, parts) {
|
|
|
62
61
|
return mapObjectValues(answers, ({ pNull, source, items, ...rest }) => {
|
|
63
62
|
const mapped = {
|
|
64
63
|
...rest,
|
|
65
|
-
p_null: pNull
|
|
64
|
+
p_null: asNumber(pNull)
|
|
66
65
|
};
|
|
67
66
|
const span = toExtractSpan(source, parts);
|
|
68
67
|
if (span) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","names":[],"sources":["../../../../src/integrations/vercel-ai/extract.ts"],"sourcesContent":["/** Maps the AI SDK `experimental_extract` input and output to the Clairic shape of the `gen_ai.extract` schemas. */\n\nimport { isObjectLike, stringify } from '@sentry/core';\nimport { mapObjectValues } from './util';\n\n/**\n * Joins the text of the AI SDK state parts into one Clairic `state` string. The gateway does this join on\n * the server and does not show its separator, so this one is our choice. It only makes the recorded text\n * easier to read: the answer spans stay correct with any separator, because we add each part's offset.\n */\nconst EXTRACT_STATE_SEPARATOR = '\\n\\n';\nconst BLOB_SUBSTITUTE = '[Blob substitute]';\n\ninterface ExtractState {\n request:
|
|
1
|
+
{"version":3,"file":"extract.js","names":[],"sources":["../../../../src/integrations/vercel-ai/extract.ts"],"sourcesContent":["/** Maps the AI SDK `experimental_extract` input and output to the Clairic shape of the `gen_ai.extract` schemas. */\n\nimport type { ExtractAnswer, ExtractRequest, ExtractSpan } from '@sentry/conventions/attributes';\nimport { isObjectLike, stringify } from '@sentry/core';\nimport { asNumber, mapObjectValues } from './util';\n\n/**\n * Joins the text of the AI SDK state parts into one Clairic `state` string. The gateway does this join on\n * the server and does not show its separator, so this one is our choice. It only makes the recorded text\n * easier to read: the answer spans stay correct with any separator, because we add each part's offset.\n */\nconst EXTRACT_STATE_SEPARATOR = '\\n\\n';\nconst BLOB_SUBSTITUTE = '[Blob substitute]';\n\ninterface ExtractState {\n request: Pick<ExtractRequest, 'state' | 'images' | 'documents'>;\n /** For each AI SDK state part, the offset of its text in `request.state`, or `'image'` for an image part. */\n parts: (number | 'image' | undefined)[];\n}\n\n/**\n * Clairic takes the text as one `state` string, with images and PDF documents in their own arrays. The AI SDK\n * also takes a JSON object, or an array of text, JSON and file parts. Join the text of the parts and keep the\n * offset of each part, so that the answer spans point into the joined `state`.\n */\nexport function toExtractState(state: unknown): ExtractState {\n const images: string[] = [];\n const documents: string[] = [];\n // Each text gets a separator in front, which is cut off from the start of `state` at the end.\n let joined = '';\n\n const parts = (Array.isArray(state) ? state : [{ type: 'json', value: state }]).map(part => {\n if (!isObjectLike(part)) {\n return undefined;\n }\n if (part.type === 'file') {\n if (String(part.mediaType).split('/')[0] === 'image') {\n images.push(BLOB_SUBSTITUTE);\n return 'image' as const;\n }\n if (part.mediaType === 'application/pdf') {\n documents.push(BLOB_SUBSTITUTE);\n }\n return undefined;\n }\n const text = part.type === 'text' ? part.text : stringify(part.value);\n if (typeof text !== 'string') {\n return undefined;\n }\n joined += EXTRACT_STATE_SEPARATOR + text;\n return joined.length - text.length - EXTRACT_STATE_SEPARATOR.length;\n });\n\n return {\n request: {\n state: joined ? joined.slice(EXTRACT_STATE_SEPARATOR.length) : undefined,\n images: images.length ? images : undefined,\n documents: documents.length ? documents : undefined,\n },\n parts,\n };\n}\n\n/**\n * The AI SDK also takes JSON or `null` as field `instructions`, but the schema allows only a string.\n */\nexport function toExtractFields(fields: unknown): unknown {\n return isObjectLike(fields)\n ? mapObjectValues(fields, field => ({\n ...field,\n instructions: field.instructions === null ? undefined : stringify(field.instructions),\n }))\n : fields;\n}\n\n/**\n * The AI SDK normalizes the provider's extraction answers. Map them back to the provider shape of\n * `gen_ai.output.messages` on `gen_ai.extract` spans. The AI SDK does not expose `truncated`.\n */\nexport function toExtractAnswers(\n answers: Record<string, unknown>,\n parts: ExtractState['parts'],\n): Record<string, unknown> {\n return mapObjectValues(answers, ({ pNull, source, items, ...rest }) => {\n const mapped: Record<string, unknown> & Partial<ExtractAnswer> = { ...rest, p_null: asNumber(pNull) };\n const span = toExtractSpan(source, parts);\n if (span) {\n mapped.source = 'input';\n mapped.span = span;\n } else if (isObjectLike(source) && parts[Number(source.part)] === 'image') {\n mapped.source = 'image';\n }\n if (Array.isArray(items)) {\n const confidences = items.map(item => (isObjectLike(item) ? item.confidence : undefined));\n if (confidences.every(confidence => typeof confidence === 'number')) {\n mapped.confidences = confidences;\n }\n const spans = items.map(item => toExtractSpan(isObjectLike(item) ? item.source : undefined, parts));\n if (spans.some(Boolean)) {\n mapped.spans = spans;\n }\n }\n return mapped;\n });\n}\n\nfunction toExtractSpan(source: unknown, parts: ExtractState['parts']): ExtractSpan | null {\n if (!isObjectLike(source) || source.type !== 'text') {\n return null;\n }\n const offset = parts[Number(source.part)];\n return typeof offset === 'number' ? [offset + Number(source.start), offset + Number(source.end)] : null;\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,0BAA0B;AAChC,MAAM,kBAAkB;;;;;;AAaxB,SAAgB,eAAe,OAA8B;CAC3D,MAAM,SAAmB,CAAC;CAC1B,MAAM,YAAsB,CAAC;CAE7B,IAAI,SAAS;CAEb,MAAM,SAAS,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC;EAAE,MAAM;EAAQ,OAAO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Aa,KAAA,CAAU;GACxF,IAAI,YAAY,OAAM,eAAc,OAAO,eAAe,QAAQ,GAChE,OAAO,cAAc;GAEvB,MAAM,QAAQ,MAAM,KAAI,SAAQ,cAAc,aAAa,IAAI,IAAI,KAAK,SAAS,KAAA,GAAW,KAAK,CAAC;GAClG,IAAI,MAAM,KAAK,OAAO,GACpB,OAAO,QAAQ;EAEnB;EACA,OAAO;CACT,CAAC;AACH;AAEA,SAAS,cAAc,QAAiB,OAAkD;CACxF,IAAI,CAAC,aAAa,MAAM,KAAK,OAAO,SAAS,QAC3C,OAAO;CAET,MAAM,SAAS,MAAM,OAAO,OAAO,IAAI;CACvC,OAAO,OAAO,WAAW,WAAW,CAAC,SAAS,OAAO,OAAO,KAAK,GAAG,SAAS,OAAO,OAAO,GAAG,CAAC,IAAI;AACrG"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { defineIntegration, waitForTracingChannelBinding } from "@sentry/core";
|
|
1
2
|
import { subscribeVercelAiTracingChannel } from "./vercel-ai-dc-subscriber.js";
|
|
2
3
|
import { registerVercelAiToolTelemetry } from "./vercel-ai-tool-telemetry.js";
|
|
3
4
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
4
5
|
import { invokeOrchestrionInstrumentation } from "../../orchestrion/instrumentation.js";
|
|
5
6
|
import { vercelAiModuleNames } from "../../orchestrion/config/vercel-ai.js";
|
|
6
7
|
import { subscribeVercelAiOrchestrionChannels } from "./vercel-ai-orchestrion-subscriber.js";
|
|
7
|
-
import { defineIntegration, waitForTracingChannelBinding } from "@sentry/core";
|
|
8
8
|
// src/integrations/vercel-ai/index.ts
|
|
9
9
|
const _vercelAIIntegration = ((options = {}) => {
|
|
10
10
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { isObjectLike } from "@sentry/core";
|
|
1
2
|
import { recordTimeToFirstChunk } from "../../ai/core/time-to-first-chunk.js";
|
|
2
3
|
import { isReadableStream } from "../../ai/core/utils.js";
|
|
3
|
-
import { isObjectLike } from "@sentry/core";
|
|
4
4
|
// src/integrations/vercel-ai/util.ts
|
|
5
5
|
/** Narrow to a string, or `undefined` for anything else. */
|
|
6
6
|
function asString(value) {
|
|
@@ -48,7 +48,7 @@ function tapModelCallStream(span, stream, onFinal, onError) {
|
|
|
48
48
|
controller.close();
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
if (value
|
|
51
|
+
if (hasOutput(value)) recordTimeToFirstChunk(span);
|
|
52
52
|
text += accumulateChunk(state, value) ?? "";
|
|
53
53
|
controller.enqueue(value);
|
|
54
54
|
} catch (error) {
|
|
@@ -63,6 +63,25 @@ function tapModelCallStream(span, stream, onFinal, onError) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* Whether a chunk carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
67
|
+
* `stream-start`, `response-metadata`, empty `*-start` and `finish` chunks do not.
|
|
68
|
+
*/
|
|
69
|
+
function hasOutput(chunk) {
|
|
70
|
+
if (!isObjectLike(chunk)) return false;
|
|
71
|
+
const { type, delta, textDelta, argsTextDelta } = chunk;
|
|
72
|
+
switch (type) {
|
|
73
|
+
case "text-delta":
|
|
74
|
+
case "reasoning-delta":
|
|
75
|
+
case "tool-input-delta": return !!(delta ?? textDelta);
|
|
76
|
+
case "reasoning": return !!textDelta;
|
|
77
|
+
case "tool-call-delta": return !!argsTextDelta;
|
|
78
|
+
case "tool-input-start":
|
|
79
|
+
case "tool-call":
|
|
80
|
+
case "file": return true;
|
|
81
|
+
default: return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
66
85
|
* Fold a single streamed chunk into the running aggregate. Returns any text delta so the caller can
|
|
67
86
|
* accumulate it (kept out of `state` until the end to avoid re-joining on every chunk).
|
|
68
87
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","names":[],"sources":["../../../../src/integrations/vercel-ai/util.ts"],"sourcesContent":["/** Shared, state-free helpers for the Vercel AI (`ai`) channel subscribers, plus the streamed model-call tap. */\n\nimport type { Span } from '@sentry/core';\nimport { isObjectLike } from '@sentry/core';\nimport { recordTimeToFirstChunk } from '../../ai/core/time-to-first-chunk';\n\n/** Narrow to a string, or `undefined` for anything else. */\nexport function asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\n/** Narrow to a finite number, or `undefined` for anything else (including `NaN`). */\nexport function asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && !isNaN(value) ? value : undefined;\n}\n\n/** Add two optional numbers, treating a missing operand as `0` but returning `undefined` when both are absent. */\nexport function sum(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);\n}\n\n/*\n * Streaming support for the `ai:telemetry` tracing channel.\n *\n * For a streamed model call (`doStream`) the SDK resolves the `languageModelCall` channel promise as\n * soon as it hands back the *unconsumed* stream — so `result.stream` is a `ReadableStream` and the\n * final usage / finish reason / output only arrive later, as the stream is drained (they ride the\n * stream's own `finish`/`text-delta`/`tool-call` chunks, never the channel context). The SDK\n * deliberately leaves `result` undefined on the `streamText`/`step` contexts and exposes the stream\n * only on the model call, expecting consumers to tap it themselves.\n * @see https://github.com/vercel/ai/pull/15660 (discussion: \"tee off and aggregate ourselves\")\n *\n * We replace `result.stream` with a passthrough that forwards every chunk untouched (so the SDK's own\n * consumption is unaffected) while accumulating the data we need, then hand the aggregate back once the\n * stream settles so the model-call span can be enriched and ended out-of-band.\n */\n\n/** The subset of a streamed provider chunk we read. Unknown chunk types are forwarded and ignored. */\ninterface StreamChunk {\n type?: unknown;\n delta?: unknown;\n // v4 text-delta chunks carry the text on `textDelta`; v5+ uses `delta`.\n textDelta?: unknown;\n id?: unknown;\n modelId?: unknown;\n toolCallId?: unknown;\n toolName?: unknown;\n input?: unknown;\n args?: unknown;\n finishReason?: unknown;\n usage?: unknown;\n providerMetadata?: unknown;\n error?: unknown;\n}\n\n/** The aggregate handed back once a streamed model call finishes, in the shape `enrichSpanOnEnd` expects. */\nexport interface StreamedModelCallResult {\n text?: string;\n toolCalls: Array<Record<string, unknown>>;\n usage?: unknown;\n finishReason?: unknown;\n responseId?: string;\n responseModel?: string;\n providerMetadata?: unknown;\n}\n\n/** The streamed model call exposes a web `ReadableStream` on `result.stream`. */\nexport { isReadableStream } from '../../ai/core/utils';\n\n/**\n * Wrap a streamed model call's `ReadableStream` so its chunks are observed as the SDK consumes them,\n * without altering what the SDK sees. Returns a replacement stream to swap onto `result.stream`.\n *\n * `onFinal` runs exactly once when the stream drains cleanly; `onError` runs exactly once if it errors\n * or is cancelled. Reading one source chunk per `pull` preserves the SDK's backpressure. The\n * `try/catch` around every read guarantees the owning span is always ended — a leaked open span on a\n * mid-stream failure would be worse than a slightly-less-enriched one.\n */\nexport function tapModelCallStream(\n span: Span,\n stream: ReadableStream<unknown>,\n onFinal: (result: StreamedModelCallResult) => void,\n onError: (error: unknown) => void,\n): ReadableStream<unknown> {\n const reader = stream.getReader();\n const state: StreamedModelCallResult = { toolCalls: [] };\n let text = '';\n let settled = false;\n\n const finalize = (): void => {\n if (settled) {\n return;\n }\n settled = true;\n if (text) {\n state.text = text;\n }\n onFinal(state);\n };\n\n const fail = (error: unknown): void => {\n if (settled) {\n return;\n }\n settled = true;\n onError(error);\n };\n\n return new ReadableStream<unknown>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finalize();\n controller.close();\n\n return;\n }\n
|
|
1
|
+
{"version":3,"file":"util.js","names":[],"sources":["../../../../src/integrations/vercel-ai/util.ts"],"sourcesContent":["/** Shared, state-free helpers for the Vercel AI (`ai`) channel subscribers, plus the streamed model-call tap. */\n\nimport type { Span } from '@sentry/core';\nimport { isObjectLike } from '@sentry/core';\nimport { recordTimeToFirstChunk } from '../../ai/core/time-to-first-chunk';\n\n/** Narrow to a string, or `undefined` for anything else. */\nexport function asString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\n/** Narrow to a finite number, or `undefined` for anything else (including `NaN`). */\nexport function asNumber(value: unknown): number | undefined {\n return typeof value === 'number' && !isNaN(value) ? value : undefined;\n}\n\n/** Add two optional numbers, treating a missing operand as `0` but returning `undefined` when both are absent. */\nexport function sum(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0);\n}\n\n/*\n * Streaming support for the `ai:telemetry` tracing channel.\n *\n * For a streamed model call (`doStream`) the SDK resolves the `languageModelCall` channel promise as\n * soon as it hands back the *unconsumed* stream — so `result.stream` is a `ReadableStream` and the\n * final usage / finish reason / output only arrive later, as the stream is drained (they ride the\n * stream's own `finish`/`text-delta`/`tool-call` chunks, never the channel context). The SDK\n * deliberately leaves `result` undefined on the `streamText`/`step` contexts and exposes the stream\n * only on the model call, expecting consumers to tap it themselves.\n * @see https://github.com/vercel/ai/pull/15660 (discussion: \"tee off and aggregate ourselves\")\n *\n * We replace `result.stream` with a passthrough that forwards every chunk untouched (so the SDK's own\n * consumption is unaffected) while accumulating the data we need, then hand the aggregate back once the\n * stream settles so the model-call span can be enriched and ended out-of-band.\n */\n\n/** The subset of a streamed provider chunk we read. Unknown chunk types are forwarded and ignored. */\ninterface StreamChunk {\n type?: unknown;\n delta?: unknown;\n // v4 text-delta chunks carry the text on `textDelta`; v5+ uses `delta`.\n textDelta?: unknown;\n id?: unknown;\n modelId?: unknown;\n toolCallId?: unknown;\n toolName?: unknown;\n input?: unknown;\n args?: unknown;\n finishReason?: unknown;\n usage?: unknown;\n providerMetadata?: unknown;\n error?: unknown;\n}\n\n/** The aggregate handed back once a streamed model call finishes, in the shape `enrichSpanOnEnd` expects. */\nexport interface StreamedModelCallResult {\n text?: string;\n toolCalls: Array<Record<string, unknown>>;\n usage?: unknown;\n finishReason?: unknown;\n responseId?: string;\n responseModel?: string;\n providerMetadata?: unknown;\n}\n\n/** The streamed model call exposes a web `ReadableStream` on `result.stream`. */\nexport { isReadableStream } from '../../ai/core/utils';\n\n/**\n * Wrap a streamed model call's `ReadableStream` so its chunks are observed as the SDK consumes them,\n * without altering what the SDK sees. Returns a replacement stream to swap onto `result.stream`.\n *\n * `onFinal` runs exactly once when the stream drains cleanly; `onError` runs exactly once if it errors\n * or is cancelled. Reading one source chunk per `pull` preserves the SDK's backpressure. The\n * `try/catch` around every read guarantees the owning span is always ended — a leaked open span on a\n * mid-stream failure would be worse than a slightly-less-enriched one.\n */\nexport function tapModelCallStream(\n span: Span,\n stream: ReadableStream<unknown>,\n onFinal: (result: StreamedModelCallResult) => void,\n onError: (error: unknown) => void,\n): ReadableStream<unknown> {\n const reader = stream.getReader();\n const state: StreamedModelCallResult = { toolCalls: [] };\n let text = '';\n let settled = false;\n\n const finalize = (): void => {\n if (settled) {\n return;\n }\n settled = true;\n if (text) {\n state.text = text;\n }\n onFinal(state);\n };\n\n const fail = (error: unknown): void => {\n if (settled) {\n return;\n }\n settled = true;\n onError(error);\n };\n\n return new ReadableStream<unknown>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finalize();\n controller.close();\n\n return;\n }\n if (hasOutput(value)) {\n recordTimeToFirstChunk(span);\n }\n text += accumulateChunk(state, value) ?? '';\n controller.enqueue(value);\n } catch (error) {\n fail(error);\n controller.error(error);\n }\n },\n cancel(reason) {\n // Consumer stopped reading early (e.g. a `break` out of `for await`); close out the span with\n // whatever we have rather than leave it open. A non-error reason is a deliberate stop, not a failure.\n finalize();\n\n return reader.cancel(reason);\n },\n });\n}\n\n/**\n * Whether a chunk carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.\n * `stream-start`, `response-metadata`, empty `*-start` and `finish` chunks do not.\n */\nfunction hasOutput(chunk: unknown): boolean {\n if (!isObjectLike(chunk)) {\n return false;\n }\n const { type, delta, textDelta, argsTextDelta } = chunk as StreamChunk & { argsTextDelta?: unknown };\n switch (type) {\n case 'text-delta':\n case 'reasoning-delta':\n case 'tool-input-delta':\n return !!(delta ?? textDelta);\n // v4 streams reasoning on `textDelta` and tool arguments on `argsTextDelta`.\n case 'reasoning':\n return !!textDelta;\n case 'tool-call-delta':\n return !!argsTextDelta;\n // These carry a tool name, a whole tool call or a generated file.\n case 'tool-input-start':\n case 'tool-call':\n case 'file':\n return true;\n default:\n return false;\n }\n}\n\n/**\n * Fold a single streamed chunk into the running aggregate. Returns any text delta so the caller can\n * accumulate it (kept out of `state` until the end to avoid re-joining on every chunk).\n */\nfunction accumulateChunk(state: StreamedModelCallResult, chunk: unknown): string | undefined {\n if (!isObjectLike(chunk)) {\n return undefined;\n }\n const {\n type,\n delta,\n textDelta,\n id,\n modelId,\n toolCallId,\n toolName,\n input,\n args,\n finishReason,\n usage,\n providerMetadata,\n } = chunk as StreamChunk;\n\n switch (type) {\n case 'text-delta': {\n const textChunk = delta ?? textDelta;\n return typeof textChunk === 'string' ? textChunk : undefined;\n }\n case 'tool-call':\n state.toolCalls.push({ toolCallId, toolName, input: input ?? args });\n\n return undefined;\n case 'response-metadata':\n if (typeof id === 'string') {\n state.responseId = id;\n }\n if (typeof modelId === 'string') {\n state.responseModel = modelId;\n }\n\n return undefined;\n case 'finish':\n state.finishReason = finishReason;\n state.usage = usage;\n if (providerMetadata !== undefined) {\n state.providerMetadata = providerMetadata;\n }\n\n return undefined;\n default:\n return undefined;\n }\n}\n\n/** Maps each object value of `record` and keeps the other values as they are. */\nexport function mapObjectValues(\n record: Record<string, unknown>,\n fn: (value: Record<string, unknown>, key: string) => unknown,\n): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(record).map(([key, value]) => [key, isObjectLike(value) ? fn(value, key) : value]),\n );\n}\n"],"mappings":";;;;;AAOA,SAAgB,SAAS,OAAoC;CAC3D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;;AAGA,SAAgB,SAAS,OAAoC;CAC3D,OAAO,OAAO,UAAU,YAAY,CAAC,MAAM,KAAK,IAAI,QAAQ,KAAA;AAC9D;;AAGA,SAAgB,IAAI,GAAuB,GAA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oC;CAC3F,IAAI,CAAC,aAAa,KAAK,GACrB;CAEF,MAAM,EACJ,MACA,OACA,WACA,IACA,SACA,YACA,UACA,OACA,MACA,cACA,OACA,qBACE;CAEJ,QAAQ,MAAR;EACE,KAAK,cAAc;GACjB,MAAM,YAAY,SAAS;GAC3B,OAAO,OAAO,cAAc,WAAW,YAAY,KAAA;EACrD;EACA,KAAK;GACH,MAAM,UAAU,KAAK;IAAE;IAAY;IAAU,OAAO,SAAS;GAAK,CAAC;GAEnE;EACF,KAAK;GACH,IAAI,OAAO,OAAO,UAChB,MAAM,aAAa;GAErB,IAAI,OAAO,YAAY,UACrB,MAAM,gBAAgB;GAGxB;EACF,KAAK;GACH,MAAM,eAAe;GACrB,MAAM,QAAQ;GACd,IAAI,qBAAqB,KAAA,GACvB,MAAM,mBAAmB;GAG3B;EACF,SACE;CACJ;AACF;;AAGA,SAAgB,gBACd,QACA,IACyB;CACzB,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,aAAa,KAAK,IAAI,GAAG,OAAO,GAAG,IAAI,KAAK,CAAC,CAClG;AACF"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { GEN_AI_CONVERSATION_ID, GEN_AI_COST_TOTAL_TOKENS, GEN_AI_EMBEDDINGS_INPUT, GEN_AI_FUNCTION_ID, GEN_AI_INPUT_MESSAGES, GEN_AI_OPERATION_NAME, GEN_AI_OUTPUT_MESSAGES, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_RESPONSE_ID, GEN_AI_RESPONSE_MODEL, GEN_AI_RESPONSE_STREAMING, GEN_AI_SYSTEM_INSTRUCTIONS, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_TOOL_CALL_RESULT, GEN_AI_TOOL_DEFINITIONS, GEN_AI_TOOL_DESCRIPTION, GEN_AI_TOOL_NAME, GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_REASONING_OUTPUT_TOKENS, GEN_AI_USAGE_TOTAL_TOKENS, SENTRY_OP, SENTRY_ORIGIN, VERCEL_AI_SETTINGS_CONTEXT_KEY_BASE, VERCEL_AI_TOOL_CALL_CONTEXT_KEY_BASE } from "@sentry/conventions/attributes";
|
|
2
|
+
import { GEN_AI_DECIDE, GEN_AI_EMBEDDINGS, GEN_AI_EXECUTE_TOOL, GEN_AI_EXTRACT, GEN_AI_GENERATE_CONTENT, GEN_AI_INVOKE_AGENT, GEN_AI_RERANK } from "@sentry/conventions/op";
|
|
3
|
+
import { SPAN_STATUS_ERROR, _INTERNAL_skipAiProviderWrapping, captureException, getActiveSpan, getClient, isObjectLike, isPlainObject, spanToJSON, spanToTraceContext, startInactiveSpan, stringify, withScope } from "@sentry/core";
|
|
1
4
|
import { GEN_AI_TOOL_CALL_ID_ATTRIBUTE } from "../../ai/core/gen-ai-attributes.js";
|
|
2
5
|
import { runGenAiSpanEnd, runGenAiSpanStart } from "../../ai/core/span-hooks.js";
|
|
3
6
|
import { isEveGenAiRecordingDefault } from "./gen-ai-recording-mode.js";
|
|
@@ -7,9 +10,6 @@ import { WORKERS_AI_INTEGRATION_NAME } from "../../ai/workers-ai/constants.js";
|
|
|
7
10
|
import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
8
11
|
import { toExtractAnswers, toExtractFields, toExtractState } from "./extract.js";
|
|
9
12
|
import { asNumber, asString, mapObjectValues, sum, tapModelCallStream } from "./util.js";
|
|
10
|
-
import { GEN_AI_CONVERSATION_ID, GEN_AI_COST_TOTAL_TOKENS, GEN_AI_EMBEDDINGS_INPUT, GEN_AI_FUNCTION_ID, GEN_AI_INPUT_MESSAGES, GEN_AI_OPERATION_NAME, GEN_AI_OUTPUT_MESSAGES, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MODEL, GEN_AI_RESPONSE_FINISH_REASONS, GEN_AI_RESPONSE_ID, GEN_AI_RESPONSE_MODEL, GEN_AI_RESPONSE_STREAMING, GEN_AI_SYSTEM_INSTRUCTIONS, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_TOOL_CALL_RESULT, GEN_AI_TOOL_DEFINITIONS, GEN_AI_TOOL_DESCRIPTION, GEN_AI_TOOL_NAME, GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_REASONING_OUTPUT_TOKENS, GEN_AI_USAGE_TOTAL_TOKENS, SENTRY_OP, SENTRY_ORIGIN, VERCEL_AI_SETTINGS_CONTEXT_KEY_BASE, VERCEL_AI_TOOL_CALL_CONTEXT_KEY_BASE } from "@sentry/conventions/attributes";
|
|
11
|
-
import { SPAN_STATUS_ERROR, _INTERNAL_skipAiProviderWrapping, captureException, getActiveSpan, getClient, isObjectLike, isPlainObject, spanToJSON, spanToTraceContext, startInactiveSpan, stringify, withScope } from "@sentry/core";
|
|
12
|
-
import { GEN_AI_DECIDE, GEN_AI_EMBEDDINGS, GEN_AI_EXECUTE_TOOL, GEN_AI_EXTRACT, GEN_AI_GENERATE_CONTENT, GEN_AI_INVOKE_AGENT, GEN_AI_RERANK } from "@sentry/conventions/op";
|
|
13
13
|
// src/integrations/vercel-ai/vercel-ai-dc-subscriber.ts
|
|
14
14
|
/**
|
|
15
15
|
* The single tracing channel the `ai` package (>= 7) publishes all telemetry lifecycle events to
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { SPAN_STATUS_ERROR, addNonEnumerableProperty, debug, getActiveSpan, isObjectLike, withActiveSpan } from "@sentry/core";
|
|
1
2
|
import { DEBUG_BUILD } from "../../debug-build.js";
|
|
2
3
|
import { isReadableStream } from "../../ai/core/utils.js";
|
|
3
4
|
import { CHANNELS } from "../../orchestrion/channels.js";
|
|
4
5
|
import { bindTracingChannelToSpan } from "../../tracing-channel.js";
|
|
5
6
|
import { captureToolError, clearOperationCallId, clearOperationId, createSpanFromMessage, enrichSpanOnEnd, runVercelAiSpanEnd, streamedResultToChannelResult } from "./vercel-ai-dc-subscriber.js";
|
|
6
7
|
import { asString, tapModelCallStream } from "./util.js";
|
|
7
|
-
import { SPAN_STATUS_ERROR, addNonEnumerableProperty, debug, getActiveSpan, isObjectLike, withActiveSpan } from "@sentry/core";
|
|
8
8
|
// src/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.ts
|
|
9
9
|
const PATCHED = Symbol("SentryVercelAiModelPatched");
|
|
10
10
|
const TOOL_PATCHED = Symbol("SentryVercelAiToolPatched");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { SENTRY_OP } from "@sentry/conventions/attributes";
|
|
2
|
+
import { GEN_AI_GENERATE_CONTENT } from "@sentry/conventions/op";
|
|
3
|
+
import { getActiveSpan, handleCallbackErrors, spanToJSON } from "@sentry/core";
|
|
1
4
|
import "../../ai/core/gen-ai-attributes.js";
|
|
2
5
|
import { tracingChannel } from "../../utils/diagnosticsChannel.js";
|
|
3
6
|
import { AI_SDK_TELEMETRY_TRACING_CHANNEL, fallbackChannelResults } from "./vercel-ai-dc-subscriber.js";
|
|
4
|
-
import { SENTRY_OP } from "@sentry/conventions/attributes";
|
|
5
|
-
import { getActiveSpan, handleCallbackErrors, spanToJSON } from "@sentry/core";
|
|
6
|
-
import { GEN_AI_GENERATE_CONTENT } from "@sentry/conventions/op";
|
|
7
7
|
// src/integrations/vercel-ai/vercel-ai-tool-telemetry.ts
|
|
8
8
|
const openToolCalls = /* @__PURE__ */ new Map();
|
|
9
9
|
function isRecordingOff(event) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DEBUG_BUILD } from "../debug-build.js";
|
|
2
1
|
import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
3
2
|
import { captureLogEvent, debug, isObjectLike } from "@sentry/core";
|
|
3
|
+
import { DEBUG_BUILD } from "../debug-build.js";
|
|
4
4
|
// src/integrations/winston.ts
|
|
5
5
|
const DEFAULT_CAPTURED_LEVELS = [
|
|
6
6
|
"trace",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SENTRY_API_VERSION, defineIntegration, dsnFromString, registerExternalPropagationContext } from "@sentry/core";
|
|
2
1
|
import { isSpanContextValid, trace } from "@opentelemetry/api";
|
|
2
|
+
import { SENTRY_API_VERSION, defineIntegration, dsnFromString, registerExternalPropagationContext } from "@sentry/core";
|
|
3
3
|
// src/opentelemetry.ts
|
|
4
4
|
const INTEGRATION_NAME = "OpenTelemetry";
|
|
5
5
|
const _openTelemetryIntegration = (() => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import codeTransformerEsbuild from "../../vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/esbuild.js";
|
|
2
|
+
import { escapeStringForRegex } from "@sentry/core";
|
|
2
3
|
import { instrumentedModuleNames } from "../config/index.js";
|
|
3
4
|
import { externalEntryMatchesModule, externalizedModulesWarning, orchestrionTransformOptions } from "./options.js";
|
|
4
5
|
import { SNIPPET_IMPORT_SPECIFIER_FILTER, resolveOrchestrionRuntimeRequest } from "./resolve.js";
|
|
5
|
-
import { escapeStringForRegex } from "@sentry/core";
|
|
6
6
|
// src/orchestrion/bundler/esbuild.ts
|
|
7
7
|
function matchesEsbuildExternal(entry, moduleName) {
|
|
8
8
|
if (entry.includes("*")) return new RegExp(`^${entry.split("*").map(escapeStringForRegex).join(".*")}$`).test(moduleName);
|