Skip to content

Commit 556bdd5

Browse files
committed
fix(otel): replace middleware with fastapi middleware
1 parent 7897899 commit 556bdd5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llama_stack/core/server/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def create_app() -> StackApp:
410410

411411
if Api.telemetry in impls:
412412
setup_logger(impls[Api.telemetry])
413+
TelemetryAdapter.fastapi_middleware(app) # hold us over until we can move to programmatic instrumentation
413414
else:
414415
setup_logger(TelemetryAdapter(TelemetryConfig(), {}))
415416

llama_stack/providers/inline/telemetry/meta_reference/telemetry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
from llama_stack.providers.utils.telemetry.sqlite_trace_store import SQLiteTraceStore
5050
from llama_stack.providers.utils.telemetry.tracing import ROOT_SPAN_MARKERS
5151

52+
from fastapi import FastAPI
53+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
54+
5255
from .config import TelemetryConfig, TelemetrySink
5356

5457
_GLOBAL_STORAGE: dict[str, dict[str | int, Any]] = {
@@ -362,3 +365,8 @@ async def get_span_tree(
362365
max_depth=max_depth,
363366
)
364367
)
368+
369+
@staticmethod
370+
def fastapi_middleware(app: FastAPI):
371+
''' Inject telemetry middleware into the FastAPI app '''
372+
FastAPIInstrumentor.instrument_app(app)

0 commit comments

Comments
 (0)