Adding a New AI Integration
SkillCloud & infraThis skill guides your AI through adding a new AI provider tracing integration to the Sentry JavaScript SDK. Once added, your AI can build instrumentation for providers like OpenAI, Anthropic, Vercel AI, or LangChain, or update an integration that already exists. The outcome is a working integration in the SDK that you can contribute.
Available today. Use it from your connected AI after setup.
No other account needed.
After adding this skill, tell your AI which AI provider you want to trace. It will then walk through the steps to build that integration in the Sentry JavaScript SDK.
Then ask your AI: use the Adding a New AI Integration skill
What your AI can do with it
- Add tracing for a new AI provider such as OpenAI, Anthropic, Vercel AI, or LangChain
- Modify an existing AI instrumentation in the Sentry JavaScript SDK
- Follow a guided, step-by-step process for building the integration
- Prepare the new integration as a contribution to the SDK
What this skill tells your AI
The instructions your AI receives, as published by getsentry/sentry-javascript in .agents/skills/add-ai-integration/SKILL.md and read by ahel’s review.
Decision Tree
Does the AI SDK have native OpenTelemetry support?
|- YES -> Does it emit OTel spans automatically?
| |- YES (like Vercel AI) -> Pattern 1: OTel Span Processors
| +- NO -> Pattern 2: OTel Instrumentation (wrap client)
+- NO -> Does the SDK provide hooks/callbacks?
|- YES (like LangChain) -> Pattern 3: Callback/Hook Based
+- NO -> Pattern 4: Client Wrapping
Runtime-Specific Placement
If an AI SDK only works in one runtime, code lives exclusively in that runtime's package. Do NOT add it to packages/core/.
- Node.js-only ->
packages/node/src/integrations/tracing/{provider}/ - Cloudflare-only ->
packages/cloudflare/src/integrations/tracing/{provider}.ts - Browser-only ->
packages/browser/src/integrations/tracing/{provider}/ - Multi-runtime -> shared core in
packages/core/src/tracing/{provider}/with runtime-specific wrappers
Span Hierarchy
gen_ai.invoke_agent— parent/pipeline spans (chains, agents, orchestration)gen_ai.chat,gen_ai.generate_text, etc. — child spans (actual LLM calls)
Shared Utilities (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()- Only use attributes from Sentry Gen AI Conventions.
Streaming
- Non-streaming:
startSpan(), set attributes from response - Streaming:
startSpanManual(), accumulate state via async generator or event listeners, setGEN_AI_RESPONSE_STREAMING_ATTRIBUTE: true, callspan.end()in finally block - Detect via
params.stream === true - References:
openai/streaming.ts(async generator),anthropic-ai/streaming.ts(event listeners)
Token Accumulation
- Child spans: Set tokens directly from API response via
setTokenUsageAttributes() - Parent spans (
invoke_agent): Accumulate from children using event processor (seevercel-ai/)
Pattern 1: OTel Span Processors
Use when: SDK emits OTel spans automatically (Vercel AI)
- Core: Create
add{Provider}Processors()inpackages/core/src/tracing/{provider}/index.ts— registersspanStartlistener + event processor - Node.js: Add
callWhenPatched()optimization inpackages/node/src/integrations/tracing/{provider}/index.ts— defers registration until package is imported - Edge: Direct registration in
packages/cloudflare/src/integrations/tracing/{provider}.ts— no OTel, call processors immediately
Reference: packages/node/src/integrations/tracing/vercelai/
Pattern 2: OTel Instrumentation (Client Wrapping)
Use when: SDK has no native OTel support (OpenAI, Anthropic, Google GenAI)
- Core: Create
instrument{Provider}Client()inpackages/core/src/tracing/{provider}/index.ts— Proxy to wrap client methods, create spans manually - Node.js
instrumentation.ts: Patch module exports, wrap client constructor. Check_INTERNAL_shouldSkipAiProviderWrapping()for LangChain compatibility. - Node.js
index.ts: Export integration function usinggenerateInstrumentOnce()helper
Reference: packages/node/src/integrations/tracing/openai/
Pattern 3: Callback/Hook Based
Use when: SDK provides lifecycle hooks (LangChain, LangGraph)
- Core: Create
create{Provider}CallbackHandler()— implement SDK's callback interface, create spans in callbacks - Node.js
instrumentation.ts: Auto-inject callbacks by patching runnable methods. Disable underlying AI provider wrapping.
Reference: packages/node/src/integrations/tracing/langchain/
Auto-Instrumentation (Node.js)
Mandatory for Node.js AI integrations. OTel only patches when the package is imported (zero cost if unused).
Steps
- Add to
getAutoPerformanceIntegrations()inpackages/node/src/integrations/tracing/index.ts— LangChain MUST come first - Add to
getOpenTelemetryInstrumentationToPreload()for OTel-based integrations - Export from
packages/node/src/index.ts: integration function + options type - Add E2E tests:
- Node.js:
dev-packages/node-integration-tests/suites/tracing/{provider}/ - Cloudflare:
dev-packages/cloudflare-integration-tests/suites/tracing/{provider}/ - Browser:
dev-packages/browser-integration-tests/suites/tracing/ai-providers/{provider}/
- Node.js:
Key Rules
- Respect
dataCollection.genAIfor recording input and output messages - Set
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.{provider}'(alphanumerics,_,.only) - Truncate large data with helper functions from
utils.ts gen_ai.invoke_agentfor parent ops,gen_ai.chatfor child ops
Checklist
- Runtime-specific code placed only in that runtime's package
- Added to
getAutoPerformanceIntegrations()in correct order (Node.js) - Added to
getOpenTelemetryInstrumentationToPreload()(Node.js with OTel) - Exported from appropriate package index
- E2E tests added and verifying auto-instrumentation
- Only used attributes from Sentry Gen AI Conventions
- JSDoc says "enabled by default" or "not enabled by default"
- Documented how to disable (if auto-enabled)
- Verified OTel only patches when package imported (Node.js)
Reference Implementations
- Pattern 1 (Span Processors):
packages/node/src/integrations/tracing/vercelai/ - Pattern 2 (Client Wrapping):
packages/node/src/integrations/tracing/openai/ - Pattern 3 (Callback/Hooks):
packages/node/src/integrations/tracing/langchain/
When in doubt, follow the pattern of the most similar existing integration.
Signals
- GitHub stars
- 9k
- Forks
- 2k
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
add-ai-integration- Source
- github.com/getsentry/sentry-javascript