add-ai-integration

作成者: sentry

Sentry JavaScript SDKに新しいAIプロバイダー統合を追加します。新しいAIインストルメンテーション(OpenAI、Anthropic、Vercel AI、LangChainなど)を貢献する際に使用します…

npx skills add https://github.com/getsentry/sentry-javascript --skill add-ai-integration

Adding a New AI Integration

Conventions First

Span ops and attributes are specified outside this repo. Never invent or hardcode either:

Derive the op with getGenAiSpanOp() from ai/core/utils.ts rather than picking one by hand. ai/core/gen-ai-attributes.ts is for gap-fillers only — keys with no @sentry/conventions equivalent — so check it last, not first.

Which Pattern

Does the SDK publish its own `diagnostics_channel` telemetry?
|- YES (ai >= 7) -> Pattern 1: Native tracing channel
+- NO -> Does the SDK expose callback/exporter hooks?
    |- YES (LangChain, Mastra) -> Pattern 3: Callback/Exporter
    +- NO (OpenAI, Anthropic, Google GenAI, ai < 7) -> Pattern 2: Orchestrion-injected channels
PatternUse whenReference
1 — Native tracing channelthe SDK publishes to diagnostics_channelintegrations/vercel-ai/vercel-ai-dc-subscriber.ts
2 — Orchestrion channelsthe SDK has no telemetry of its ownintegrations/openai.ts + orchestrion/config/openai.ts
3 — Callback/exporterthe SDK exposes hooks or an exporterai/langchain/, ai/mastra/ (exporter-shaped agent framework)

What the reference files won't tell you:

  • A provider can need two patterns at once: vercelAIIntegration subscribes to native ai:telemetry for ai >= 7 and runs orchestrion injection for v4-v6.
  • Pattern 1 subscribers are safe to register unconditionally — subscribing is a no-op on SDK versions that never publish.

Where The Code Goes

  • Instrumentation -> packages/server-utils/src/ai/{provider}/
  • Integration -> packages/server-utils/src/integrations/{provider}.ts
  • Runtime packages (node, cloudflare, bun, ...) re-export from @sentry/server-utils — they never define their own
  • Exception: Workers AI is client-wrapped in packages/cloudflare/src/instrumentations/worker/instrumentEnv.ts

Gotchas

  1. Detect streaming from the result shape — an async-iterable or the SDK's stream object — not from params.stream. Only the manual instrument{Provider}Client() API keys off params.stream === true.
  2. Never set streamed response attributes by hand. Accumulate into a StreamResponseState and call endStreamSpan() (ai/openai/streaming.ts for an async generator, ai/anthropic-ai/streaming.ts for a listener-based stream).
  3. Never truncate message payloads. Truncation was removed in v11 (#23045) and nothing downstream caps them; size limiting is server-side.
  4. Never roll child token usage up onto parent spans. Tree totals are computed product-side from the full span tree.
  5. Never read dataCollection.genAI directly. Gate input/output recording on resolveAIRecordingOptions().
  6. LangChain must be registered first in getTracingIntegrations(), so it can disable the provider integrations before they instrument.
  7. Set SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.{provider}' (alphanumerics, _, . only).

Checklist

  • Instrumentation in src/ai/, integration in src/integrations/, registered in getTracingIntegrations() (LangChain first)
  • Exported from packages/server-utils/src/index.ts, re-exported from the supported runtime packages
  • E2E tests in dev-packages/node-integration-tests/suites/tracing/{provider}/ (and cloudflare-integration-tests/ if supported)
  • Ops and attributes from @sentry/conventions, op derived via getGenAiSpanOp()
  • Recording gated on resolveAIRecordingOptions(); no truncation, no token rollup
  • JSDoc names the channels subscribed to, the supported SDK versions, and — for Pattern 2 — that it requires the Sentry runtime hook or bundler plugin
  • Patching happens only once the target package is imported (zero cost if unused)

When in doubt, follow the pattern of the most similar existing integration.

sentryのその他のスキル

architecture-review
sentry
スタッフレベルのコードベースヘルスレビュー。モノリシックモジュール、サイレント障害、型安全性のギャップ、テストカバレッジの穴、LLMフレンドリー性の問題を発見します。
pi-agent-integration
sentry
Integrate `@mariozechner/pi-agent-core` as the agent abstraction inside another library or runtime. Use when implementing or refactoring Pi Agent wrappers,…
sentry-debug-issue
sentry
Sentryの課題をデバッグして修正する — (リンク、ID、検索で)課題を見つけ、完全なコンテキスト(スタックトレース、ブレッドクラム、トレース、ログ)を取得し、必要に応じてSeerの根本原因分析を実行…
sentry-svelte-sdk
sentry
SvelteおよびSvelteKit向けの完全なSentry SDKセットアップ。「SvelteにSentryを追加」「SvelteKitにSentryを追加」「@sentry/sveltekitをインストール」または設定を求められた場合に使用します。
sentry-svelte-sdk
sentry
SvelteおよびSvelteKit向けの完全なSentry SDKセットアップ。「SvelteにSentryを追加」「SvelteKitにSentryを追加」「@sentry/sveltekitをインストール」、または設定を求められた場合に使用します。
skill-scanner
sentry
エージェントスキルをセキュリティ問題についてスキャンします。「スキルをスキャンして」と依頼されたときに使用します。
prompt-optimizer
sentry
エージェントプロンプト、システムプロンプト、開発者プロンプト、再利用可能なプロンプトテンプレートを作成、最適化、反復的に改良します。改善を求められた際に使用します…
commit
sentry
commit — getsentry/sentry-docs が公開する、AIエージェント向けのインストール可能なスキルです。