Production-Grade Observability for LLM Applications on Google Vertex AI
SentinelLLM is a FastAPI gateway that instruments LLM requests to Google Gemini (Vertex AI) with comprehensive OpenTelemetry observability and Datadog integration.
LLM applications fail in non-obvious ways. SentinelLLM makes these failures visible:
- Hallucinations — Confident but incorrect responses
- Prompt injection attacks — Malicious users manipulating the AI
- Silent latency regressions — Performance degradation over time
- Runaway token costs — Unexpected budget overruns
- Sensitive data leakage — PII exposure in responses
┌─────────────┐ ┌─────────────────────┐ ┌──────────────────┐
│ Client │────▶│ SentinelLLM │────▶│ Vertex AI │
│ (cURL/API) │ │ FastAPI Gateway │ │ Gemini 2.0 │
└─────────────┘ └─────────────────────┘ └──────────────────┘
│
▼
┌──────────────┐
│OpenTelemetry │
└──────────────┘
│
▼
┌──────────────┐ ┌──────────────────┐
│ Datadog │────▶│ APM Dashboards │
│ Agent │ │ & Alerts │
└──────────────┘ └──────────────────┘
- Request — Client sends prompt to gateway
- Instrumentation — OpenTelemetry span starts
- LLM Call — Request to Vertex AI Gemini
- Response — Response parsed with token counts
- Telemetry — Metrics sent to Datadog Agent
- Monitoring — Traces appear in Datadog APM
| Feature | Description |
|---|---|
| Request Tracing | Every LLM call creates a distributed trace |
| Token Monitoring | Input/output token counts per request |
| Latency Tracking | P50/P95 latency with percentiles |
| Cost Estimation | Per-request cost based on token usage |
| Prompt Injection Detection | Security monitoring for attacks |
| Layer | Technology |
|---|---|
| Language | Python 3.11+ |
| Framework | FastAPI |
| LLM Provider | Google Vertex AI (Gemini 2.0) |
| Observability | OpenTelemetry |
| Monitoring | Datadog APM |
| Containerization | Docker |
git clone <repository-url>
cd sentinel-llm
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt# Google Cloud (required)
export GCP_PROJECT_ID=<your-project-id>
export VERTEX_LOCATION=us-central1
export GEMINI_MODEL=gemini-2.0-flash
export GOOGLE_APPLICATION_CREDENTIALS=<path-to-credentials>
# Datadog (optional for local dev)
export DD_SERVICE=sentinelllm
export DD_ENV=development
export DD_TRACE_ENABLED=true# With Datadog tracing
ddtrace-run python -m uvicorn src.main:app --host 0.0.0.0 --port 8080
# Without Datadog (console output only)
python -m uvicorn src.main:app --host 0.0.0.0 --port 8080# Generate text
curl -X POST http://localhost:8080/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Explain zero trust security in 2 sentences"}'
# Health check
curl http://localhost:8080/healthGenerate text using Gemini with full observability.
Request:
{
"prompt": "Your prompt here",
"max_tokens": 100,
"temperature": 0.7
}Response:
{
"text": "Generated response...",
"input_tokens": 25,
"output_tokens": 45,
"latency_ms": 1234.5,
"cost_estimate": 0.00125,
"model": "gemini-2.0-flash"
}Returns service health status.
- Navigate to APM → Traces
- Filter by service:
sentinel-llm - Search:
env:development service:sentinel-llm
- Navigate to Metrics → Metrics Explorer
- Query:
sentinel_llm.request.count - Filter:
service:sentinel-llm env:development
| Metric | Description |
|---|---|
sentinel_llm.request.latency |
Request duration (ms) |
sentinel_llm.tokens.input |
Input tokens per request |
sentinel_llm.tokens.output |
Output tokens per request |
sentinel_llm.cost.estimate |
Estimated cost (USD) |
sentinel-llm/
├── src/
│ ├── main.py # FastAPI application entry point
│ ├── api/
│ │ └── routes.py # API endpoints
│ ├── gateway/
│ │ ├── llm_client.py # Vertex AI Gemini client
│ │ ├── config.py # Settings management
│ │ └── telemetry.py # OpenTelemetry instrumentation
│ └── utils/
│ └── token_counter.py # Token estimation
├── requirements.txt
├── Dockerfile
└── README.md
- Real Production Problem — LLM observability is critical for enterprise adoption
- Clean Architecture — FastAPI gateway with clear separation of concerns
- Strong Observability Story — OpenTelemetry → Datadog APM integration
- Working Demo — End-to-end system that traces real Gemini requests
- Production-Ready — Structured logging, metrics, and distributed tracing
This project is licensed under the MIT License.