Setup Sentry AI Agent Monitoring
Configure Sentry to track LLM calls, agent executions, tool usage, and token consumption.
Invoke This Skill When
- User asks to "monitor AI/LLM calls" or "track OpenAI/Anthropic usage"
- User wants "AI observability" or "agent monitoring"
- User asks about token usage, model latency, or AI costs
Important: The SDK versions, API names, and code samples below are examples. Always verify against docs.sentry.io before implementing, as APIs and minimum versions may have changed.
Prerequisites
AI monitoring requires tracing enabled (tracesSampleRate > 0).
Data Capture Warning
Prompt and output recording captures user content that is likely PII. Before enabling recordInputs/recordOutputs (JS) or include_prompts/send_default_pii (Python), confirm:
- The application's privacy policy permits capturing user prompts and model responses
- Captured data complies with applicable regulations (GDPR, CCPA, etc.)
- Sentry data retention settings are appropriate for the sensitivity of the data
Ask the user whether they want prompt/output capture enabled. Do not enable it by default — configure it only when explicitly requested or confirmed. Use tracesSampleRate: 1.0 only in development; in production, use a lower value or a tracesSampler function.
Detection First
Always detect installed AI SDKs before configuring:
Supported SDKs
JavaScript
*Vercel AI: 10.6.0+ for Node.js, Cloudflare Workers, Vercel Edge Functions, Bun. 10.12.0+ for Deno. Requires experimental_telemetry per-call.
Python
Integrations auto-enable when the AI package is installed — no explicit registration needed:
JavaScript Configuration
Node.js — auto-enabled integrations
Just ensure tracing is enabled. Integrations auto-enable when the AI package is installed:
To customize (e.g., enable prompt capture — see Data Capture Warning):
Browser / Next.js OpenAI (manual wrapping required)
In browser-side code or Next.js meta-framework apps, auto-instrumentation is not available. Wrap the client manually:
LangChain / LangGraph (auto-enabled)
Vercel AI SDK
Add to sentry.edge.config.ts for Edge runtime:
Enable telemetry per-call:
Python Configuration
Integrations auto-enable — just init with tracing. Only add explicit imports to customize options:
Manual Instrumentation
Use when no supported SDK is detected.
Span Types
Example (JavaScript)
Key Attributes
Enable prompt/output capture only after confirming with the user (see Data Capture Warning above).
Verification
After configuring, make an LLM call and check the Sentry Traces dashboard. AI spans appear with gen_ai.* operations showing model, token counts, and latency.


