npx skills add ...
npx skills add getsentry/sentry-javascript --skill add-ai-integration
npx skills add getsentry/sentry-javascript --skill add-ai-integration
Add a new AI provider integration to the Sentry JavaScript SDK. Use when contributing a new AI instrumentation (OpenAI, Anthropic, Vercel AI, LangChain, etc.) or modifying an existing one.
If an AI SDK only works in one runtime, code lives exclusively in that runtime's package. Do NOT add it to packages/core/.
packages/node/src/integrations/tracing/{provider}/packages/cloudflare/src/integrations/tracing/{provider}.tspackages/browser/src/integrations/tracing/{provider}/packages/core/src/tracing/{provider}/ with runtime-specific wrappersgen_ai.invoke_agent — parent/pipeline spans (chains, agents, orchestration)gen_ai.chat, gen_ai.generate_text, etc. — child spans (actual LLM calls)packages/core/src/tracing/ai/)gen-ai-attributes.ts — OTel Semantic Convention attribute constants. Always use these, never hardcode.utils.ts — setTokenUsageAttributes(), getTruncatedJsonString(), truncateGenAiMessages(), buildMethodPath()startSpan(), set attributes from responsestartSpanManual(), accumulate state via async generator or event listeners, set GEN_AI_RESPONSE_STREAMING_ATTRIBUTE: true, call span.end() in finally blockparams.stream === trueopenai/streaming.ts (async generator), anthropic-ai/streaming.ts (event listeners)setTokenUsageAttributes()invoke_agent): Accumulate from children using event processor (see vercel-ai/)Use when: SDK emits OTel spans automatically (Vercel AI)
add{Provider}Processors() in packages/core/src/tracing/{provider}/index.ts — registers spanStart listener + event processorcallWhenPatched() optimization in packages/node/src/integrations/tracing/{provider}/index.ts — defers registration until package is importedpackages/cloudflare/src/integrations/tracing/{provider}.ts — no OTel, call processors immediatelyReference: packages/node/src/integrations/tracing/vercelai/
Use when: SDK has no native OTel support (OpenAI, Anthropic, Google GenAI)
instrument{Provider}Client() in packages/core/src/tracing/{provider}/index.ts — Proxy to wrap client methods, create spans manuallyinstrumentation.ts: Patch module exports, wrap client constructor. Check _INTERNAL_shouldSkipAiProviderWrapping() for LangChain compatibility.index.ts: Export integration function using generateInstrumentOnce() helperReference: packages/node/src/integrations/tracing/openai/
Use when: SDK provides lifecycle hooks (LangChain, LangGraph)
create{Provider}CallbackHandler() — implement SDK's callback interface, create spans in callbacksinstrumentation.ts: Auto-inject callbacks by patching runnable methods. Disable underlying AI provider wrapping.Reference: packages/node/src/integrations/tracing/langchain/
Mandatory for Node.js AI integrations. OTel only patches when the package is imported (zero cost if unused).
getAutoPerformanceIntegrations() in packages/node/src/integrations/tracing/index.ts — LangChain MUST come firstgetOpenTelemetryInstrumentationToPreload() for OTel-based integrationspackages/node/src/index.ts: integration function + options typedev-packages/node-integration-tests/suites/tracing/{provider}/dev-packages/cloudflare-integration-tests/suites/tracing/{provider}/dev-packages/browser-integration-tests/suites/tracing/ai-providers/{provider}/sendDefaultPii for recordInputs/recordOutputsSEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.{provider}' (alphanumerics, _, . only)utils.tsgen_ai.invoke_agent for parent ops, gen_ai.chat for child opsgetAutoPerformanceIntegrations() in correct order (Node.js)getOpenTelemetryInstrumentationToPreload() (Node.js with OTel)packages/node/src/integrations/tracing/vercelai/packages/node/src/integrations/tracing/openai/packages/node/src/integrations/tracing/langchain/When in doubt, follow the pattern of the most similar existing integration.