pip install opencensus-ext-fastapi
from fastapi import FastAPI
from opencensus.ext.fastapi.fastapi_middleware import FastAPIMiddleware
app = FastAPI(__name__)
app.add_middleware(FastAPIMiddleware)
@app.get('/')
def hello():
return 'Hello World!'Additional configuration can be provided, please read Customization for a complete reference.
app.add_middleware(
FastAPIMiddleware,
excludelist_paths=["paths"],
excludelist_hostnames=["hostnames"],
sampler=sampler,
exporter=exporter,
propagator=propagator,
)