How gaursaru/observability-lab works
Purpose and Entry Points
This repository is an observability lab centered on a Flask checkout-api. It demonstrates Datadog APM, custom metrics, structured log correlation, SLO-driven alerting, and optional AWS deployment.
Primary entry points:
• Service runtime: app/app.py
• Local stack orchestration: docker-compose.yml
• Datadog observability resources: terraform/datadog/main.tf
• AWS deployment: terraform/aws/main.tf
• SLO/deploy-gate automation: scripts/slo_report.py
Checkout API and OAuth Boundary
app/app.py is the application boundary. It exposes checkout behavior, intentionally injects failures for error-budget demonstrations, and implements GitHub OAuth endpoints (/login, /callback).
GitHub is an external identity provider. OAuth client credentials and Flask session secret are supplied through environment variables rather than embedded in application code.
Telemetry Emission
The Flask process emits all three telemetry pillars:
• ddtrace auto-instruments Flask requests and sends traces to the Datadog Agent.
• DogStatsD emits custom request and latency metrics.
• Structured JSON application logs carry trace identifiers for log-to-trace correlation.
Relevant runtime dependencies are defined in app/requirements.txt; the image boundary is app/Dockerfile.
Local Runtime and Datadog Agent
docker-compose.yml composes the application, Datadog Agent, and traffic/load generation. The Agent is the local telemetry collection boundary: the app sends APM traces and DogStatsD metrics to it, while it collects logs and forwards telemetry to Datadog SaaS.
Datadog API credentials and site selection determine the remote account/region endpoint.
Datadog as Code
terraform/datadog/main.tf provisions the operational control plane in Datadog: an SLO, burn-rate monitor, and RED-oriented dashboard. These resources consume the service’s emitted metrics and make reliability state visible and alertable.
The monitor’s error-budget policy is deliberately aligned with the application’s injected failure rate, allowing a live alert/burn demonstration.
SLO Reporting and Deployment Gate
scripts/slo_report.py queries Datadog using API/application credentials, calculates error-budget burn against a requested SLO target, and can act as a deployment gate. This separates operational policy evaluation from service request handling and is suitable for invocation from CI/CD after traffic data exists.
Optional AWS Infrastructure
terraform/aws/main.tf defines the optional AWS execution environment, intended to run the Dockerized stack on EC2. The AWS module is infrastructure provisioning only; observability remains routed through the Datadog Agent and Datadog service.
The repository therefore supports two execution paths: local Docker Compose for rapid demonstrations and Terraform-managed EC2 for cloud deployment.
Main entry points: app.py Checkout API · docker-compose.yml Datadog Agent · Dockerfile API Image · main.tf AWS EC2 Stack
Components 17
Service Runtime
- Docker Compose · Runs the local demo stack.
docker-compose.yml - Checkout API · Checkout behavior, injected failures, and OAuth endpoints.
app/app.py - API Image
app/Dockerfile - Runtime Dependencies · Includes Flask, ddtrace, and DogStatsD client dependencies.
app/requirements.txt - Traffic Generator · Generates traffic for live reliability demonstrations.
docker-compose.yml - Datadog Agent · Receives traces and metrics, collects logs, and forwards telemetry.
docker-compose.yml
Datadog Platform
- Datadog SaaS · Remote account and site selected by credentials.
- APM Traces
- Custom Metrics · Request and latency metrics.
- Correlated Logs · Logs include trace identifiers.
- SLO, Monitor & Dashboard · SLO, burn-rate alerting, and RED dashboard.
terraform/datadog/main.tf
Infrastructure & Automation
- Datadog Terraform · Provisions reliability controls.
terraform/datadog/main.tf - SLO Report & Deploy Gate · Queries error-budget burn for CI/CD gating.
scripts/slo_report.py - AWS Terraform · Provisions optional EC2 execution environment.
terraform/aws/main.tf - AWS EC2 Stack · Optional host for the Dockerized stack.
terraform/aws/main.tf
Other components
- GitHub · OAuth identity boundary.
- Environment Secrets · Supplies OAuth, session, and Datadog credentials.
Connections 19
- Docker Compose → Checkout API: runs
- Docker Compose → Datadog Agent: runs
- Docker Compose → Traffic Generator: runs
- API Image → Checkout API: packages
- Runtime Dependencies → API Image: installed in
- Traffic Generator → Checkout API: sends requests
- Checkout API → GitHub: OAuth login and callback
- Environment Secrets → Checkout API: supplies secrets
- Checkout API → Datadog Agent: traces and DogStatsD
- Datadog Agent → Datadog SaaS: forwards telemetry
- Datadog SaaS → APM Traces: stores
- Datadog SaaS → Custom Metrics: stores
- Datadog SaaS → Correlated Logs: stores
- Datadog Terraform → SLO, Monitor & Dashboard: provisions
- Custom Metrics → SLO, Monitor & Dashboard: drives SLO and burn rate
- Datadog SaaS → SLO Report & Deploy Gate: queried by
- AWS Terraform → AWS EC2 Stack: provisions
- AWS EC2 Stack → API Image: runs
- Environment Secrets → Datadog Agent: supplies API credentials