Observability architecture¶
Three facets, one module tree at src/bqemulator/observability/.
Logging — structlog¶
logging_.pyconfigures structlog with a shared processor pipeline.- JSON renderer in production; pretty console renderer when
log_format=console. - Correlation id is propagated via a
ContextVarbound by theCorrelationIdMiddleware(REST) andCorrelationInterceptor(gRPC).
Metrics — Prometheus¶
metrics.pydeclares every metric on aMetricsRegistry. The composition root creates one registry; adapters read it fromAppContext.- Exposed at
/metrics(seemetrics_router). - No global registry — tests instantiate their own.
Tracing — OpenTelemetry¶
tracing.pyconfigures the OTel tracer provider with an OTLP gRPC exporter whenBQEMU_TRACING_ENABLED=true.opentelemetry-instrumentation-fastapiandopentelemetry-instrumentation-grpcinstrument the inbound request surfaces automatically.- Custom spans are added around SQL translation, DuckDB execution, UDF invocation, and scripting statement dispatch.
- No-op by default — zero overhead when disabled.