OpenTelemetry FastAPI Instrumentation

pypi

This library provides automatic and manual instrumentation of FastAPI web frameworks, instrumenting http requests served by applications utilizing the framework.

auto-instrumentation using the opentelemetry-instrumentation package is also supported.

Installation

pip install opentelemetry-instrumentation-fastapi

Usage

import fastapi
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor

app = fastapi.FastAPI()

@app.get("/foobar")
async def foobar():
    return {"message": "hello world"}

FastAPIInstrumentor.instrument_app(app)

API

class opentelemetry.instrumentation.fastapi.FastAPIInstrumentor[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

An instrumentor for FastAPI

See BaseInstrumentor

static instrument_app(app)[source]

Instrument an uninstrumented FastAPI application.