# gaursaru/observability-lab architecture

> Architecture diagram of the GitHub repository gaursaru/observability-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gaursaru/observability-lab
- Repository: https://github.com/gaursaru/observability-lab

## Overview

#### 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/app.py`](https://github.com/gaursaru/observability-lab/blob/main/app/app.py) (Checkout API), [`docker-compose.yml`](https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml) (Datadog Agent), [`app/Dockerfile`](https://github.com/gaursaru/observability-lab/blob/main/app/Dockerfile) (API Image), [`terraform/aws/main.tf`](https://github.com/gaursaru/observability-lab/blob/main/terraform/aws/main.tf) (AWS EC2 Stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Service Runtime"]
  node_compose{{"Docker Compose<br/>local orchestration<br/>[docker-compose.yml]"}}
  node_checkout_api["Checkout API<br/>Flask service<br/>[app.py]"]
  node_container_image["API Image<br/>container build"]
  node_runtime_dependencies["Runtime Dependencies<br/>Python dependencies<br/>[requirements.txt]"]
  node_traffic_generator["Traffic Generator<br/>load generation<br/>[docker-compose.yml]"]
  node_datadog_agent{{"Datadog Agent<br/>telemetry collector<br/>[docker-compose.yml]"}}
end

subgraph group_datadog["Datadog Platform"]
  node_datadog_saas(("Datadog SaaS<br/>observability service"))
  node_apm_traces["APM Traces<br/>request telemetry"]
  node_custom_metrics["Custom Metrics<br/>DogStatsD telemetry"]
  node_correlated_logs["Correlated Logs<br/>structured JSON logs"]
  node_reliability_controls["SLO, Monitor &amp; Dashboard<br/>operational controls<br/>[main.tf]"]
end

subgraph group_automation["Infrastructure &amp; Automation"]
  node_datadog_iac["Datadog Terraform<br/>observability IaC<br/>[main.tf]"]
  node_slo_gate["SLO Report &amp; Deploy Gate<br/>policy automation<br/>[slo_report.py]"]
  node_aws_iac["AWS Terraform<br/>infrastructure IaC<br/>[main.tf]"]
  node_aws_ec2["AWS EC2 Stack<br/>cloud execution environment<br/>[main.tf]"]
end

node_github(("GitHub<br/>external identity provider"))
node_environment["Environment Secrets<br/>runtime configuration"]

node_compose -->|"runs"| node_checkout_api
node_compose -->|"runs"| node_datadog_agent
node_compose -->|"runs"| node_traffic_generator
node_container_image -->|"packages"| node_checkout_api
node_runtime_dependencies -->|"installed in"| node_container_image
node_traffic_generator -->|"sends requests"| node_checkout_api
node_checkout_api -->|"OAuth login and callback"| node_github
node_environment -.->|"supplies secrets"| node_checkout_api
node_checkout_api -->|"traces and DogStatsD"| node_datadog_agent
node_datadog_agent -->|"forwards telemetry"| node_datadog_saas
node_datadog_saas -->|"stores"| node_apm_traces
node_datadog_saas -->|"stores"| node_custom_metrics
node_datadog_saas -->|"stores"| node_correlated_logs
node_datadog_iac -->|"provisions"| node_reliability_controls
node_custom_metrics -->|"drives SLO and burn rate"| node_reliability_controls
node_datadog_saas -->|"queried by"| node_slo_gate
node_aws_iac -->|"provisions"| node_aws_ec2
node_aws_ec2 -->|"runs"| node_container_image
node_environment -.->|"supplies API credentials"| node_datadog_agent

click node_compose "https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml"
click node_checkout_api "https://github.com/gaursaru/observability-lab/blob/main/app/app.py"
click node_container_image "https://github.com/gaursaru/observability-lab/blob/main/app/Dockerfile"
click node_runtime_dependencies "https://github.com/gaursaru/observability-lab/blob/main/app/requirements.txt"
click node_traffic_generator "https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml"
click node_datadog_agent "https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml"
click node_datadog_iac "https://github.com/gaursaru/observability-lab/blob/main/terraform/datadog/main.tf"
click node_reliability_controls "https://github.com/gaursaru/observability-lab/blob/main/terraform/datadog/main.tf"
click node_slo_gate "https://github.com/gaursaru/observability-lab/blob/main/scripts/slo_report.py"
click node_aws_iac "https://github.com/gaursaru/observability-lab/blob/main/terraform/aws/main.tf"
click node_aws_ec2 "https://github.com/gaursaru/observability-lab/blob/main/terraform/aws/main.tf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_compose,node_checkout_api,node_container_image,node_runtime_dependencies,node_traffic_generator,node_datadog_agent toneBlue
class node_datadog_saas,node_apm_traces,node_custom_metrics,node_correlated_logs,node_reliability_controls toneAmber
class node_datadog_iac,node_slo_gate,node_aws_iac,node_aws_ec2 toneMint
class node_github,node_environment toneNeutral
```

## Components

### Service Runtime

- [Docker Compose](https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml): local orchestration · Runs the local demo stack. · `docker-compose.yml`
- [Checkout API](https://github.com/gaursaru/observability-lab/blob/main/app/app.py): Flask service · Checkout behavior, injected failures, and OAuth endpoints. · `app/app.py`
- [API Image](https://github.com/gaursaru/observability-lab/blob/main/app/Dockerfile): container build · `app/Dockerfile`
- [Runtime Dependencies](https://github.com/gaursaru/observability-lab/blob/main/app/requirements.txt): Python dependencies · Includes Flask, ddtrace, and DogStatsD client dependencies. · `app/requirements.txt`
- [Traffic Generator](https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml): load generation · Generates traffic for live reliability demonstrations. · `docker-compose.yml`
- [Datadog Agent](https://github.com/gaursaru/observability-lab/blob/main/docker-compose.yml): telemetry collector · Receives traces and metrics, collects logs, and forwards telemetry. · `docker-compose.yml`

### Datadog Platform

- **Datadog SaaS**: observability service · Remote account and site selected by credentials.
- **APM Traces**: request telemetry
- **Custom Metrics**: DogStatsD telemetry · Request and latency metrics.
- **Correlated Logs**: structured JSON logs · Logs include trace identifiers.
- [SLO, Monitor & Dashboard](https://github.com/gaursaru/observability-lab/blob/main/terraform/datadog/main.tf): operational controls · SLO, burn-rate alerting, and RED dashboard. · `terraform/datadog/main.tf`

### Infrastructure & Automation

- [Datadog Terraform](https://github.com/gaursaru/observability-lab/blob/main/terraform/datadog/main.tf): observability IaC · Provisions reliability controls. · `terraform/datadog/main.tf`
- [SLO Report & Deploy Gate](https://github.com/gaursaru/observability-lab/blob/main/scripts/slo_report.py): policy automation · Queries error-budget burn for CI/CD gating. · `scripts/slo_report.py`
- [AWS Terraform](https://github.com/gaursaru/observability-lab/blob/main/terraform/aws/main.tf): infrastructure IaC · Provisions optional EC2 execution environment. · `terraform/aws/main.tf`
- [AWS EC2 Stack](https://github.com/gaursaru/observability-lab/blob/main/terraform/aws/main.tf): cloud execution environment · Optional host for the Dockerized stack. · `terraform/aws/main.tf`

### Other components

- **GitHub**: external identity provider · OAuth identity boundary.
- **Environment Secrets**: runtime configuration · Supplies OAuth, session, and Datadog credentials.

## Connections

- 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
