Loading...
Loading...
FastAPI OpenTelemetry style: native FastAPIInstrumentor, centralized observability init, Python decorators, OTLP logs, and LLM cost metrics.
npx skill4agent add superloglabs/skills otel-fastapi-stylefrom fastapi import FastAPI
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
def init_observability(app: FastAPI) -> bool:
...
FastAPIInstrumentor.instrument_app(app)
return TrueFastAPIInstrumentor.instrument_app(app)init_observability(app)app = FastAPI(title="Mugline API")
init_observability(app)tracer = trace.get_tracer("mugline.api")
meter = metrics.get_meter("mugline.api")
@tracer.start_as_current_span("mug.recommend")
async def recommend_mug(*, tenant_id: str, preference: str) -> dict[str, str]:
span = trace.get_current_span()
span.set_attribute("tenant.id", tenant_id)
...LoggerProviderset_logger_provider(logger_provider)OTLPLogExporterLoggingHandlerLoggingInstrumentor().instrument(...)llm.tokens.inputllm.tokens.output