Skip to content

Commit 89bd5b4

Browse files
committed
Add open telemetry tracing
1 parent cef8c83 commit 89bd5b4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

code/function/wrapper/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import azure.functions as func
22
from fastapp.main import app
3+
from fastapp.utils import setup_tracer
34
from opentelemetry.context import attach, detach
45
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
56

7+
tracer = setup_tracer(__name__)
8+
69

710
async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
811
# Start distributed tracing
@@ -16,8 +19,11 @@ async def main(req: func.HttpRequest, context: func.Context) -> func.HttpRespons
1619
token = attach(parent_context)
1720

1821
# Function logic
19-
response = await func.AsgiMiddleware(app).handle_async(req, context)
22+
try:
23+
with tracer.start_as_current_span('wrapper') as span:
24+
response = await func.AsgiMiddleware(app).handle_async(req, context)
25+
finally:
26+
# End distributed tracing
27+
detach(token)
2028

21-
# End distributed tracing
22-
detach(token)
2329
return response

0 commit comments

Comments
 (0)