- Python 3.14
- FastAPI
- Developer Testing with Pytest
- API testing with Postman
- MySQL Connector/Python
docker compose up --buildCreate an employee at http://localhost:8000/api/employees:
curl -X POST http://localhost:8000/api/employees \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john.doe@example.com","position":"Software Engineer"}'cd api
pytestThe API tests replace the repository dependency with a mock, so they cover the controller and service without requiring a running MySQL instance.
The api service is auto-instrumented with OpenTelemetry (opentelemetry-instrument)
and exports traces, metrics, and logs over OTLP gRPC to the otel-collector service,
which prints all three signals to its own console output via a debug exporter.
View the exported telemetry:
docker compose logs -f otel-collectorGenerate telemetry with a request that succeeds and one that fails:
curl -X POST http://localhost:8000/api/employees \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john.doe@example.com","position":"Software Engineer"}'
curl -X POST http://localhost:8000/api/employees \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"invalid","position":"Software Engineer"}'The collector logs should show trace spans and metric data points for both
requests, and an error log record for the failing one, all tagged with
service.name=employee-api.
docker-compose-otel.yml extends the base stack so the collector fans out
traces to Tempo, metrics to Prometheus, and logs to Loki (in addition to its
console output), and adds Grafana with those three data sources pre-provisioned:
docker compose -f docker-compose.yml -f docker-compose-otel.yml up --build- Grafana:
http://localhost:3000(anonymous access, Admin role) - Prometheus:
http://localhost:9090 - Tempo API:
http://localhost:3200 - Loki API:
http://localhost:3100
In Grafana, use Explore with the Prometheus, Tempo, or Loki data source to query the telemetry generated by the requests above.