mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-12 12:06:04 +00:00
feat(telemetry): capture opentelemtry traces and metrics for fast API
This commit is contained in:
parent
658fb2c777
commit
62651ce774
4 changed files with 138 additions and 13 deletions
|
|
@ -8,9 +8,11 @@ import os
|
|||
import threading
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI
|
||||
from opentelemetry import metrics, trace
|
||||
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
|
||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
||||
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
||||
from opentelemetry.sdk.metrics import MeterProvider
|
||||
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
|
||||
from opentelemetry.sdk.trace import TracerProvider
|
||||
|
|
@ -250,3 +252,10 @@ class TelemetryAdapter(Telemetry):
|
|||
_GLOBAL_STORAGE["active_spans"].pop(span_id, None)
|
||||
else:
|
||||
raise ValueError(f"Unknown structured log event: {event}")
|
||||
|
||||
|
||||
def fastapi_telemetry_middleware(app: FastAPI):
|
||||
"""
|
||||
Instrument the FastAPI app with OpenTelemetry.
|
||||
"""
|
||||
FastAPIInstrumentor.instrument_app(app)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue