Use when adding error tracking, monitoring, or observability to a Gemini or AI application, setting up Sentry for error tracking or Datadog for metrics and APM
Add production monitoring to Gemini API applications. Sentry for error tracking and crash reporting; Datadog for metrics, APM, and dashboards. Can use one or both.
When NOT to use: For local development debugging.
| Need | Sentry | Datadog |
|---|---|---|
| Error tracking | Excellent | Good |
| APM / Traces | Good | Excellent |
| Custom metrics | Limited |
| Excellent |
| Free tier | 5K errors/mo | 14-day trial |
| Setup effort | 5 min | 15 min |
| Best for | "Just tell me when it breaks" | "I need dashboards and deep metrics" |
Recommendation: Start with Sentry (fast setup, free tier). Add Datadog when you need metrics/dashboards.
# pip install sentry-sdk
import sentry_sdk
sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
traces_sample_rate=0.1,
environment=os.environ.get("ENVIRONMENT", "production"),
)
// npm install @sentry/node
const Sentry = require("@sentry/node");
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0.1,
environment: process.env.ENVIRONMENT || "production",
});
| Metric | Why |
|---|---|
| Gemini API latency | Detect slowdowns |
| Token usage per request | Cost monitoring |
| Error rate by endpoint | Identify failing routes |
| Rate limit hits (429s) | Capacity planning |
| Response quality scores | If using evals |
traces_sample_rate=1.0 in production — Sample at 0.1 or lower to control costsenvironment to distinguish staging/productiongoogle.api_core.exceptions explicitly