@sentry/server-utils 11.13.0 → 11.15.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/chunks/config.js +19 -5
- package/build/cjs/chunks/config.js.map +1 -1
- package/build/cjs/chunks/exports.js +593 -238
- package/build/cjs/chunks/exports.js.map +1 -1
- package/build/cjs/chunks/moduleInjectedTransform.js +6 -5
- package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
- package/build/cjs/index.js +1186 -182
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/orchestrion/bundler/rollup.js +4 -4
- package/build/cjs/orchestrion/bundler/rollup.js.map +1 -1
- package/build/esm/ai/anthropic-ai/index.js +32 -56
- package/build/esm/ai/anthropic-ai/index.js.map +1 -1
- package/build/esm/ai/anthropic-ai/streaming.js +10 -6
- package/build/esm/ai/anthropic-ai/streaming.js.map +1 -1
- package/build/esm/ai/anthropic-ai/tool-runner.js +18 -3
- package/build/esm/ai/anthropic-ai/tool-runner.js.map +1 -1
- package/build/esm/ai/anthropic-ai/utils.js +41 -3
- package/build/esm/ai/anthropic-ai/utils.js.map +1 -1
- package/build/esm/ai/core/span-hooks.js +23 -0
- package/build/esm/ai/core/span-hooks.js.map +1 -0
- package/build/esm/ai/core/time-to-first-chunk.js +14 -0
- package/build/esm/ai/core/time-to-first-chunk.js.map +1 -0
- package/build/esm/ai/core/utils.js +29 -3
- package/build/esm/ai/core/utils.js.map +1 -1
- package/build/esm/ai/flue/index.js +15 -12
- package/build/esm/ai/flue/index.js.map +1 -1
- package/build/esm/ai/flue/utils.js +24 -17
- package/build/esm/ai/flue/utils.js.map +1 -1
- package/build/esm/ai/google-genai/constants.js +2 -1
- package/build/esm/ai/google-genai/constants.js.map +1 -1
- package/build/esm/ai/google-genai/decisions.js +25 -0
- package/build/esm/ai/google-genai/decisions.js.map +1 -0
- package/build/esm/ai/google-genai/index.js +35 -11
- package/build/esm/ai/google-genai/index.js.map +1 -1
- package/build/esm/ai/google-genai/streaming.js +6 -2
- package/build/esm/ai/google-genai/streaming.js.map +1 -1
- package/build/esm/ai/langchain/embeddings.js +5 -2
- package/build/esm/ai/langchain/embeddings.js.map +1 -1
- package/build/esm/ai/langchain/index.js +82 -24
- package/build/esm/ai/langchain/index.js.map +1 -1
- package/build/esm/ai/langchain/utils.js +9 -1
- package/build/esm/ai/langchain/utils.js.map +1 -1
- package/build/esm/ai/langgraph/agent-span.js +13 -5
- package/build/esm/ai/langgraph/agent-span.js.map +1 -1
- package/build/esm/ai/langgraph/index.js +13 -15
- package/build/esm/ai/langgraph/index.js.map +1 -1
- package/build/esm/ai/langgraph/stream.js +4 -3
- package/build/esm/ai/langgraph/stream.js.map +1 -1
- package/build/esm/ai/langgraph/utils.js +17 -8
- package/build/esm/ai/langgraph/utils.js.map +1 -1
- package/build/esm/ai/mastra/classifier-evaluation.js.map +1 -1
- package/build/esm/ai/mastra/index.js +33 -16
- package/build/esm/ai/mastra/index.js.map +1 -1
- package/build/esm/ai/mastra/utils.js +3 -5
- package/build/esm/ai/mastra/utils.js.map +1 -1
- package/build/esm/ai/mistral/index.js +28 -13
- package/build/esm/ai/mistral/index.js.map +1 -1
- package/build/esm/ai/mistral/streaming.js +6 -8
- package/build/esm/ai/mistral/streaming.js.map +1 -1
- package/build/esm/ai/mistral/utils.js +9 -1
- package/build/esm/ai/mistral/utils.js.map +1 -1
- package/build/esm/ai/openai/index.js +19 -8
- package/build/esm/ai/openai/index.js.map +1 -1
- package/build/esm/ai/openai/streaming.js +7 -2
- package/build/esm/ai/openai/streaming.js.map +1 -1
- package/build/esm/ai/pi-ai/chat.js +18 -1
- package/build/esm/ai/pi-ai/chat.js.map +1 -1
- package/build/esm/ai/pi-ai/recording.js +34 -15
- package/build/esm/ai/pi-ai/recording.js.map +1 -1
- package/build/esm/ai/pi-durable/index.js +7 -2
- package/build/esm/ai/pi-durable/index.js.map +1 -1
- package/build/esm/ai/pi-durable/runs.js.map +1 -1
- package/build/esm/ai/pi-durable/tools.js +18 -3
- package/build/esm/ai/pi-durable/tools.js.map +1 -1
- package/build/esm/ai/typesafe/index.js +14 -6
- package/build/esm/ai/typesafe/index.js.map +1 -1
- package/build/esm/ai/vercel-ai/index.js +3 -1
- package/build/esm/ai/vercel-ai/index.js.map +1 -1
- package/build/esm/ai/workers-ai/index.js +32 -14
- package/build/esm/ai/workers-ai/index.js.map +1 -1
- package/build/esm/ai/workers-ai/streaming.js +8 -10
- package/build/esm/ai/workers-ai/streaming.js.map +1 -1
- package/build/esm/cron/common.js +16 -0
- package/build/esm/cron/common.js.map +1 -0
- package/build/esm/cron/cron.js +82 -0
- package/build/esm/cron/cron.js.map +1 -0
- package/build/esm/cron/index.js +13 -0
- package/build/esm/cron/index.js.map +1 -0
- package/build/esm/cron/node-cron.js +66 -0
- package/build/esm/cron/node-cron.js.map +1 -0
- package/build/esm/cron/node-schedule.js +43 -0
- package/build/esm/cron/node-schedule.js.map +1 -0
- package/build/esm/index.js +6 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/anthropic.js +25 -16
- package/build/esm/integrations/anthropic.js.map +1 -1
- package/build/esm/integrations/aws-sdk/index.js +1 -0
- package/build/esm/integrations/aws-sdk/index.js.map +1 -1
- package/build/esm/integrations/aws-sdk/services/ServicesExtensions.js +3 -0
- package/build/esm/integrations/aws-sdk/services/ServicesExtensions.js.map +1 -1
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js +45 -12
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js.map +1 -1
- package/build/esm/integrations/bullmq/contextManager.js +45 -0
- package/build/esm/integrations/bullmq/contextManager.js.map +1 -0
- package/build/esm/integrations/bullmq/index.js +44 -0
- package/build/esm/integrations/bullmq/index.js.map +1 -0
- package/build/esm/integrations/bullmq/meter.js +86 -0
- package/build/esm/integrations/bullmq/meter.js.map +1 -0
- package/build/esm/integrations/bullmq/span.js +114 -0
- package/build/esm/integrations/bullmq/span.js.map +1 -0
- package/build/esm/integrations/bullmq/tracer.js +62 -0
- package/build/esm/integrations/bullmq/tracer.js.map +1 -0
- package/build/esm/integrations/cron.js +2 -2
- package/build/esm/integrations/cron.js.map +1 -1
- package/build/esm/integrations/express/instrumentation.js +10 -1
- package/build/esm/integrations/express/instrumentation.js.map +1 -1
- package/build/esm/integrations/google-genai.js +26 -14
- package/build/esm/integrations/google-genai.js.map +1 -1
- package/build/esm/integrations/langgraph.js +5 -7
- package/build/esm/integrations/langgraph.js.map +1 -1
- package/build/esm/integrations/mastra-classifier.js +1 -1
- package/build/esm/integrations/mastra-classifier.js.map +1 -1
- package/build/esm/integrations/mistral.js +15 -5
- package/build/esm/integrations/mistral.js.map +1 -1
- package/build/esm/integrations/node-cron.js +5 -4
- package/build/esm/integrations/node-cron.js.map +1 -1
- package/build/esm/integrations/node-schedule.js +2 -2
- package/build/esm/integrations/node-schedule.js.map +1 -1
- package/build/esm/integrations/openai-compatible.js +16 -8
- package/build/esm/integrations/openai-compatible.js.map +1 -1
- package/build/esm/integrations/openai.js +16 -8
- package/build/esm/integrations/openai.js.map +1 -1
- package/build/esm/integrations/pi-ai.js +39 -18
- package/build/esm/integrations/pi-ai.js.map +1 -1
- package/build/esm/integrations/pino.js +131 -0
- package/build/esm/integrations/pino.js.map +1 -0
- package/build/esm/integrations/typesafe.js +17 -3
- package/build/esm/integrations/typesafe.js.map +1 -1
- package/build/esm/integrations/vercel-ai/index.js.map +1 -1
- package/build/esm/integrations/vercel-ai/util.js +3 -2
- package/build/esm/integrations/vercel-ai/util.js.map +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +53 -18
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +22 -16
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js.map +1 -1
- package/build/esm/integrations/winston.js +90 -0
- package/build/esm/integrations/winston.js.map +1 -0
- package/build/esm/orchestrion/bundler/moduleInjectedTransform.js +6 -5
- package/build/esm/orchestrion/bundler/moduleInjectedTransform.js.map +1 -1
- package/build/esm/orchestrion/bundler/rollup.js +4 -4
- package/build/esm/orchestrion/bundler/rollup.js.map +1 -1
- package/build/esm/orchestrion/config/google-genai.js +19 -5
- package/build/esm/orchestrion/config/google-genai.js.map +1 -1
- package/build/esm/orchestrion/detect.js +1 -1
- package/build/esm/orchestrion/detect.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/utils/cronMonitoring.js +128 -50
- package/build/esm/utils/cronMonitoring.js.map +1 -1
- package/build/types/ai/anthropic-ai/index.d.ts +1 -5
- package/build/types/ai/anthropic-ai/index.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/streaming.d.ts +3 -2
- package/build/types/ai/anthropic-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/tool-runner.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/types.d.ts +24 -3
- package/build/types/ai/anthropic-ai/types.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/utils.d.ts +2 -3
- package/build/types/ai/anthropic-ai/utils.d.ts.map +1 -1
- package/build/types/ai/core/span-hooks.d.ts +31 -0
- package/build/types/ai/core/span-hooks.d.ts.map +1 -0
- package/build/types/ai/core/time-to-first-chunk.d.ts +7 -0
- package/build/types/ai/core/time-to-first-chunk.d.ts.map +1 -0
- package/build/types/ai/core/utils.d.ts +30 -1
- package/build/types/ai/core/utils.d.ts.map +1 -1
- package/build/types/ai/flue/index.d.ts +13 -5
- package/build/types/ai/flue/index.d.ts.map +1 -1
- package/build/types/ai/flue/types.d.ts +20 -2
- package/build/types/ai/flue/types.d.ts.map +1 -1
- package/build/types/ai/flue/utils.d.ts +5 -9
- package/build/types/ai/flue/utils.d.ts.map +1 -1
- package/build/types/ai/google-genai/constants.d.ts +3 -0
- package/build/types/ai/google-genai/constants.d.ts.map +1 -1
- package/build/types/ai/google-genai/decisions.d.ts +8 -0
- package/build/types/ai/google-genai/decisions.d.ts.map +1 -0
- package/build/types/ai/google-genai/index.d.ts +3 -1
- package/build/types/ai/google-genai/index.d.ts.map +1 -1
- package/build/types/ai/google-genai/streaming.d.ts +2 -1
- package/build/types/ai/google-genai/streaming.d.ts.map +1 -1
- package/build/types/ai/google-genai/types.d.ts +17 -3
- package/build/types/ai/google-genai/types.d.ts.map +1 -1
- package/build/types/ai/langchain/index.d.ts.map +1 -1
- package/build/types/ai/langchain/types.d.ts +49 -3
- package/build/types/ai/langchain/types.d.ts.map +1 -1
- package/build/types/ai/langchain/utils.d.ts +6 -0
- package/build/types/ai/langchain/utils.d.ts.map +1 -1
- package/build/types/ai/langgraph/agent-span.d.ts +4 -1
- package/build/types/ai/langgraph/agent-span.d.ts.map +1 -1
- package/build/types/ai/langgraph/index.d.ts +1 -1
- package/build/types/ai/langgraph/index.d.ts.map +1 -1
- package/build/types/ai/langgraph/stream.d.ts.map +1 -1
- package/build/types/ai/langgraph/types.d.ts +14 -3
- package/build/types/ai/langgraph/types.d.ts.map +1 -1
- package/build/types/ai/langgraph/utils.d.ts +3 -0
- package/build/types/ai/langgraph/utils.d.ts.map +1 -1
- package/build/types/ai/mastra/classifier-evaluation.d.ts +3 -3
- package/build/types/ai/mastra/classifier-evaluation.d.ts.map +1 -1
- package/build/types/ai/mastra/index.d.ts +17 -3
- package/build/types/ai/mastra/index.d.ts.map +1 -1
- package/build/types/ai/mastra/types.d.ts +2 -0
- package/build/types/ai/mastra/types.d.ts.map +1 -1
- package/build/types/ai/mastra/utils.d.ts.map +1 -1
- package/build/types/ai/mistral/index.d.ts.map +1 -1
- package/build/types/ai/mistral/streaming.d.ts +2 -1
- package/build/types/ai/mistral/streaming.d.ts.map +1 -1
- package/build/types/ai/mistral/types.d.ts +14 -3
- package/build/types/ai/mistral/types.d.ts.map +1 -1
- package/build/types/ai/mistral/utils.d.ts +5 -0
- package/build/types/ai/mistral/utils.d.ts.map +1 -1
- package/build/types/ai/openai/index.d.ts.map +1 -1
- package/build/types/ai/openai/streaming.d.ts +3 -1
- package/build/types/ai/openai/streaming.d.ts.map +1 -1
- package/build/types/ai/openai/types.d.ts +14 -3
- package/build/types/ai/openai/types.d.ts.map +1 -1
- package/build/types/ai/pi-ai/chat.d.ts +7 -1
- package/build/types/ai/pi-ai/chat.d.ts.map +1 -1
- package/build/types/ai/pi-ai/recording.d.ts +21 -9
- package/build/types/ai/pi-ai/recording.d.ts.map +1 -1
- package/build/types/ai/pi-ai/types.d.ts +16 -0
- package/build/types/ai/pi-ai/types.d.ts.map +1 -1
- package/build/types/ai/pi-durable/index.d.ts +12 -3
- package/build/types/ai/pi-durable/index.d.ts.map +1 -1
- package/build/types/ai/pi-durable/runs.d.ts +2 -0
- package/build/types/ai/pi-durable/runs.d.ts.map +1 -1
- package/build/types/ai/pi-durable/tools.d.ts +4 -3
- package/build/types/ai/pi-durable/tools.d.ts.map +1 -1
- package/build/types/ai/pi-durable/types.d.ts +15 -0
- package/build/types/ai/pi-durable/types.d.ts.map +1 -1
- package/build/types/ai/typesafe/index.d.ts +10 -2
- package/build/types/ai/typesafe/index.d.ts.map +1 -1
- package/build/types/ai/vercel-ai/index.d.ts.map +1 -1
- package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts +3 -0
- package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
- package/build/types/ai/workers-ai/index.d.ts.map +1 -1
- package/build/types/ai/workers-ai/streaming.d.ts +2 -1
- package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/workers-ai/types.d.ts +18 -3
- package/build/types/ai/workers-ai/types.d.ts.map +1 -1
- package/build/types/cron/common.d.ts +8 -0
- package/build/types/cron/common.d.ts.map +1 -0
- package/build/types/cron/cron.d.ts +45 -0
- package/build/types/cron/cron.d.ts.map +1 -0
- package/build/types/cron/index.d.ts +10 -0
- package/build/types/cron/index.d.ts.map +1 -0
- package/build/types/cron/node-cron.d.ts +33 -0
- package/build/types/cron/node-cron.d.ts.map +1 -0
- package/build/types/cron/node-schedule.d.ts +19 -0
- package/build/types/cron/node-schedule.d.ts.map +1 -0
- package/build/types/index.d.ts +5 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/anthropic.d.ts +2 -1
- package/build/types/integrations/anthropic.d.ts.map +1 -1
- package/build/types/integrations/aws-sdk/index.d.ts +3 -3
- package/build/types/integrations/aws-sdk/index.d.ts.map +1 -1
- package/build/types/integrations/aws-sdk/services/ServiceExtension.d.ts +1 -0
- package/build/types/integrations/aws-sdk/services/ServiceExtension.d.ts.map +1 -1
- package/build/types/integrations/aws-sdk/services/ServicesExtensions.d.ts +3 -2
- package/build/types/integrations/aws-sdk/services/ServicesExtensions.d.ts.map +1 -1
- package/build/types/integrations/aws-sdk/services/bedrock-runtime.d.ts +25 -4
- package/build/types/integrations/aws-sdk/services/bedrock-runtime.d.ts.map +1 -1
- package/build/types/integrations/bullmq/contextManager.d.ts +13 -0
- package/build/types/integrations/bullmq/contextManager.d.ts.map +1 -0
- package/build/types/integrations/bullmq/index.d.ts +43 -0
- package/build/types/integrations/bullmq/index.d.ts.map +1 -0
- package/build/types/integrations/bullmq/meter.d.ts +7 -0
- package/build/types/integrations/bullmq/meter.d.ts.map +1 -0
- package/build/types/integrations/bullmq/span.d.ts +35 -0
- package/build/types/integrations/bullmq/span.d.ts.map +1 -0
- package/build/types/integrations/bullmq/tracer.d.ts +5 -0
- package/build/types/integrations/bullmq/tracer.d.ts.map +1 -0
- package/build/types/integrations/bullmq/types.d.ts +72 -0
- package/build/types/integrations/bullmq/types.d.ts.map +1 -0
- package/build/types/integrations/cron.d.ts.map +1 -1
- package/build/types/integrations/express/types.d.ts +1 -0
- package/build/types/integrations/express/types.d.ts.map +1 -1
- package/build/types/integrations/flue.d.ts +2 -1
- package/build/types/integrations/flue.d.ts.map +1 -1
- package/build/types/integrations/google-genai.d.ts +5 -4
- package/build/types/integrations/google-genai.d.ts.map +1 -1
- package/build/types/integrations/groq.d.ts +1 -1
- package/build/types/integrations/langchain.d.ts +2 -1
- package/build/types/integrations/langchain.d.ts.map +1 -1
- package/build/types/integrations/langgraph.d.ts +2 -1
- package/build/types/integrations/langgraph.d.ts.map +1 -1
- package/build/types/integrations/mistral.d.ts +2 -1
- package/build/types/integrations/mistral.d.ts.map +1 -1
- package/build/types/integrations/node-cron.d.ts +1 -1
- package/build/types/integrations/node-cron.d.ts.map +1 -1
- package/build/types/integrations/node-schedule.d.ts.map +1 -1
- package/build/types/integrations/openai-compatible.d.ts.map +1 -1
- package/build/types/integrations/openai.d.ts +2 -1
- package/build/types/integrations/openai.d.ts.map +1 -1
- package/build/types/integrations/pi-ai.d.ts +6 -3
- package/build/types/integrations/pi-ai.d.ts.map +1 -1
- package/build/types/integrations/pi-durable.d.ts +2 -1
- package/build/types/integrations/pi-durable.d.ts.map +1 -1
- package/build/types/integrations/pino.d.ts +61 -0
- package/build/types/integrations/pino.d.ts.map +1 -0
- package/build/types/integrations/together-ai.d.ts +1 -1
- package/build/types/integrations/typesafe.d.ts +2 -2
- package/build/types/integrations/typesafe.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/index.d.ts +3 -3
- package/build/types/integrations/vercel-ai/index.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/util.d.ts +2 -1
- package/build/types/integrations/vercel-ai/util.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts +20 -4
- package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.d.ts.map +1 -1
- package/build/types/integrations/winston.d.ts +55 -0
- package/build/types/integrations/winston.d.ts.map +1 -0
- package/build/types/orchestrion/bundler/moduleInjectedTransform.d.ts.map +1 -1
- package/build/types/orchestrion/bundler/rollup.d.ts +3 -3
- package/build/types/orchestrion/bundler/rollup.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/google-genai.d.ts +13 -0
- package/build/types/orchestrion/config/google-genai.d.ts.map +1 -1
- package/build/types/utils/cronMonitoring.d.ts +4 -5
- package/build/types/utils/cronMonitoring.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-schedule.js","names":[],"sources":["../../../src/integrations/node-schedule.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { nodeScheduleModuleNames } from '../orchestrion/config/node-schedule';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport type { AnyFn, ScheduleChange } from '../utils/cronMonitoring';\nimport {\n cronExpressionToMonitorConfig,\n shouldMonitorJob,\n subscribeToScheduleChange,\n updateMonitorConfig,\n wrapScheduledJob,\n} from '../utils/cronMonitoring';\n\nconst INTEGRATION_NAME = 'NodeSchedule' as const;\n\nexport interface NodeScheduleIntegrationOptions {\n /** Job names not to monitor. Strings must match the name exactly. */\n excludeJobs?: Array<string | RegExp>;\n}\n\nconst _nodeScheduleIntegration = ((options: NodeScheduleIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, nodeScheduleModuleNames, subscribe, [options], {\n requiresTracingChannelBinding: false,\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends Crons check-ins for every named `node-schedule` job, whether it's created with `scheduleJob` or `new Job()`.\n * The monitor slug is the job name. Jobs without a name, one-off jobs, and jobs with a schedule Crons can't express\n * are not monitored.\n */\nexport const nodeScheduleIntegration = defineIntegration(_nodeScheduleIntegration);\n\nfunction subscribe(options: NodeScheduleIntegrationOptions): void {\n subscribeToScheduleChange(CHANNELS.NODE_SCHEDULE_SCHEDULE, INTEGRATION_NAME, onSchedule, change =>\n beforeSchedule(change, options),\n );\n}\n\ninterface Job {\n name?: unknown;\n job?: unknown;\n nextInvocation?: () => unknown;\n}\n\n// The name node-schedule gives jobs created without one.\nconst ANONYMOUS_NAME = /^<Anonymous Job \\d+[ >]/;\n\n// `job.schedule(spec)` calls that add to runs the job already has pending, rather than replace them.\nconst addsToPendingRuns = new WeakSet<ScheduleChange>();\n\n/** Wraps a named job's method before `job.schedule(spec)` with a recurring spec, unless it's already wrapped. */\nexport function beforeSchedule(change: ScheduleChange, options: NodeScheduleIntegrationOptions): void {\n const job = change.self as Job | undefined;\n if (!job) {\n return;\n }\n if (typeof job.nextInvocation === 'function' && job.nextInvocation() != null) {\n addsToPendingRuns.add(change);\n }\n const name = typeof job.name === 'string' && !ANONYMOUS_NAME.test(job.name) ? job.name : undefined;\n if (isOneOffSpec(change.arguments[0]) || !shouldMonitorJob(name, job.job, options.excludeJobs)) {\n return;\n }\n job.job = wrapScheduledJob(job.job as AnyFn, name, undefined, 'auto.function.node-schedule');\n}\n\n/**\n * Sets the spec's config after `job.schedule(spec)`. Without one, from a spec Crons can't express or a job that also\n * keeps runs from an earlier spec, the job doesn't check in.\n */\nexport function onSchedule(change: ScheduleChange): void {\n // `schedule` returns false when it scheduled nothing, and `reschedule` then keeps the old schedule.\n if (change.result === true) {\n const job = change.self as Job | undefined;\n updateMonitorConfig(job?.job, addsToPendingRuns.has(change) ? undefined : getMonitorConfig(change.arguments[0]));\n }\n}\n\n/** Whether node-schedule runs a job with this spec once: a `Date`, a timestamp, or a date string. */\nexport function isOneOffSpec(spec: unknown): boolean {\n const { rule } = (spec || {}) as { rule?: unknown };\n const when = typeof spec === 'object' && rule ? rule : spec;\n if (typeof when === 'string') {\n // `Date.parse` also accepts some crons, like `0 9 * * *`.\n return !isCronShaped(when) && !Number.isNaN(Date.parse(when));\n }\n return when instanceof Date || typeof when === 'number';\n}\n\nfunction isCronShaped(value: string): boolean {\n const fields = value.trim().split(/\\s+/);\n return (\n /^@[a-z]+$/i.test(value.trim()) ||\n ((fields.length === 5 || fields.length === 6) && fields.every(field => /^[\\d*,/?#a-z-]+$/i.test(field)))\n );\n}\n\n// Only cron strings convert; recurrence rules and rules limited by `start` or `end` don't.\nexport function getMonitorConfig(spec: unknown): MonitorConfig | undefined {\n if (typeof spec === 'string') {\n return cronExpressionToMonitorConfig(spec, undefined, '
|
|
1
|
+
{"version":3,"file":"node-schedule.js","names":[],"sources":["../../../src/integrations/node-schedule.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { nodeScheduleModuleNames } from '../orchestrion/config/node-schedule';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport type { AnyFn, ScheduleChange } from '../utils/cronMonitoring';\nimport {\n cronExpressionToMonitorConfig,\n shouldMonitorJob,\n subscribeToScheduleChange,\n updateMonitorConfig,\n wrapScheduledJob,\n} from '../utils/cronMonitoring';\n\nconst INTEGRATION_NAME = 'NodeSchedule' as const;\n\nexport interface NodeScheduleIntegrationOptions {\n /** Job names not to monitor. Strings must match the name exactly. */\n excludeJobs?: Array<string | RegExp>;\n}\n\nconst _nodeScheduleIntegration = ((options: NodeScheduleIntegrationOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, nodeScheduleModuleNames, subscribe, [options], {\n requiresTracingChannelBinding: false,\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends Crons check-ins for every named `node-schedule` job, whether it's created with `scheduleJob` or `new Job()`.\n * The monitor slug is the job name. Jobs without a name, one-off jobs, and jobs with a schedule Crons can't express\n * are not monitored.\n */\nexport const nodeScheduleIntegration = defineIntegration(_nodeScheduleIntegration);\n\nfunction subscribe(options: NodeScheduleIntegrationOptions): void {\n subscribeToScheduleChange(CHANNELS.NODE_SCHEDULE_SCHEDULE, INTEGRATION_NAME, onSchedule, change =>\n beforeSchedule(change, options),\n );\n}\n\ninterface Job {\n name?: unknown;\n job?: unknown;\n nextInvocation?: () => unknown;\n}\n\n// The name node-schedule gives jobs created without one.\nconst ANONYMOUS_NAME = /^<Anonymous Job \\d+[ >]/;\n\n// `job.schedule(spec)` calls that add to runs the job already has pending, rather than replace them.\nconst addsToPendingRuns = new WeakSet<ScheduleChange>();\n\n/** Wraps a named job's method before `job.schedule(spec)` with a recurring spec, unless it's already wrapped. */\nexport function beforeSchedule(change: ScheduleChange, options: NodeScheduleIntegrationOptions): void {\n const job = change.self as Job | undefined;\n if (!job) {\n return;\n }\n if (typeof job.nextInvocation === 'function' && job.nextInvocation() != null) {\n addsToPendingRuns.add(change);\n }\n const name = typeof job.name === 'string' && !ANONYMOUS_NAME.test(job.name) ? job.name : undefined;\n if (isOneOffSpec(change.arguments[0]) || !shouldMonitorJob(name, job.job, options.excludeJobs)) {\n return;\n }\n job.job = wrapScheduledJob(job.job as AnyFn, name, undefined, 'auto.function.node-schedule');\n}\n\n/**\n * Sets the spec's config after `job.schedule(spec)`. Without one, from a spec Crons can't express or a job that also\n * keeps runs from an earlier spec, the job doesn't check in.\n */\nexport function onSchedule(change: ScheduleChange): void {\n // `schedule` returns false when it scheduled nothing, and `reschedule` then keeps the old schedule.\n if (change.result === true) {\n const job = change.self as Job | undefined;\n updateMonitorConfig(job?.job, addsToPendingRuns.has(change) ? undefined : getMonitorConfig(change.arguments[0]));\n }\n}\n\n/** Whether node-schedule runs a job with this spec once: a `Date`, a timestamp, or a date string. */\nexport function isOneOffSpec(spec: unknown): boolean {\n const { rule } = (spec || {}) as { rule?: unknown };\n const when = typeof spec === 'object' && rule ? rule : spec;\n if (typeof when === 'string') {\n // `Date.parse` also accepts some crons, like `0 9 * * *`.\n return !isCronShaped(when) && !Number.isNaN(Date.parse(when));\n }\n return when instanceof Date || typeof when === 'number';\n}\n\nfunction isCronShaped(value: string): boolean {\n const fields = value.trim().split(/\\s+/);\n return (\n /^@[a-z]+$/i.test(value.trim()) ||\n ((fields.length === 5 || fields.length === 6) && fields.every(field => /^[\\d*,/?#a-z-]+$/i.test(field)))\n );\n}\n\n// Only cron strings convert; recurrence rules and rules limited by `start` or `end` don't.\nexport function getMonitorConfig(spec: unknown): MonitorConfig | undefined {\n if (typeof spec === 'string') {\n return cronExpressionToMonitorConfig(spec, undefined, 'cron-parser');\n }\n const { rule, tz, start, end } = (spec || {}) as { rule?: unknown; tz?: unknown; start?: unknown; end?: unknown };\n return typeof rule === 'string' && !start && !end\n ? cronExpressionToMonitorConfig(rule, tz, 'cron-parser')\n : undefined;\n}\n"],"mappings":";;;;;;AAcA,MAAM,mBAAmB;AAOzB,MAAM,6BAA6B,UAA0C,CAAC,MAAM;CAClF,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,yBAAyB,WAAW,CAAC,OAAO,GAAG,EACtF,+BAA+B,MACjC,CAAC;EACH;CACF;AACF;;;;;;AAOA,MAAa,0BAA0B,kBAAkB,wBAAwB;AAEjF,SAAS,UAAU,SAA+C;CAChE,0BAA0B,SAAS,wBAAwB,kBAAkB,aAAY,WACvF,eAAe,QAAQ,OAAO,CAChC;AACF;AASA,MAAM,iBAAiB;AAGvB,MAAM,oCAAoB,IAAI,QAAwB;;AAGtD,SAAgB,eAAe,QAAwB,SAA+C;CACpG,MAAM,MAAM,OAAO;CACnB,IAAI,CAAC,KACH;CAEF,IAAI,OAAO,IAAI,mBAAmB,cAAc,IAAI,eAAe,KAAK,MACtE,kBAAkB,IAAI,MAAM;CAE9B,MAAM,OAAO,OAAO,IAAI,SAAS,YAAY,CAAC,eAAe,KAAK,IAAI,IAAI,IAAI,IAAI,OAAO,KAAA;CACzF,IAAI,aAAa,OAAO,UAAU,EAAE,KAAK,CAAC,iBAAiB,MAAM,IAAI,KAAK,QAAQ,WAAW,GAC3F;CAEF,IAAI,MAAM,iBAAiB,IAAI,KAAc,MAAM,KAAA,GAAW,6BAA6B;AAC7F;;;;;AAMA,SAAgB,WAAW,QAA8B;CAEvD,IAAI,OAAO,WAAW,MAAM;EAC1B,MAAM,MAAM,OAAO;EACnB,oBAAoB,KAAK,KAAK,kBAAkB,IAAI,MAAM,IAAI,KAAA,IAAY,iBAAiB,OAAO,UAAU,EAAE,CAAC;CACjH;AACF;;AAGA,SAAgB,aAAa,MAAwB;CACnD,MAAM,EAAE,SAAU,QAAQ,CAAC;CAC3B,MAAM,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO;CACvD,IAAI,OAAO,SAAS,UAElB,OAAO,CAAC,aAAa,IAAI,KAAK,CAAC,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC;CAE9D,OAAO,gBAAgB,QAAQ,OAAO,SAAS;AACjD;AAEA,SAAS,aAAa,OAAwB;CAC5C,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,MAAM,KAAK;CACvC,OACE,aAAa,KAAK,MAAM,KAAK,CAAC,MAC5B,OAAO,WAAW,KAAK,OAAO,WAAW,MAAM,OAAO,OAAM,UAAS,oBAAoB,KAAK,KAAK,CAAC;AAE1G;AAGA,SAAgB,iBAAiB,MAA0C;CACzE,IAAI,OAAO,SAAS,UAClB,OAAO,8BAA8B,MAAM,KAAA,GAAW,aAAa;CAErE,MAAM,EAAE,MAAM,IAAI,OAAO,QAAS,QAAQ,CAAC;CAC3C,OAAO,OAAO,SAAS,YAAY,CAAC,SAAS,CAAC,MAC1C,8BAA8B,MAAM,IAAI,aAAa,IACrD,KAAA;AACN"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
-
import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted,
|
|
2
|
+
import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from "../ai/core/utils.js";
|
|
3
3
|
import { wrapApiPromiseResponse } from "../ai/core/apiPromise.js";
|
|
4
|
+
import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
|
|
4
5
|
import { addRequestAttributes, extractRequestAttributes } from "../ai/openai/index.js";
|
|
5
6
|
import { instrumentStream } from "../ai/openai/streaming.js";
|
|
6
7
|
import { addResponseAttributes } from "../ai/openai/utils.js";
|
|
@@ -28,12 +29,13 @@ function createOpenAiCompatibleIntegration(provider) {
|
|
|
28
29
|
for (const { channel, operation } of instrumentedChannels) bindTracingChannelToSpan(tracingChannel(channel), (data) => createGenAiSpan(data, operation, provider, options), {
|
|
29
30
|
beforeSpanEnd: (span, data) => {
|
|
30
31
|
if ("error" in data) markCancelledIfAborted(span, getRequestSignal(data.arguments?.[1]));
|
|
31
|
-
addResponseAttributes(span, data.result,
|
|
32
|
+
addResponseAttributes(span, data.result, !!data._sentryRecordOutputs);
|
|
33
|
+
data._sentryOnSpanEnd?.("error" in data ? { error: data.error } : { response: data.result });
|
|
32
34
|
},
|
|
33
35
|
deferSpanEnd: ({ span, data, end }) => wrapApiPromiseResponse(data.result, (response) => {
|
|
34
36
|
data.result = response;
|
|
35
|
-
if (!wrapStreamResult(span, data
|
|
36
|
-
}, end) || wrapStreamResult(span, data
|
|
37
|
+
if (!wrapStreamResult(span, data)) end();
|
|
38
|
+
}, end) || wrapStreamResult(span, data)
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
return ((options = {}) => {
|
|
@@ -53,7 +55,12 @@ function createGenAiSpan(data, operation, provider, options) {
|
|
|
53
55
|
if (_INTERNAL_shouldSkipAiProviderWrapping(provider.integrationName)) return;
|
|
54
56
|
const args = data.arguments ?? [];
|
|
55
57
|
const params = args[0];
|
|
56
|
-
const
|
|
58
|
+
const call = {
|
|
59
|
+
operation,
|
|
60
|
+
request: params
|
|
61
|
+
};
|
|
62
|
+
const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);
|
|
63
|
+
data._sentryRecordOutputs = recordOutputs;
|
|
57
64
|
const attributes = extractRequestAttributes(args, operation, recordInputs);
|
|
58
65
|
attributes[GEN_AI_PROVIDER_NAME] = provider.providerName;
|
|
59
66
|
attributes[SENTRY_ORIGIN] = provider.origin;
|
|
@@ -65,6 +72,8 @@ function createGenAiSpan(data, operation, provider, options) {
|
|
|
65
72
|
attributes
|
|
66
73
|
});
|
|
67
74
|
if (recordInputs && params) addRequestAttributes(span, params, operation);
|
|
75
|
+
runGenAiSpanStart(options, span, call);
|
|
76
|
+
data._sentryOnSpanEnd = (result) => runGenAiSpanEnd(options, span, call, result);
|
|
68
77
|
return span;
|
|
69
78
|
}
|
|
70
79
|
function isAsyncIterable(value) {
|
|
@@ -79,12 +88,11 @@ function isAsyncIterable(value) {
|
|
|
79
88
|
* to hand span-ending ownership to `instrumentStream`; `false` for non-streaming/errored results, which end
|
|
80
89
|
* via the normal `beforeSpanEnd` path.
|
|
81
90
|
*/
|
|
82
|
-
function wrapStreamResult(span, data
|
|
91
|
+
function wrapStreamResult(span, data) {
|
|
83
92
|
const result = data.result;
|
|
84
93
|
if (!isAsyncIterable(result)) return false;
|
|
85
|
-
const { recordOutputs } = resolveAIRecordingOptions(options);
|
|
86
94
|
const iterate = result[Symbol.asyncIterator].bind(result);
|
|
87
|
-
const instrumented = instrumentStream({ [Symbol.asyncIterator]: iterate }, span,
|
|
95
|
+
const instrumented = instrumentStream({ [Symbol.asyncIterator]: iterate }, span, !!data._sentryRecordOutputs, data._sentryOnSpanEnd);
|
|
88
96
|
result[Symbol.asyncIterator] = () => instrumented;
|
|
89
97
|
return true;
|
|
90
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-compatible.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/openai-compatible.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { Integration, IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n hasSpanStreamingEnabled,\n startInactiveSpan,\n} from '@sentry/core';\nimport { GEN_AI_PROVIDER_NAME, SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted,
|
|
1
|
+
{"version":3,"file":"openai-compatible.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/openai-compatible.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { Integration, IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n getClient,\n hasSpanStreamingEnabled,\n startInactiveSpan,\n} from '@sentry/core';\nimport { GEN_AI_PROVIDER_NAME, SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from '../ai/core/utils';\nimport { wrapApiPromiseResponse } from '../ai/core/apiPromise';\nimport { type GenAiSpanResult, runGenAiSpanEnd, runGenAiSpanStart } from '../ai/core/span-hooks';\nimport { addRequestAttributes, extractRequestAttributes } from '../ai/openai';\nimport { instrumentStream } from '../ai/openai/streaming';\nimport type { OpenAiCallInfo, OpenAiOptions } from '../ai/openai/types';\nimport { addResponseAttributes } from '../ai/openai/utils';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\n\n// The recording decision is made once, when the span starts, in the caller's async context.\ntype OpenAiChannelContext = OrchestrionChannelContext & {\n _sentryRecordOutputs?: boolean;\n _sentryOnSpanEnd?: (result: GenAiSpanResult<unknown>) => void;\n};\n\n/**\n * Describes an OpenAI-compatible provider whose SDK mirrors the openai wire format (Groq, Together, ...),\n * so the span building, streaming and response parsing can all be reused from `ai/openai`.\n */\nexport interface OpenAiCompatibleProvider {\n /** Integration name; also the key used to skip double-wrapping when another provider drives the SDK. */\n integrationName: string;\n /** Value reported on `gen_ai.provider.name`. */\n providerName: string;\n /** Span origin, `auto.ai.<provider>`. */\n origin: string;\n /** The instrumented `module.name`s (from the orchestrion config's `getModuleNames`). */\n moduleNames: string[];\n /** The fully-qualified orchestrion channels this provider publishes to. */\n channels: { chat: string; embeddings: string };\n}\n\n/**\n * Builds a diagnostics-channel integration for an OpenAI-compatible provider SDK. It subscribes to the\n * `orchestrion:<module>:{chat,embeddings}` channels injected into the SDK's `create` methods, so it\n * requires the Sentry runtime hook or bundler plugin. Everything below the channel — request/response\n * attributes and streaming — is shared with the openai integration; only the provider name and origin\n * differ.\n */\nexport function createOpenAiCompatibleIntegration<T extends OpenAiCompatibleProvider>(\n provider: T,\n): (options?: OpenAiOptions) => Integration & { name: T['integrationName'] } {\n const instrumentedChannels = [\n { channel: provider.channels.chat, operation: 'chat' },\n { channel: provider.channels.embeddings, operation: 'embeddings' },\n ] as const;\n\n function instrument(options: OpenAiOptions): void {\n for (const { channel, operation } of instrumentedChannels) {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<OpenAiChannelContext>(channel),\n data => createGenAiSpan(data, operation, provider, options),\n {\n beforeSpanEnd: (span, data) => {\n if ('error' in data) {\n markCancelledIfAborted(span, getRequestSignal(data.arguments?.[1]));\n }\n addResponseAttributes(span, data.result, !!data._sentryRecordOutputs);\n data._sentryOnSpanEnd?.('error' in data ? { error: data.error } : { response: data.result });\n },\n deferSpanEnd: ({ span, data, end }) =>\n wrapApiPromiseResponse(\n data.result,\n response => {\n data.result = response;\n if (!wrapStreamResult(span, data)) {\n end();\n }\n },\n end,\n ) || wrapStreamResult(span, data),\n },\n );\n }\n }\n\n return ((options: OpenAiOptions = {}) => {\n return {\n name: provider.integrationName,\n setup(client) {\n invokeOrchestrionInstrumentation(client, provider.moduleNames, instrument, [options]);\n },\n };\n }) satisfies IntegrationFn;\n}\n\n/**\n * Build the span for an instrumented `create` call.\n * Returning `undefined` opts the payload out so no span is opened.\n */\nfunction createGenAiSpan(\n data: OpenAiChannelContext,\n operation: string,\n provider: OpenAiCompatibleProvider,\n options: OpenAiOptions,\n): Span | undefined {\n // When another provider (e.g. LangChain) is driving the SDK, it records the spans itself and marks this\n // provider as skipped; skip here to avoid double spans.\n if (_INTERNAL_shouldSkipAiProviderWrapping(provider.integrationName)) {\n return undefined;\n }\n\n const args = data.arguments ?? [];\n const params = args[0] as Record<string, unknown> | undefined;\n\n const call: OpenAiCallInfo = { operation, request: params };\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n data._sentryRecordOutputs = recordOutputs;\n\n // `extractRequestAttributes` defaults the provider to openai; override it for the concrete provider.\n const attributes = extractRequestAttributes(args, operation, recordInputs);\n attributes[GEN_AI_PROVIDER_NAME] = provider.providerName;\n attributes[SENTRY_ORIGIN] = provider.origin;\n const model = (params?.model as string) || 'unknown';\n const client = getClient();\n\n const span = startInactiveSpan({\n // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality.\n name: model !== 'unknown' || !(client && hasSpanStreamingEnabled(client)) ? `${operation} ${model}` : operation,\n op: getGenAiSpanOp(operation),\n attributes: attributes as Record<string, SpanAttributeValue>,\n });\n\n if (recordInputs && params) {\n addRequestAttributes(span, params, operation);\n }\n\n runGenAiSpanStart(options, span, call);\n data._sentryOnSpanEnd = result => runGenAiSpanEnd(options, span, call, result);\n\n return span;\n}\n\ntype AsyncIterableStream = { [Symbol.asyncIterator]: () => AsyncIterator<unknown> };\n\nfunction isAsyncIterable(value: unknown): value is AsyncIterableStream {\n return !!value && typeof (value as AsyncIterableStream)[Symbol.asyncIterator] === 'function';\n}\n\n/**\n * For a streaming `create({ stream: true })` the result is a `Stream` the caller consumes later. We can't\n * swap what `create` returns, but the `Stream` in `data.result` is the same instance the caller holds and\n * we observe it before the caller iterates — so we patch its async iterator in place to run through\n * `instrumentStream`, which accumulates the streamed attributes and ends the span when iteration finishes.\n * Only a streaming call resolves to an async-iterable, so that check alone distinguishes it. Returns `true`\n * to hand span-ending ownership to `instrumentStream`; `false` for non-streaming/errored results, which end\n * via the normal `beforeSpanEnd` path.\n */\nfunction wrapStreamResult(span: Span, data: OpenAiChannelContext): boolean {\n const result = data.result;\n if (!isAsyncIterable(result)) {\n return false;\n }\n\n const iterate = result[Symbol.asyncIterator].bind(result);\n const instrumented = instrumentStream(\n { [Symbol.asyncIterator]: iterate },\n span,\n !!data._sentryRecordOutputs,\n data._sentryOnSpanEnd,\n );\n result[Symbol.asyncIterator] = () => instrumented;\n\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,kCACd,UAC2E;CAC3E,MAAM,uBAAuB,CAC3B;EAAE,SAAS,SAAS,SAAS;EAAM,WAAW;CAAO,GACrD;EAAE,SAAS,SAAS,SAAS;EAAY,WAAW;CAAa,CACnE;CAEA,SAAS,WAAW,SAA8B;EAChD,KAAK,MAAM,EAAE,SAAS,eAAe,sBACnC,yBACEA,eAAwD,OAAO,IAC/D,SAAQ,gBAAgB,MAAM,WAAW,UAAU,OAAO,GAC1D;GACE,gBAAgB,MAAM,SAAS;IAC7B,IAAI,WAAW,MACb,uBAAuB,MAAM,iBAAiB,KAAK,YAAY,EAAE,CAAC;IAEpE,sBAAsB,MAAM,KAAK,QAAQ,CAAC,CAAC,KAAK,oBAAoB;IACpE,KAAK,mBAAmB,WAAW,OAAO,EAAE,OAAO,KAAK,MAAM,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;GAC7F;GACA,eAAe,EAAE,MAAM,MAAM,UAC3B,uBACE,KAAK,SACL,aAAY;IACV,KAAK,SAAS;IACd,IAAI,CAAC,iBAAiB,MAAM,IAAI,GAC9B,IAAI;GAER,GACA,GACF,KAAK,iBAAiB,MAAM,IAAI;EACpC,CACF;CAEJ;CAEA,SAAS,UAAyB,CAAC,MAAM;EACvC,OAAO;GACL,MAAM,SAAS;GACf,MAAM,QAAQ;IACZ,iCAAiC,QAAQ,SAAS,aAAa,YAAY,CAAC,OAAO,CAAC;GACtF;EACF;CACF;AACF;;;;;AAMA,SAAS,gBACP,MACA,WACA,UACA,SACkB;CAGlB,IAAI,uCAAuC,SAAS,eAAe,GACjE;CAGF,MAAM,OAAO,KAAK,aAAa,CAAC;CAChC,MAAM,SAAS,KAAK;CAEpB,MAAM,OAAuB;EAAE;EAAW,SAAS;CAAO;CAC1D,MAAM,EAAE,cAAc,kBAAkB,0BAA0B,SAAS,IAAI;CAC/E,KAAK,uBAAuB;CAG5B,MAAM,aAAa,yBAAyB,MAAM,WAAW,YAAY;CACzE,WAAW,wBAAwB,SAAS;CAC5C,WAAW,iBAAiB,SAAS;CACrC,MAAM,QAAS,QAAQ,SAAoB;CAC3C,MAAM,SAAS,UAAU;CAEzB,MAAM,OAAO,kBAAkB;EAE7B,MAAM,UAAU,aAAa,EAAE,UAAU,wBAAwB,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU;EACtG,IAAI,eAAe,SAAS;EAChB;CACd,CAAC;CAED,IAAI,gBAAgB,QAClB,qBAAqB,MAAM,QAAQ,SAAS;CAG9C,kBAAkB,SAAS,MAAM,IAAI;CACrC,KAAK,oBAAmB,WAAU,gBAAgB,SAAS,MAAM,MAAM,MAAM;CAE7E,OAAO;AACT;AAIA,SAAS,gBAAgB,OAA8C;CACrE,OAAO,CAAC,CAAC,SAAS,OAAQ,MAA8B,OAAO,mBAAmB;AACpF;;;;;;;;;;AAWA,SAAS,iBAAiB,MAAY,MAAqC;CACzE,MAAM,SAAS,KAAK;CACpB,IAAI,CAAC,gBAAgB,MAAM,GACzB,OAAO;CAGT,MAAM,UAAU,OAAO,OAAO,cAAc,CAAC,KAAK,MAAM;CACxD,MAAM,eAAe,iBACnB,GAAG,OAAO,gBAAgB,QAAQ,GAClC,MACA,CAAC,CAAC,KAAK,sBACP,KAAK,gBACP;CACA,OAAO,OAAO,uBAAuB;CAErC,OAAO;AACT"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
-
import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted,
|
|
2
|
+
import { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from "../ai/core/utils.js";
|
|
3
3
|
import { addRequestAttributes, extractRequestAttributes } from "../ai/openai/index.js";
|
|
4
4
|
import { wrapApiPromiseResponse } from "../ai/core/apiPromise.js";
|
|
5
|
+
import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
|
|
5
6
|
import { instrumentStream } from "../ai/openai/streaming.js";
|
|
6
7
|
import { addResponseAttributes } from "../ai/openai/utils.js";
|
|
7
8
|
import { shouldSkipAiProviderSpan } from "../ai/pi-ai/providers.js";
|
|
@@ -40,12 +41,13 @@ function instrumentOpenai(options) {
|
|
|
40
41
|
for (const { channel, operation } of INSTRUMENTED_CHANNELS) bindTracingChannelToSpan(tracingChannel(channel), (data) => createGenAiSpan(data, operation, options), {
|
|
41
42
|
beforeSpanEnd: (span, data) => {
|
|
42
43
|
if ("error" in data) markCancelledIfAborted(span, getRequestSignal(data.arguments?.[1]));
|
|
43
|
-
addResponseAttributes(span, data.result,
|
|
44
|
+
addResponseAttributes(span, data.result, !!data._sentryRecordOutputs, operation);
|
|
45
|
+
data._sentryOnSpanEnd?.("error" in data ? { error: data.error } : { response: data.result });
|
|
44
46
|
},
|
|
45
47
|
deferSpanEnd: ({ span, data, end }) => wrapApiPromiseResponse(data.result, (response) => {
|
|
46
48
|
data.result = response;
|
|
47
|
-
if (!wrapStreamResult(span, data
|
|
48
|
-
}, end) || wrapStreamResult(span, data
|
|
49
|
+
if (!wrapStreamResult(span, data)) end();
|
|
50
|
+
}, end) || wrapStreamResult(span, data)
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
@@ -56,7 +58,12 @@ function createGenAiSpan(data, operation, options) {
|
|
|
56
58
|
if (shouldSkipAiProviderSpan(INTEGRATION_NAME)) return;
|
|
57
59
|
const args = data.arguments ?? [];
|
|
58
60
|
const params = args[0];
|
|
59
|
-
const
|
|
61
|
+
const call = {
|
|
62
|
+
operation,
|
|
63
|
+
request: params
|
|
64
|
+
};
|
|
65
|
+
const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);
|
|
66
|
+
data._sentryRecordOutputs = recordOutputs;
|
|
60
67
|
const attributes = extractRequestAttributes(args, operation, recordInputs);
|
|
61
68
|
attributes[SENTRY_ORIGIN] = ORIGIN;
|
|
62
69
|
const model = params?.model || "unknown";
|
|
@@ -67,6 +74,8 @@ function createGenAiSpan(data, operation, options) {
|
|
|
67
74
|
attributes
|
|
68
75
|
});
|
|
69
76
|
if (recordInputs && params) addRequestAttributes(span, params, operation);
|
|
77
|
+
runGenAiSpanStart(options, span, call);
|
|
78
|
+
data._sentryOnSpanEnd = (result) => runGenAiSpanEnd(options, span, call, result);
|
|
70
79
|
return span;
|
|
71
80
|
}
|
|
72
81
|
function isAsyncIterable(value) {
|
|
@@ -81,12 +90,11 @@ function isAsyncIterable(value) {
|
|
|
81
90
|
* to hand span-ending ownership to `instrumentStream`; `false` for non-streaming/errored results, which end
|
|
82
91
|
* via the normal `beforeSpanEnd` path.
|
|
83
92
|
*/
|
|
84
|
-
function wrapStreamResult(span, data
|
|
93
|
+
function wrapStreamResult(span, data) {
|
|
85
94
|
const result = data.result;
|
|
86
95
|
if (!isAsyncIterable(result)) return false;
|
|
87
|
-
const { recordOutputs } = resolveAIRecordingOptions(options);
|
|
88
96
|
const iterate = result[Symbol.asyncIterator].bind(result);
|
|
89
|
-
const instrumented = instrumentStream({ [Symbol.asyncIterator]: iterate }, span,
|
|
97
|
+
const instrumented = instrumentStream({ [Symbol.asyncIterator]: iterate }, span, !!data._sentryRecordOutputs, data._sentryOnSpanEnd);
|
|
90
98
|
result[Symbol.asyncIterator] = () => instrumented;
|
|
91
99
|
return true;
|
|
92
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/openai.ts"],"sourcesContent":["import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';\nimport { defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from '@sentry/core';\nimport { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted,
|
|
1
|
+
{"version":3,"file":"openai.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/openai.ts"],"sourcesContent":["import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn, Span, SpanAttributeValue } from '@sentry/core';\nimport { defineIntegration, getClient, hasSpanStreamingEnabled, startInactiveSpan } from '@sentry/core';\nimport { getGenAiSpanOp, getRequestSignal, markCancelledIfAborted, resolveGenAiCallRecording } from '../ai/core/utils';\nimport { addRequestAttributes, extractRequestAttributes } from '../ai/openai';\nimport { wrapApiPromiseResponse } from '../ai/core/apiPromise';\nimport { type GenAiSpanResult, runGenAiSpanEnd, runGenAiSpanStart } from '../ai/core/span-hooks';\nimport { instrumentStream } from '../ai/openai/streaming';\nimport type { OpenAiCallInfo, OpenAiOptions } from '../ai/openai/types';\nimport { addResponseAttributes } from '../ai/openai/utils';\nimport { shouldSkipAiProviderSpan } from '../ai/pi-ai/providers';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\nimport { openaiModuleNames } from '../orchestrion/config/openai';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\n\n// The recording decision is made once, when the span starts, in the caller's async context.\ntype OpenAiChannelContext = OrchestrionChannelContext & {\n _sentryRecordOutputs?: boolean;\n _sentryOnSpanEnd?: (result: GenAiSpanResult<unknown>) => void;\n};\n\n// Same name as the OTel integration by design, so the OTel 'OpenAI'\n// integration is deduplicated out of the default set.\nconst INTEGRATION_NAME = 'OpenAI' as const;\n\nconst ORIGIN = 'auto.ai.openai';\n\n// Each instrumented `create` method maps to the gen_ai operation its span reports.\nconst INSTRUMENTED_CHANNELS = [\n { channel: CHANNELS.OPENAI_CHAT, operation: 'chat' },\n { channel: CHANNELS.OPENAI_EMBEDDINGS, operation: 'embeddings' },\n { channel: CHANNELS.OPENAI_DECIDE, operation: 'decide' },\n] as const;\n\nconst _openAIIntegration = ((options: OpenAiOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, openaiModuleNames, instrumentOpenai, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentOpenai(options: OpenAiOptions): void {\n for (const { channel, operation } of INSTRUMENTED_CHANNELS) {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<OpenAiChannelContext>(channel),\n data => createGenAiSpan(data, operation, options),\n {\n beforeSpanEnd: (span, data) => {\n if ('error' in data) {\n markCancelledIfAborted(span, getRequestSignal(data.arguments?.[1]));\n }\n addResponseAttributes(span, data.result, !!data._sentryRecordOutputs, operation);\n data._sentryOnSpanEnd?.('error' in data ? { error: data.error } : { response: data.result });\n },\n deferSpanEnd: ({ span, data, end }) =>\n wrapApiPromiseResponse(\n data.result,\n response => {\n data.result = response;\n // stream responses should end only after iteration is completed\n if (!wrapStreamResult(span, data)) {\n end();\n }\n },\n end,\n ) || wrapStreamResult(span, data),\n },\n );\n }\n}\n\n/**\n * Build the span for an instrumented `create` call.\n * Returning `undefined` opts the payload out so no span is opened.\n */\nfunction createGenAiSpan(data: OpenAiChannelContext, operation: string, options: OpenAiOptions): Span | undefined {\n if (shouldSkipAiProviderSpan(INTEGRATION_NAME)) {\n return undefined;\n }\n\n const args = data.arguments ?? [];\n const params = args[0] as Record<string, unknown> | undefined;\n\n const call: OpenAiCallInfo = { operation, request: params };\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n data._sentryRecordOutputs = recordOutputs;\n\n const attributes = extractRequestAttributes(args, operation, recordInputs);\n attributes[SENTRY_ORIGIN] = ORIGIN;\n const model = (params?.model as string) || 'unknown';\n const client = getClient();\n\n const span = startInactiveSpan({\n // With span streaming, omit the `'unknown'` model sentinel so the name stays low-cardinality.\n name: model !== 'unknown' || !(client && hasSpanStreamingEnabled(client)) ? `${operation} ${model}` : operation,\n op: getGenAiSpanOp(operation),\n attributes: attributes as Record<string, SpanAttributeValue>,\n });\n\n if (recordInputs && params) {\n addRequestAttributes(span, params, operation);\n }\n\n runGenAiSpanStart(options, span, call);\n data._sentryOnSpanEnd = result => runGenAiSpanEnd(options, span, call, result);\n\n return span;\n}\n\ntype AsyncIterableStream = { [Symbol.asyncIterator]: () => AsyncIterator<unknown> };\n\nfunction isAsyncIterable(value: unknown): value is AsyncIterableStream {\n return !!value && typeof (value as AsyncIterableStream)[Symbol.asyncIterator] === 'function';\n}\n\n/**\n * For a streaming `create({ stream: true })` the result is a `Stream` the caller consumes later. We can't\n * swap what `create` returns, but the `Stream` in `data.result` is the same instance the caller holds and\n * we observe it before the caller iterates — so we patch its async iterator in place to run through\n * `instrumentStream`, which accumulates the streamed attributes and ends the span when iteration finishes.\n * Only a streaming call resolves to an async-iterable, so that check alone distinguishes it. Returns `true`\n * to hand span-ending ownership to `instrumentStream`; `false` for non-streaming/errored results, which end\n * via the normal `beforeSpanEnd` path.\n */\nfunction wrapStreamResult(span: Span, data: OpenAiChannelContext): boolean {\n const result = data.result;\n if (!isAsyncIterable(result)) {\n return false;\n }\n\n const iterate = result[Symbol.asyncIterator].bind(result);\n const instrumented = instrumentStream(\n { [Symbol.asyncIterator]: iterate },\n span,\n !!data._sentryRecordOutputs,\n data._sentryOnSpanEnd,\n );\n result[Symbol.asyncIterator] = () => instrumented;\n\n return true;\n}\n\n/**\n * Diagnostics-channel-based OpenAI integration. Subscribes to the `orchestrion:openai:*`\n * diagnostics_channels injected into `openai`'s `create` methods (chat completions, responses, embeddings,\n * conversations, decisions), so it requires the Sentry runtime hook or bundler plugin.\n */\nexport const openAIIntegration = defineIntegration(_openAIIntegration);\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,mBAAmB;AAEzB,MAAM,SAAS;AAGf,MAAM,wBAAwB;CAC5B;EAAE,SAAS,SAAS;EAAa,WAAW;CAAO;CACnD;EAAE,SAAS,SAAS;EAAmB,WAAW;CAAa;CAC/D;EAAE,SAAS,SAAS;EAAe,WAAW;CAAS;AACzD;AAEA,MAAM,uBAAuB,UAAyB,CAAC,MAAM;CAC3D,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,mBAAmB,kBAAkB,CAAC,OAAO,CAAC;EACzF;CACF;AACF;AAEA,SAAS,iBAAiB,SAA8B;CACtD,KAAK,MAAM,EAAE,SAAS,eAAe,uBACnC,yBACEA,eAAwD,OAAO,IAC/D,SAAQ,gBAAgB,MAAM,WAAW,OAAO,GAChD;EACE,gBAAgB,MAAM,SAAS;GAC7B,IAAI,WAAW,MACb,uBAAuB,MAAM,iBAAiB,KAAK,YAAY,EAAE,CAAC;GAEpE,sBAAsB,MAAM,KAAK,QAAQ,CAAC,CAAC,KAAK,sBAAsB,SAAS;GAC/E,KAAK,mBAAmB,WAAW,OAAO,EAAE,OAAO,KAAK,MAAM,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;EAC7F;EACA,eAAe,EAAE,MAAM,MAAM,UAC3B,uBACE,KAAK,SACL,aAAY;GACV,KAAK,SAAS;GAEd,IAAI,CAAC,iBAAiB,MAAM,IAAI,GAC9B,IAAI;EAER,GACA,GACF,KAAK,iBAAiB,MAAM,IAAI;CACpC,CACF;AAEJ;;;;;AAMA,SAAS,gBAAgB,MAA4B,WAAmB,SAA0C;CAChH,IAAI,yBAAyB,gBAAgB,GAC3C;CAGF,MAAM,OAAO,KAAK,aAAa,CAAC;CAChC,MAAM,SAAS,KAAK;CAEpB,MAAM,OAAuB;EAAE;EAAW,SAAS;CAAO;CAC1D,MAAM,EAAE,cAAc,kBAAkB,0BAA0B,SAAS,IAAI;CAC/E,KAAK,uBAAuB;CAE5B,MAAM,aAAa,yBAAyB,MAAM,WAAW,YAAY;CACzE,WAAW,iBAAiB;CAC5B,MAAM,QAAS,QAAQ,SAAoB;CAC3C,MAAM,SAAS,UAAU;CAEzB,MAAM,OAAO,kBAAkB;EAE7B,MAAM,UAAU,aAAa,EAAE,UAAU,wBAAwB,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU;EACtG,IAAI,eAAe,SAAS;EAChB;CACd,CAAC;CAED,IAAI,gBAAgB,QAClB,qBAAqB,MAAM,QAAQ,SAAS;CAG9C,kBAAkB,SAAS,MAAM,IAAI;CACrC,KAAK,oBAAmB,WAAU,gBAAgB,SAAS,MAAM,MAAM,MAAM;CAE7E,OAAO;AACT;AAIA,SAAS,gBAAgB,OAA8C;CACrE,OAAO,CAAC,CAAC,SAAS,OAAQ,MAA8B,OAAO,mBAAmB;AACpF;;;;;;;;;;AAWA,SAAS,iBAAiB,MAAY,MAAqC;CACzE,MAAM,SAAS,KAAK;CACpB,IAAI,CAAC,gBAAgB,MAAM,GACzB,OAAO;CAGT,MAAM,UAAU,OAAO,OAAO,cAAc,CAAC,KAAK,MAAM;CACxD,MAAM,eAAe,iBACnB,GAAG,OAAO,gBAAgB,QAAQ,GAClC,MACA,CAAC,CAAC,KAAK,sBACP,KAAK,gBACP;CACA,OAAO,OAAO,uBAAuB;CAErC,OAAO;AACT;;;;;;AAOA,MAAa,oBAAoB,kBAAkB,kBAAkB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
-
import {
|
|
2
|
+
import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
|
|
3
|
+
import { getPiAiChatSpanOptions, observePiAiFirstChunk, setPiAiResponseAttributes } from "../ai/pi-ai/chat.js";
|
|
3
4
|
import { PI_AI_INTEGRATION_NAME } from "../ai/pi-ai/constants.js";
|
|
4
5
|
import { isInsidePiAiSpan } from "../ai/pi-ai/providers.js";
|
|
5
|
-
import { resolvePiAiRecordingOptions } from "../ai/pi-ai/recording.js";
|
|
6
|
+
import { getPiAiDriver, resolvePiAiRecordingOptions } from "../ai/pi-ai/recording.js";
|
|
6
7
|
import { CHANNELS } from "../orchestrion/channels.js";
|
|
7
8
|
import { piAiModuleNames } from "../orchestrion/config/pi-ai.js";
|
|
8
9
|
import { invokeOrchestrionInstrumentation } from "../orchestrion/instrumentation.js";
|
|
@@ -23,32 +24,52 @@ function instrumentPiAi(options) {
|
|
|
23
24
|
const startSpan = (data, streaming) => {
|
|
24
25
|
if (isInsidePiAiSpan()) return;
|
|
25
26
|
const [model, context, callOptions] = data.arguments ?? [];
|
|
26
|
-
const
|
|
27
|
+
const call = {
|
|
28
|
+
model,
|
|
29
|
+
context,
|
|
30
|
+
options: callOptions
|
|
31
|
+
};
|
|
32
|
+
const driver = getPiAiDriver();
|
|
33
|
+
const { recordInputs, recordOutputs } = resolvePiAiRecordingOptions(options, call, driver);
|
|
27
34
|
data._sentryRecordOutputs = recordOutputs;
|
|
28
|
-
|
|
35
|
+
const span = startInactiveSpan(getPiAiChatSpanOptions({
|
|
29
36
|
model: model ?? {},
|
|
30
37
|
context,
|
|
31
38
|
callOptions,
|
|
32
39
|
streaming,
|
|
33
40
|
recordInputs
|
|
34
41
|
}));
|
|
42
|
+
runGenAiSpanStart(options, span, call);
|
|
43
|
+
driver?.onSpanStart(span);
|
|
44
|
+
data._sentryOnSpanEnd = (result) => {
|
|
45
|
+
runGenAiSpanEnd(options, span, call, result);
|
|
46
|
+
driver?.onSpanEnd(span, result);
|
|
47
|
+
};
|
|
48
|
+
return span;
|
|
35
49
|
};
|
|
36
|
-
const
|
|
50
|
+
const beforeSpanEnd = (span, data, message) => {
|
|
51
|
+
if ("error" in data) {
|
|
52
|
+
data._sentryOnSpanEnd?.({ error: data.error });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
37
55
|
if (message && typeof message === "object") setPiAiResponseAttributes(span, message, !!data._sentryRecordOutputs);
|
|
56
|
+
data._sentryOnSpanEnd?.({ response: message });
|
|
38
57
|
};
|
|
39
|
-
bindTracingChannelToSpan(streamChannel, (data) => startSpan(data, true), {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
bindTracingChannelToSpan(streamChannel, (data) => startSpan(data, true), {
|
|
59
|
+
deferSpanEnd: ({ span, data, end }) => {
|
|
60
|
+
const events = data.result;
|
|
61
|
+
const settled = "error" in data || typeof events?.result !== "function" ? void 0 : events.result();
|
|
62
|
+
if (!isThenable(settled)) return false;
|
|
63
|
+
observePiAiFirstChunk(span, events);
|
|
64
|
+
settled.then((message) => {
|
|
65
|
+
data._sentryMessage = message;
|
|
66
|
+
end();
|
|
67
|
+
}, end);
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
beforeSpanEnd: (span, data) => beforeSpanEnd(span, data, data._sentryMessage)
|
|
71
|
+
});
|
|
72
|
+
bindTracingChannelToSpan(completeChannel, (data) => startSpan(data, false), { beforeSpanEnd: (span, data) => beforeSpanEnd(span, data, data.result) });
|
|
52
73
|
}
|
|
53
74
|
/**
|
|
54
75
|
* Traces the requests sent with pi-ai (`@earendil-works/pi-ai` >= 0.80.0 < 2) as `gen_ai.chat` spans,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-ai.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/pi-ai.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport { defineIntegration, isThenable, startInactiveSpan } from '@sentry/core';\nimport type {
|
|
1
|
+
{"version":3,"file":"pi-ai.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/pi-ai.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport { defineIntegration, isThenable, startInactiveSpan } from '@sentry/core';\nimport type { GenAiSpanHooks, GenAiSpanResult } from '../ai/core/span-hooks';\nimport { runGenAiSpanEnd, runGenAiSpanStart } from '../ai/core/span-hooks';\nimport type { GenAiCallOptions } from '../ai/core/utils';\nimport { getPiAiChatSpanOptions, observePiAiFirstChunk, setPiAiResponseAttributes } from '../ai/pi-ai/chat';\nimport { PI_AI_INTEGRATION_NAME } from '../ai/pi-ai/constants';\nimport type { PiAiContext } from '../ai/pi-ai/messages';\nimport { isInsidePiAiSpan } from '../ai/pi-ai/providers';\nimport { getPiAiDriver, resolvePiAiRecordingOptions } from '../ai/pi-ai/recording';\nimport type { PiAiCallInfo, PiAssistantMessage, PiEventStream, PiModel, PiStreamOptions } from '../ai/pi-ai/types';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { piAiModuleNames } from '../orchestrion/config/pi-ai';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\n\n/** `onSpanEnd` gets the `AssistantMessage` the request settled with, for `stream` and `complete` alike. */\nexport type PiAiOptions = GenAiCallOptions<PiAiCallInfo> & GenAiSpanHooks<PiAiCallInfo, PiAssistantMessage>;\n\ntype PiAiChannelContext = OrchestrionChannelContext & {\n _sentryRecordOutputs?: boolean;\n /** The message a stream's `result()` settled with. */\n _sentryMessage?: unknown;\n _sentryOnSpanEnd?: (result: GenAiSpanResult<PiAssistantMessage>) => void;\n};\n\nconst _piAiIntegration = ((options: PiAiOptions = {}) => {\n return {\n name: PI_AI_INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, piAiModuleNames, instrumentPiAi, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentPiAi(options: PiAiOptions): void {\n const streamChannel = diagnosticsChannel.tracingChannel<PiAiChannelContext>(CHANNELS.PI_AI_STREAM);\n const completeChannel = diagnosticsChannel.tracingChannel<PiAiChannelContext>(CHANNELS.PI_AI_COMPLETE);\n\n const startSpan = (data: PiAiChannelContext, streaming: boolean): Span | undefined => {\n // `complete` awaits `stream`, and the `compat` functions hand some models to a `Models` of their\n // own, so a traced call can make another one. Only the outermost gets a span.\n if (isInsidePiAiSpan()) {\n return undefined;\n }\n const [model, context, callOptions] = (data.arguments ?? []) as [\n PiModel | undefined,\n PiAiCallInfo['context'],\n PiStreamOptions | undefined,\n ];\n const call: PiAiCallInfo = { model, context, options: callOptions };\n // Flue and pi-durable put their own options on the scope of the requests they send.\n const driver = getPiAiDriver();\n const { recordInputs, recordOutputs } = resolvePiAiRecordingOptions(options, call, driver);\n data._sentryRecordOutputs = recordOutputs;\n const span = startInactiveSpan(\n getPiAiChatSpanOptions({\n model: model ?? {},\n // The deferred calls pass a handle here, which carries no request content.\n context: context as PiAiContext | undefined,\n callOptions,\n streaming,\n recordInputs,\n }),\n );\n runGenAiSpanStart(options, span, call);\n driver?.onSpanStart(span);\n data._sentryOnSpanEnd = result => {\n runGenAiSpanEnd(options, span, call, result);\n driver?.onSpanEnd(span, result);\n };\n return span;\n };\n\n const beforeSpanEnd = (span: Span, data: PiAiChannelContext, message: unknown): void => {\n if ('error' in data) {\n data._sentryOnSpanEnd?.({ error: data.error });\n return;\n }\n if (message && typeof message === 'object') {\n setPiAiResponseAttributes(span, message, !!data._sentryRecordOutputs);\n }\n data._sentryOnSpanEnd?.({ response: message as PiAssistantMessage | undefined });\n };\n\n bindTracingChannelToSpan(streamChannel, data => startSpan(data, true), {\n // The stream is returned before the request settles; its `result()` settles with the message.\n deferSpanEnd: ({ span, data, end }) => {\n const events = data.result as Partial<PiEventStream> | undefined;\n const settled = 'error' in data || typeof events?.result !== 'function' ? undefined : events.result();\n if (!isThenable(settled)) {\n return false;\n }\n observePiAiFirstChunk(span, events);\n settled.then(message => {\n data._sentryMessage = message;\n end();\n }, end);\n return true;\n },\n beforeSpanEnd: (span, data) => beforeSpanEnd(span, data, data._sentryMessage),\n });\n\n bindTracingChannelToSpan(completeChannel, data => startSpan(data, false), {\n beforeSpanEnd: (span, data) => beforeSpanEnd(span, data, data.result),\n });\n}\n\n/**\n * Traces the requests sent with pi-ai (`@earendil-works/pi-ai` >= 0.80.0 < 2) as `gen_ai.chat` spans,\n * through `createModels()` or the standalone `stream` and `complete` functions. Needs the Sentry\n * runtime hook (`--import`) or bundler plugin. This includes the model calls of Flue and pi-durable\n * agents, which send them through pi-ai.\n *\n * @example\n * ```javascript\n * Sentry.init({\n * integrations: [Sentry.piAiIntegration({ recordInputs: true, recordOutputs: true })],\n * });\n * ```\n */\nexport const piAiIntegration = defineIntegration(_piAiIntegration);\n"],"mappings":";;;;;;;;;;;;AA4BA,MAAM,qBAAqB,UAAuB,CAAC,MAAM;CACvD,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,iBAAiB,gBAAgB,CAAC,OAAO,CAAC;EACrF;CACF;AACF;AAEA,SAAS,eAAe,SAA4B;CAClD,MAAM,gBAAgBA,eAAsD,SAAS,YAAY;CACjG,MAAM,kBAAkBA,eAAsD,SAAS,cAAc;CAErG,MAAM,aAAa,MAA0B,cAAyC;EAGpF,IAAI,iBAAiB,GACnB;EAEF,MAAM,CAAC,OAAO,SAAS,eAAgB,KAAK,aAAa,CAAC;EAK1D,MAAM,OAAqB;GAAE;GAAO;GAAS,SAAS;EAAY;EAElE,MAAM,SAAS,cAAc;EAC7B,MAAM,EAAE,cAAc,kBAAkB,4BAA4B,SAAS,MAAM,MAAM;EACzF,KAAK,uBAAuB;EAC5B,MAAM,OAAO,kBACX,uBAAuB;GACrB,OAAO,SAAS,CAAC;GAER;GACT;GACA;GACA;EACF,CAAC,CACH;EACA,kBAAkB,SAAS,MAAM,IAAI;EACrC,QAAQ,YAAY,IAAI;EACxB,KAAK,oBAAmB,WAAU;GAChC,gBAAgB,SAAS,MAAM,MAAM,MAAM;GAC3C,QAAQ,UAAU,MAAM,MAAM;EAChC;EACA,OAAO;CACT;CAEA,MAAM,iBAAiB,MAAY,MAA0B,YAA2B;EACtF,IAAI,WAAW,MAAM;GACnB,KAAK,mBAAmB,EAAE,OAAO,KAAK,MAAM,CAAC;GAC7C;EACF;EACA,IAAI,WAAW,OAAO,YAAY,UAChC,0BAA0B,MAAM,SAAS,CAAC,CAAC,KAAK,oBAAoB;EAEtE,KAAK,mBAAmB,EAAE,UAAU,QAA0C,CAAC;CACjF;CAEA,yBAAyB,gBAAe,SAAQ,UAAU,MAAM,IAAI,GAAG;EAErE,eAAe,EAAE,MAAM,MAAM,UAAU;GACrC,MAAM,SAAS,KAAK;GACpB,MAAM,UAAU,WAAW,QAAQ,OAAO,QAAQ,WAAW,aAAa,KAAA,IAAY,OAAO,OAAO;GACpG,IAAI,CAAC,WAAW,OAAO,GACrB,OAAO;GAET,sBAAsB,MAAM,MAAM;GAClC,QAAQ,MAAK,YAAW;IACtB,KAAK,iBAAiB;IACtB,IAAI;GACN,GAAG,GAAG;GACN,OAAO;EACT;EACA,gBAAgB,MAAM,SAAS,cAAc,MAAM,MAAM,KAAK,cAAc;CAC9E,CAAC;CAED,yBAAyB,kBAAiB,SAAQ,UAAU,MAAM,KAAK,GAAG,EACxE,gBAAgB,MAAM,SAAS,cAAc,MAAM,MAAM,KAAK,MAAM,EACtE,CAAC;AACH;;;;;;;;;;;;;;AAeA,MAAa,kBAAkB,kBAAkB,gBAAgB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
+
import { SENTRY_ORIGIN } from "@sentry/conventions/attributes";
|
|
3
|
+
import { _INTERNAL_captureLog, addExceptionMechanism, captureException, captureMessage, defineIntegration, isObjectLike, severityLevelFromString, withScope } from "@sentry/core";
|
|
4
|
+
// src/integrations/pino.ts
|
|
5
|
+
const SENTRY_TRACK_SYMBOL = Symbol("sentry-track-pino-logger");
|
|
6
|
+
/**
|
|
7
|
+
* Gets a custom Pino key from a logger instance by searching for the symbol.
|
|
8
|
+
* Pino uses non-global symbols like Symbol('pino.messageKey'): https://github.com/pinojs/pino/blob/8a816c0b1f72de5ae9181f3bb402109b66f7d812/lib/symbols.js
|
|
9
|
+
*/
|
|
10
|
+
function getPinoKey(logger, symbolName, defaultKey) {
|
|
11
|
+
const symbols = Object.getOwnPropertySymbols(logger);
|
|
12
|
+
const symbolString = `Symbol(${symbolName})`;
|
|
13
|
+
for (const sym of symbols) if (sym.toString() === symbolString) {
|
|
14
|
+
const value = logger[sym];
|
|
15
|
+
return typeof value === "string" ? value : defaultKey;
|
|
16
|
+
}
|
|
17
|
+
return defaultKey;
|
|
18
|
+
}
|
|
19
|
+
const DEFAULT_OPTIONS = {
|
|
20
|
+
autoInstrument: true,
|
|
21
|
+
error: {
|
|
22
|
+
levels: [],
|
|
23
|
+
handled: true
|
|
24
|
+
},
|
|
25
|
+
log: { levels: [
|
|
26
|
+
"trace",
|
|
27
|
+
"debug",
|
|
28
|
+
"info",
|
|
29
|
+
"warn",
|
|
30
|
+
"error",
|
|
31
|
+
"fatal"
|
|
32
|
+
] }
|
|
33
|
+
};
|
|
34
|
+
function stripIgnoredFields(result) {
|
|
35
|
+
const { level, time, pid, hostname, ...rest } = result;
|
|
36
|
+
return rest;
|
|
37
|
+
}
|
|
38
|
+
const _pinoIntegration = defineIntegration((userOptions = {}) => {
|
|
39
|
+
const options = {
|
|
40
|
+
autoInstrument: userOptions.autoInstrument !== false,
|
|
41
|
+
error: {
|
|
42
|
+
...DEFAULT_OPTIONS.error,
|
|
43
|
+
...userOptions.error
|
|
44
|
+
},
|
|
45
|
+
log: {
|
|
46
|
+
...DEFAULT_OPTIONS.log,
|
|
47
|
+
...userOptions.log
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function shouldTrackLogger(logger) {
|
|
51
|
+
const override = logger[SENTRY_TRACK_SYMBOL];
|
|
52
|
+
return override === "track" || override !== "ignore" && options.autoInstrument;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
name: "Pino",
|
|
56
|
+
setup: () => {
|
|
57
|
+
const integratedChannel = tracingChannel("pino_asJson");
|
|
58
|
+
function onPinoStart(self, args, result) {
|
|
59
|
+
if (!shouldTrackLogger(self)) return;
|
|
60
|
+
const resultObj = stripIgnoredFields(result);
|
|
61
|
+
const [captureObj, message, levelNumber] = args;
|
|
62
|
+
const level = self?.levels?.labels?.[levelNumber] || "info";
|
|
63
|
+
const messageKey = getPinoKey(self, "pino.messageKey", "msg");
|
|
64
|
+
const logMessage = message || resultObj?.[messageKey] || "";
|
|
65
|
+
if (options.log.levels.includes(level)) {
|
|
66
|
+
const attributes = {
|
|
67
|
+
...resultObj,
|
|
68
|
+
[SENTRY_ORIGIN]: "auto.log.pino",
|
|
69
|
+
"pino.logger.level": levelNumber
|
|
70
|
+
};
|
|
71
|
+
_INTERNAL_captureLog({
|
|
72
|
+
level,
|
|
73
|
+
message: logMessage,
|
|
74
|
+
attributes
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (options.error.levels.includes(level)) {
|
|
78
|
+
const errorKey = getPinoKey(self, "pino.errorKey", "err");
|
|
79
|
+
const pinoContext = {};
|
|
80
|
+
for (const [key, value] of Object.entries(resultObj)) if (key !== errorKey && key !== messageKey) pinoContext[key] = value;
|
|
81
|
+
if (logMessage) pinoContext[messageKey] = logMessage;
|
|
82
|
+
const captureContext = {
|
|
83
|
+
level: severityLevelFromString(level),
|
|
84
|
+
contexts: { pino: pinoContext }
|
|
85
|
+
};
|
|
86
|
+
withScope((scope) => {
|
|
87
|
+
scope.addEventProcessor((event) => {
|
|
88
|
+
event.logger = "pino";
|
|
89
|
+
addExceptionMechanism(event, {
|
|
90
|
+
handled: options.error.handled,
|
|
91
|
+
type: "auto.log.pino"
|
|
92
|
+
});
|
|
93
|
+
return event;
|
|
94
|
+
});
|
|
95
|
+
const error = captureObj[errorKey];
|
|
96
|
+
if (error) {
|
|
97
|
+
captureException(error, captureContext);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
captureMessage(logMessage, captureContext);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
integratedChannel.end.subscribe((data) => {
|
|
105
|
+
const { instance, arguments: args, result } = data;
|
|
106
|
+
onPinoStart(instance, args, JSON.parse(result));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Integration for Pino logging library.
|
|
113
|
+
* Captures Pino logs as Sentry logs and optionally captures some log levels as events.
|
|
114
|
+
*
|
|
115
|
+
* By default, all Pino loggers will be captured. To ignore a specific logger, use `pinoIntegration.untrackLogger(logger)`.
|
|
116
|
+
*
|
|
117
|
+
* If you disable automatic instrumentation with `autoInstrument: false`, you can mark specific loggers to be tracked with `pinoIntegration.trackLogger(logger)`.
|
|
118
|
+
*
|
|
119
|
+
* Requires Pino >=v8.0.0
|
|
120
|
+
*/
|
|
121
|
+
const pinoIntegration = Object.assign(_pinoIntegration, {
|
|
122
|
+
trackLogger(logger) {
|
|
123
|
+
if (isObjectLike(logger) && "levels" in logger) logger[SENTRY_TRACK_SYMBOL] = "track";
|
|
124
|
+
},
|
|
125
|
+
untrackLogger(logger) {
|
|
126
|
+
if (isObjectLike(logger) && "levels" in logger) logger[SENTRY_TRACK_SYMBOL] = "ignore";
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
export { pinoIntegration };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=pino.js.map
|
|
@@ -0,0 +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 _INTERNAL_captureLog,\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 _INTERNAL_captureLog({ 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;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;CACpD;CAEA,SAAS,kBAAkB,QAAuB;EAChD,MAAM,WAAW,OAAO;EACxB,OAAO,aAAa,WAAY,aAAa,YAAY,QAAQ;CACnE;CAEA,OAAO;EACL,MAAM;EACN,aAAa;GACX,MAAM,oBAAoB,eAAe,aAAa;GAEtD,SAAS,YAAY,MAAY,MAAoB,QAA0B;IAC7E,IAAI,CAAC,kBAAkB,IAAI,GACzB;IAGF,MAAM,YAAY,mBAAmB,MAAM;IAE3C,MAAM,CAAC,YAAY,SAAS,eAAe;IAC3C,MAAM,QAAQ,MAAM,QAAQ,SAAS,gBAAgB;IACrD,MAAM,aAAa,WAAW,MAAM,mBAAmB,KAAK;IAC5D,MAAM,aAAa,WAAY,YAAY,eAAsC;IAEjF,IAAI,QAAQ,IAAI,OAAO,SAAS,KAAK,GAAG;KACtC,MAAM,aAAsC;MAC1C,GAAG;OACF,gBAAgB;MACjB,qBAAqB;KACvB;KAEA,qBAAqB;MAAE;MAAO,SAAS;MAAY;KAAW,CAAC;IACjE;IAEA,IAAI,QAAQ,MAAM,OAAO,SAAS,KAAK,GAAG;KACxC,MAAM,WAAW,WAAW,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;OACT,iBAAiB,OAAO,cAAc;OACtC;MACF;MAEA,eAAe,YAAY,cAAc;KAC3C,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,5 +1,6 @@
|
|
|
1
1
|
import { tracingChannel } from "../utils/diagnosticsChannel.js";
|
|
2
|
-
import {
|
|
2
|
+
import { runGenAiSpanEnd, runGenAiSpanStart } from "../ai/core/span-hooks.js";
|
|
3
|
+
import { resolveGenAiCallRecording } from "../ai/core/utils.js";
|
|
3
4
|
import { addResponseAttributes, onSystemOneResponse, startDecideSpan } from "../ai/typesafe/index.js";
|
|
4
5
|
import { TYPESAFE_INTEGRATION_NAME } from "../ai/typesafe/constants.js";
|
|
5
6
|
import { CHANNELS } from "../orchestrion/channels.js";
|
|
@@ -17,9 +18,22 @@ const _typesafeIntegration = ((options = {}) => {
|
|
|
17
18
|
};
|
|
18
19
|
});
|
|
19
20
|
function instrumentTypeSafe(options) {
|
|
20
|
-
bindTracingChannelToSpan(tracingChannel(CHANNELS.TYPESAFE_SYSTEM_ONE), (data) =>
|
|
21
|
+
bindTracingChannelToSpan(tracingChannel(CHANNELS.TYPESAFE_SYSTEM_ONE), (data) => {
|
|
22
|
+
const request = data.arguments?.[0];
|
|
23
|
+
const call = { request };
|
|
24
|
+
const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);
|
|
25
|
+
data._sentryRecordOutputs = recordOutputs;
|
|
26
|
+
const span = startDecideSpan(request, data.self, recordInputs);
|
|
27
|
+
runGenAiSpanStart(options, span, call);
|
|
28
|
+
data._sentryOnSpanEnd = (result) => runGenAiSpanEnd(options, span, call, result);
|
|
29
|
+
return span;
|
|
30
|
+
}, {
|
|
21
31
|
beforeSpanEnd: (span, data) => {
|
|
22
|
-
if (
|
|
32
|
+
if ("error" in data) data._sentryOnSpanEnd?.({ error: data.error });
|
|
33
|
+
else {
|
|
34
|
+
addResponseAttributes(span, data.result, !!data._sentryRecordOutputs);
|
|
35
|
+
data._sentryOnSpanEnd?.({ response: data.result });
|
|
36
|
+
}
|
|
23
37
|
},
|
|
24
38
|
deferSpanEnd: ({ data, end }) => onSystemOneResponse(data.result, (body) => {
|
|
25
39
|
data.result = body;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typesafe.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/typesafe.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport type
|
|
1
|
+
{"version":3,"file":"typesafe.js","names":["diagnosticsChannel.tracingChannel"],"sources":["../../../src/integrations/typesafe.ts"],"sourcesContent":["import * as diagnosticsChannel from '../utils/diagnosticsChannel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { type GenAiSpanResult, runGenAiSpanEnd, runGenAiSpanStart } from '../ai/core/span-hooks';\nimport { resolveGenAiCallRecording } from '../ai/core/utils';\nimport type { TypeSafeCallInfo, TypeSafeOptions } from '../ai/typesafe';\nimport { addResponseAttributes, onSystemOneResponse, startDecideSpan } from '../ai/typesafe';\nimport { TYPESAFE_INTEGRATION_NAME } from '../ai/typesafe/constants';\nimport type { OrchestrionChannelContext } from '../orchestrion/types';\nimport { CHANNELS } from '../orchestrion/channels';\nimport { typesafeModuleNames } from '../orchestrion/config/typesafe';\nimport { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';\nimport { bindTracingChannelToSpan } from '../tracing-channel';\n\n// The recording decision is made once, when the span starts, in the caller's async context.\ntype TypeSafeChannelContext = OrchestrionChannelContext & {\n _sentryRecordOutputs?: boolean;\n _sentryOnSpanEnd?: (result: GenAiSpanResult<unknown>) => void;\n};\n\nconst _typesafeIntegration = ((options: TypeSafeOptions = {}) => {\n return {\n name: TYPESAFE_INTEGRATION_NAME,\n setup(client) {\n invokeOrchestrionInstrumentation(client, typesafeModuleNames, instrumentTypeSafe, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\nfunction instrumentTypeSafe(options: TypeSafeOptions): void {\n bindTracingChannelToSpan(\n diagnosticsChannel.tracingChannel<TypeSafeChannelContext>(CHANNELS.TYPESAFE_SYSTEM_ONE),\n data => {\n const request = data.arguments?.[0];\n const call: TypeSafeCallInfo = { request };\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n data._sentryRecordOutputs = recordOutputs;\n const span = startDecideSpan(request, data.self, recordInputs);\n runGenAiSpanStart(options, span, call);\n data._sentryOnSpanEnd = result => runGenAiSpanEnd(options, span, call, result);\n return span;\n },\n {\n beforeSpanEnd: (span, data) => {\n if ('error' in data) {\n data._sentryOnSpanEnd?.({ error: data.error });\n } else {\n addResponseAttributes(span, data.result, !!data._sentryRecordOutputs);\n data._sentryOnSpanEnd?.({ response: data.result });\n }\n },\n deferSpanEnd: ({ data, end }) =>\n onSystemOneResponse(\n data.result,\n body => {\n data.result = body;\n end();\n },\n error => end(error),\n ),\n },\n );\n}\n\n/**\n * Diagnostics-channel-based integration for the TypeSafe SDK (`@typesafe-ai/sdk` >= 0.5.0 < 1).\n * Subscribes to the `orchestrion:@typesafe-ai/sdk:system-one` channel injected into\n * `TypeSafeClient.systemOne`, so it requires the Sentry runtime hook or bundler plugin.\n */\nexport const typesafeIntegration = defineIntegration(_typesafeIntegration);\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,yBAAyB,UAA2B,CAAC,MAAM;CAC/D,OAAO;EACL,MAAM;EACN,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,qBAAqB,oBAAoB,CAAC,OAAO,CAAC;EAC7F;CACF;AACF;AAEA,SAAS,mBAAmB,SAAgC;CAC1D,yBACEA,eAA0D,SAAS,mBAAmB,IACtF,SAAQ;EACN,MAAM,UAAU,KAAK,YAAY;EACjC,MAAM,OAAyB,EAAE,QAAQ;EACzC,MAAM,EAAE,cAAc,kBAAkB,0BAA0B,SAAS,IAAI;EAC/E,KAAK,uBAAuB;EAC5B,MAAM,OAAO,gBAAgB,SAAS,KAAK,MAAM,YAAY;EAC7D,kBAAkB,SAAS,MAAM,IAAI;EACrC,KAAK,oBAAmB,WAAU,gBAAgB,SAAS,MAAM,MAAM,MAAM;EAC7E,OAAO;CACT,GACA;EACE,gBAAgB,MAAM,SAAS;GAC7B,IAAI,WAAW,MACb,KAAK,mBAAmB,EAAE,OAAO,KAAK,MAAM,CAAC;QACxC;IACL,sBAAsB,MAAM,KAAK,QAAQ,CAAC,CAAC,KAAK,oBAAoB;IACpE,KAAK,mBAAmB,EAAE,UAAU,KAAK,OAAO,CAAC;GACnD;EACF;EACA,eAAe,EAAE,MAAM,UACrB,oBACE,KAAK,SACL,SAAQ;GACN,KAAK,SAAS;GACd,IAAI;EACN,IACA,UAAS,IAAI,KAAK,CACpB;CACJ,CACF;AACF;;;;;;AAOA,MAAa,sBAAsB,kBAAkB,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["dc.tracingChannel"],"sources":["../../../../src/integrations/vercel-ai/index.ts"],"sourcesContent":["import { defineIntegration, waitForTracingChannelBinding, type IntegrationFn } from '@sentry/core';\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":["dc.tracingChannel"],"sources":["../../../../src/integrations/vercel-ai/index.ts"],"sourcesContent":["import { defineIntegration, waitForTracingChannelBinding, type IntegrationFn } from '@sentry/core';\nimport { subscribeVercelAiTracingChannel, type VercelAiChannelOptions } from './vercel-ai-dc-subscriber';\nimport { registerVercelAiToolTelemetry } from './vercel-ai-tool-telemetry';\nimport * as dc from '../../utils/diagnosticsChannel';\nimport { invokeOrchestrionInstrumentation } from '../../orchestrion/instrumentation';\nimport { vercelAiModuleNames } from '../../orchestrion/config/vercel-ai';\nimport { subscribeVercelAiOrchestrionChannels } from './vercel-ai-orchestrion-subscriber';\n\n/** Options for the Vercel AI integration. */\nexport type VercelAiOptions = VercelAiChannelOptions;\n\nconst _vercelAIIntegration = ((options: VercelAiOptions = {}) => {\n return {\n name: 'VercelAI' as const,\n setupOnce() {\n // Bail if this is not available\n if (!dc.tracingChannel) {\n return;\n }\n\n // Subscribe to the `ai` SDK's native telemetry tracing channel (ai >= 7).\n // This is a no-op on versions that don't publish to the channel, so it is always safe to call.\n waitForTracingChannelBinding(() => {\n subscribeVercelAiTracingChannel(dc.tracingChannel, options);\n });\n registerVercelAiToolTelemetry();\n },\n setup(client) {\n invokeOrchestrionInstrumentation(client, vercelAiModuleNames, instrumentVercelAiOrchestrion, [options]);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Auto-instrument the `ai` SDK. Supported are:\n * - v7 via native `ai:telemetry` tracing channel\n * - v4, v5 & v6 via the injected `orchestrion:ai:*` channels\n */\nexport const vercelAIIntegration = defineIntegration(_vercelAIIntegration);\n\nfunction instrumentVercelAiOrchestrion(options: VercelAiOptions): void {\n subscribeVercelAiOrchestrionChannels(dc.tracingChannel, options);\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,yBAAyB,UAA2B,CAAC,MAAM;CAC/D,OAAO;EACL,MAAM;EACN,YAAY;GAEV,IAAI,CAACA,gBACH;GAKF,mCAAmC;IACjC,gCAAgCA,gBAAmB,OAAO;GAC5D,CAAC;GACD,8BAA8B;EAChC;EACA,MAAM,QAAQ;GACZ,iCAAiC,QAAQ,qBAAqB,+BAA+B,CAAC,OAAO,CAAC;EACxG;CACF;AACF;;;;;;AAOA,MAAa,sBAAsB,kBAAkB,oBAAoB;AAEzE,SAAS,8BAA8B,SAAgC;CACrE,qCAAqCA,gBAAmB,OAAO;AACjE"}
|