---
title: Overview
description: One telemetry path from the server to any back end, and the design targets it serves.
sidebar:
  icon: radar
---

The server speaks one protocol, OTLP. An OpenTelemetry Collector decides where the data goes. Locally that is Prometheus, Jaeger and Grafana. In AWS it is CloudWatch (metrics through the Embedded Metric Format) and X-Ray, with the collector as a sidecar in the ECS task. Logs do not go through the collector: they are JSON lines on stdout, which the `awslogs` driver ships to CloudWatch Logs.

## The telemetry path

```mermaid
flowchart LR
  server["server<br/>OpenTelemetry SDK<br/>server/app/telemetry.py"] -->|"OTLP/HTTP :4318"| col
  server -->|"JSON lines on stdout"| logs
  subgraph local["Local: observability/docker-compose.yml"]
    col["otel-collector<br/>collector/local.yaml"] --> prom["Prometheus<br/>rules.yml: SuggestionFailureBudgetBurn"]
    col --> jaeger[Jaeger]
    prom --> grafana["Grafana<br/>Patent server: suggestions"]
    jaeger --> grafana
  end
  subgraph aws["AWS: sidecar in the ECS task"]
    adot["otel-collector (ADOT)<br/>collector/aws.yaml"] -->|EMF| cw["CloudWatch metric<br/>Patent/Server suggestions.requests"]
    adot --> xray[X-Ray]
    cw --> alarm["alarm: name-suggestion-failure-ratio"]
    alarm --> sns[SNS alarm topic]
    alarm --> ecs[ECS deployment rollback]
  end
  server -.->|"same image, OTLP to localhost:4318"| adot
  logs["CloudWatch Logs<br/>/ecs/name-server"]
```

## Design targets

| Design target | Mechanism | Where |
|---|---|---|
| Catch a failure before users report it | One burn-rate alert on the failure ratio of AI suggestion requests. In AWS the same metric drives a CloudWatch alarm that also rolls back a release. | `observability/prometheus/rules.yml`, `infrastructure/modules/service/alarms.tf` |
| See how the service performs and how it is used | Request rate by outcome, p50 and p95 duration, requests in flight, open WebSocket connections, on one dashboard. These are counts and timings, not product analytics. | `server/app/telemetry.py`, `observability/grafana/dashboards/suggestions.json` |
| Telemetry that is safe to keep | Audit events for document reads and saves. Telemetry never carries document text, and a test enforces it. The collector's AWS permissions only write telemetry. | `server/app/telemetry.py`, `server/tests/test_telemetry.py`, `infrastructure/modules/service/iam.tf` |
| Find the cause of one failed request fast | One trace per suggestion request, with the OpenAI call as a child span. Every log line carries the trace ID. | `server/app/telemetry.py` |
| Response times for every route | The duration histogram, plus HTTP server spans and metrics from the FastAPI instrumentation. | `server/app/telemetry.py` |
| Silent failures become visible | The WebSocket handler used to `print` the error and carry on: no 5xx, a passing health check, nothing to see. Every suggestion request now ends in exactly one `outcome`. | `server/app/__main__.py` |
| A record of who read or saved a document | `audit.document.read` and `audit.document.saved`. The AWS account trail (CloudTrail and the rest) is not built. See [Logging and audit trail](/logging). | `server/app/telemetry.py` |
| Logs and traces that join up | Traces and logs joined by `trace_id`; failures carry the exception type. | `server/app/telemetry.py` |

## Why OpenTelemetry

The same server image runs on a laptop, in AWS, and could run in a customer's environment with a different back end. Only the collector config changes:

| Config | Back end | Status |
|---|---|---|
| `observability/collector/local.yaml` | Prometheus and Jaeger | Run and proven locally |
| `observability/collector/aws.yaml` | CloudWatch (EMF) and X-Ray | The production default. Validated in CI, not run in AWS |
| `observability/collector/datadog.yaml` | Datadog | An option. Validated in CI, not deployed |

Hands-on experience behind this design is with Prometheus, Grafana and the OpenTelemetry Collector. The CloudWatch and X-Ray side follows the AWS and exporter documentation and has not been run against an account.

## Run it locally

The telemetry services are in `observability/docker-compose.yml`, which the root `docker-compose.yml` includes under the Compose profile `observability`. Two variables switch them on:

```bash
COMPOSE_PROFILES=observability \
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 \
docker compose up --build
```

Without them, `docker compose up --build` runs only the app, and the server exports nothing.

| What | URL |
|---|---|
| Grafana dashboard | http://localhost:3001/d/patent-suggestions |
| Prometheus alerts | http://localhost:9090/alerts |
| Jaeger | http://localhost:16686 |
| Collector (OTLP/HTTP) | http://localhost:4318 |

**[The implemented example](/alerting-example)**

The indicator, the alert in two forms, and the measured run.

**[Incident response](/incident-response)**

Severity, paging, and the runbook for the alert.
