OpenTelemetry — Traces and Correlation
What and where
- Code:
ms_bff_spike/ms_bff/src/observability/telemetry.py(primary) andms_bff_spike/ms_bff/src/observability.py(compat path) configure OpenTelemetry exporters and auto‑instrumentation for FastAPI, httpx, and Redis. - Collector: defined in
CRUDService/docker-compose-authzen4.ymlasotel-collectorexposing OTLP gRPC4317and OTLP HTTP4318. Vector can forward traces to Jaeger.
How it’s configured
- Enablement:
TELEMETRY_ENABLED=true(default) turns tracing/metrics on in the BFF when OTEL libs are present. - Exporter endpoint (BFF picks the first that is set):
OTLP_ENDPOINT(preferred intelemetry.py, e.g.,http://otel-collector:4317)OTEL_EXPORTER_OTLP_ENDPOINT(alternate, supported byobservability.py)
- Resource attributes:
service.name=bff-auth-service, plusservice.versionfromBFF_VERSIONanddeployment.environmentfromENVIRONMENT(see../reference/settings-reference.md#core-runtime).
Minimal setup (compose)
# CRUDService/docker-compose-authzen4.yml (excerpt)
otel-collector:
image: otel/opentelemetry-collector-contrib:0.96.0
ports: ["4317:4317", "4318:4318"]
volumes:
- ./otel-collector-config.yaml:/etc/otelcol/config.yaml:ro
# BFF service (env excerpt)
environment:
- TELEMETRY_ENABLED=true
- OTLP_ENDPOINT=http://otel-collector:4317
- BFF_VERSION=1.0.0
- ENVIRONMENT=development
What gets instrumented
- FastAPI requests (
/auth/*,/api/*), httpx client calls (IdP, PDP, backends), and Redis calls create spans automatically. - Manual spans and metrics are available via helpers:
start_span,record_forwardauth_metrics,record_session_metrics.
Flow
How to verify
- Start the stack with the collector; set
OTLP_ENDPOINTin the BFF env. - Hit
/auth/loginthen any/api/**route; you should see spans in Jaeger. - Check logs for connection messages from telemetry setup.
References
- Reference → Observability (Metrics, Tracing, Health)
- Reference → Core runtime settings:
../reference/settings-reference.md#core-runtime - Code:
ms_bff_spike/ms_bff/src/observability/telemetry.py,ms_bff_spike/ms_bff/src/observability.py