[feat] setup master from fork with fastapi + otel

This commit is contained in:
Azamat 2026-03-26 21:29:41 +03:00
parent 597eae9b97
commit 1fbf77f879
8 changed files with 310 additions and 1 deletions

View file

@ -0,0 +1,17 @@
# 005 Early FastAPI OTel Instrumentation
Context
- HTTP spans and HTTP metrics are provided by FastAPI/ASGI OpenTelemetry middleware.
- Starlette caches `middleware_stack` on first ASGI entry, including lifespan startup.
- Instrumenting FastAPI inside lifespan is too late for the initial middleware stack.
Decision
- Build the application container before returning the FastAPI app from `create_app`.
- Configure FastAPI OpenTelemetry instrumentation in the app factory, not in lifespan.
- Pass the configured tracer and meter providers directly to `FastAPIInstrumentor.instrument_app(...)`.
- Keep lifespan focused on shutdown and resource cleanup.
Consequences
- `OpenTelemetryMiddleware` is present in the runtime stack without manual stack rebuilds.
- HTTP traces and HTTP metrics use the same startup wiring as other singleton adapters.
- Observability bootstrap stays explicit in the outer adapter layer.