Skip to content

Fix OpenTelemetry FastAPI instrumentation for version 0.48b0 upgrade #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion function/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fastapi
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
from opentelemetry import trace
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
Expand All @@ -16,7 +17,10 @@ def create_app():
exporter = AzureMonitorTraceExporter.from_connection_string(conn_str)
tracer = TracerProvider(resource=Resource({SERVICE_NAME: "api"}))
tracer.add_span_processor(BatchSpanProcessor(exporter))
FastAPIInstrumentor.instrument_app(app, tracer_provider=tracer)
trace.set_tracer_provider(tracer)

# Use the newer instrumentation pattern
FastAPIInstrumentor().instrument()

app.include_router(fastapi_routes.router)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ py-staticmaps==0.4.0
fastapi==0.111.0
Pillow==9.5.0
nest-asyncio==1.6.0
opentelemetry-instrumentation-fastapi==0.46b0
opentelemetry-instrumentation-fastapi==0.48b0
azure-monitor-opentelemetry-exporter==1.0.0b26