
Add Ai Integration
- 12 installs
- 8.7k repo stars
- Updated August 4, 2026
- getsentry/sentry-javascript
add-ai-integration adds AI provider tracing to sentry-javascript.
About
The add-ai-integration skill walks contributing new AI tracing for providers like OpenAI, Anthropic, Vercel AI, or LangChain. Decision tree picks Pattern 1 OTel span processors when native OTel exists, Pattern 2 client wrapping instrumentation, Pattern 3 callback handlers, or Pattern 4 manual proxies. Runtime-specific code stays in node, cloudflare, or browser packages only, not core when single-runtime. Span hierarchy uses gen_ai.invoke_agent parents and gen_ai.chat children with attributes from gen-ai-attributes.ts never hardcoded strings. Streaming uses startSpanManual with finally end. Node auto-instrumentation requires getAutoPerformanceIntegrations ordering with LangChain first plus E2E suites per runtime. Decision tree selects OTel, wrap, callback, or proxy pattern. Runtime-specific code stays in that runtime package. Uses Sentry gen_ai semantic attribute constants only. Streaming spans use startSpanManual and finally end. Checklist covers auto-instrumentation and E2E tests. Integration with spans, auto-instrumentation, and E2E coverage.
- Decision tree selects OTel, wrap, callback, or proxy pattern.
- Runtime-specific code stays in that runtime package.
- Uses Sentry gen_ai semantic attribute constants only.
- Streaming spans use startSpanManual and finally end.
- Checklist covers auto-instrumentation and E2E tests.
Add Ai Integration by the numbers
- 12 all-time installs (skills.sh)
- Ranked #11,618 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
add-ai-integration capabilities & compatibility
- Capabilities
- decision tree patterns · span hierarchy rules · checklist auto instrumentation
- Works with
- sentry · openai · anthropic
- Use cases
- api development
What add-ai-integration says it does
Does the AI SDK have native OpenTelemetry support?
gen_ai.invoke_agent
npx skills add https://github.com/getsentry/sentry-javascript --skill add-ai-integrationAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 12 |
|---|---|
| repo stars | ★ 8.7k |
| Last updated | August 4, 2026 |
| Repository | getsentry/sentry-javascript ↗ |
How do I add AI instrumentation to Sentry JS SDK?
Add AI provider instrumentation to Sentry JavaScript SDK using OTel, wrapping, or callback patterns.
Who is it for?
sentry-javascript contributors adding gen_ai tracing.
Skip if: Skip for unrelated non-AI SDK packages.
When should I use this skill?
User adds or modifies AI provider integration in sentry-javascript.
What you get
Integration with spans, auto-instrumentation, and E2E coverage.
Files
Adding a New AI Integration
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 WrappingRuntime-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 (see
vercel-ai/)
Pattern 1: OTel Span Processors
Use when: SDK emits OTel spans automatically (Vercel AI)
1. Core: Create add{Provider}Processors() in packages/core/src/tracing/{provider}/index.ts — registers spanStart listener + event processor 2. Node.js: Add callWhenPatched() optimization in packages/node/src/integrations/tracing/{provider}/index.ts — defers registration until package is imported 3. 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)
1. Core: Create instrument{Provider}Client() in packages/core/src/tracing/{provider}/index.ts — Proxy to wrap client methods, create spans manually 2. Node.js `instrumentation.ts`: Patch module exports, wrap client constructor. Check _INTERNAL_shouldSkipAiProviderWrapping() for LangChain compatibility. 3. Node.js `index.ts`: Export integration function using generateInstrumentOnce() helper
Reference: packages/node/src/integrations/tracing/openai/
Pattern 3: Callback/Hook Based
Use when: SDK provides lifecycle hooks (LangChain, LangGraph)
1. Core: Create create{Provider}CallbackHandler() — implement SDK's callback interface, create spans in callbacks 2. 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
1. Add to `getAutoPerformanceIntegrations()` in packages/node/src/integrations/tracing/index.ts — LangChain MUST come first 2. Add to `getOpenTelemetryInstrumentationToPreload()` for OTel-based integrations 3. Export from `packages/node/src/index.ts`: integration function + options type 4. 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}/
Key Rules
1. Respect sendDefaultPii for recordInputs/recordOutputs 2. Set SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.{provider}' (alphanumerics, _, . only) 3. Truncate large data with helper functions from utils.ts 4. gen_ai.invoke_agent for parent ops, gen_ai.chat for 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.
Related skills
FAQ
What does add-ai-integration do?
add-ai-integration adds AI provider tracing to sentry-javascript.
When should I use add-ai-integration?
User adds or modifies AI provider integration in sentry-javascript.
Is this skill safe to install?
Review the Security Audits panel on this page before installing in production.