Monitor FastAPI with OpenTelemetry
FastAPI is a modern, high-performance web framework for building APIs with Python based on standard type hints
In this article you will learn how to monitor and optimize FastAPI performance using OpenTelemetry observability framework.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework hosted by Cloud Native Computing Foundation. It is a merger of OpenCensus and OpenTracing projects.
OpenTelemetry specifies how to collect and send telemetry data to backend platforms. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
To install OpenTelemetry instrumentation for FastAPI:
pip install opentelemetry-instrumentation-fastapi
To instrument FastAPI application:
from fastapi import FastAPI from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor app = FastAPI() FastAPIInstrumentor.instrument_app(app)
Also see OpenTelemetry FastAPI example at GitHub.
What is Uptrace?
Uptrace is an open source and blazingly fast distributed tracing tool powered by OpenTelemetry and ClickHouse. It allows you to identify and fix bugs in production faster knowing what conditions lead to which errors.
You can get started with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.