Skip to content

Repository files navigation

Workshop with Python

  • Python 3.14
  • FastAPI
  • Developer Testing with Pytest
  • API testing with Postman
  • MySQL Connector/Python

Run

docker compose up --build

Create 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"}'

Test

cd api
pytest

The API tests replace the repository dependency with a mock, so they cover the controller and service without requiring a running MySQL instance.

Observability

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-collector

Generate 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.

Full stack with Grafana, Prometheus, Tempo, and Loki

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages