Repository navigation
v3.0.0
Major release. FastAPI 0.142 added built-in OpenTelemetry, and servicekit now uses it for HTTP metrics instead of the separate opentelemetry-instrumentation-fastapi package. Monitoring is now on by default. HTTP metric names change, so dashboards and alerts need updating.
Why
fastapi[standard]now installsopentelemetry-sdkand the OTLP HTTP exporter, so every servicekit service already had a second OpenTelemetry stack next to ours.- FastAPI OpenTelemetry follows the stable HTTP semantic conventions. The contrib package emitted the old
http_server_duration_millisecondsseries, which did not match our own documentation. - With
OTEL_EXPORTER_OTLP_ENDPOINTset, FastAPI turns on OTLP export by itself at startup. servicekit now controls that switch together with monitoring.
Changed
- Monitoring is on by default. Every
BaseServiceBuilderservice exposes Prometheus metrics at/metricswithout callingwith_monitoring(). Callwith_monitoring(...)only to change the prefix, tags or service name. with_monitoring(enabled=False)turns monitoring off completely: it removes/metricsand disables FastAPI OpenTelemetry tracing, metrics, logs and OTLP auto-configuration, even whenOTEL_*variables are set.- HTTP metrics come from FastAPI OpenTelemetry:
http_server_request_duration_seconds(histogram,_countfor request totals) andhttp_server_active_requests, with labelshttp_request_method,http_response_status_code,http_route,url_schemeandnetwork_protocol_version. Durations are in seconds. - Requests to the metrics endpoint are no longer counted in HTTP metrics.
teardown_monitoring()keeps the global meter provider and its Prometheus reader. OpenTelemetry cannot replace a global provider, so setting monitoring up again after a teardown used to leave an orphaned reader.- Dependencies:
fastapi[standard]>=0.142.2,opentelemetry-api>=1.44.0,opentelemetry-sdk>=1.44.0.opentelemetry-instrumentation-fastapiis removed. SQLAlchemy instrumentation, process metrics and the Prometheus exporter are unchanged.
Added
- OTLP export through FastAPI OpenTelemetry. Set
OTEL_EXPORTER_OTLP_ENDPOINT(and optionallyOTEL_SERVICE_NAME,OTEL_EXPORTER_OTLP_HEADERS) to send request traces, metrics and logs to a collector, in addition to Prometheus scraping. Only thehttp/protobufprotocol is supported for this automatic setup.
Upgrading
- Update Prometheus queries, Grafana panels and alerts:
http_server_duration_milliseconds_*becomeshttp_server_request_duration_seconds_*,http_methodbecomeshttp_request_method,http_status_codebecomeshttp_response_status_code, andhttp_targetbecomeshttp_route. Thresholds in milliseconds must be divided by 1000. The example Grafana dashboard inexamples/monitoringis already updated. - Services that did not call
with_monitoring()now expose/metrics. Add.with_monitoring(enabled=False)if you do not want it, or if something else is mounted at/metrics. - If your deployment sets
OTEL_*variables for other tools, FastAPI will now export over OTLP. Usewith_monitoring(enabled=False), or setOTEL_SDK_DISABLED=true, if that is not wanted. - Remove any direct use of
FastAPIInstrumentoralongside servicekit; it is no longer installed. - Downstream projects pinning
servicekit>=2,<3need to move to>=3.0.0,<4.
What's Changed
- chore(ci): tag releases with --cleanup=verbatim to keep Markdown headings by @mortenoh in #44
- feat(monitoring): use FastAPI OpenTelemetry and enable monitoring by default by @mortenoh in #45
- chore: release 3.0.0 by @mortenoh in #46
Full Changelog: v2.0.3...v3.0.0