-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
26 lines (21 loc) · 881 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import azure.functions as func
from fastapp.main import app, lifespan_sync
from fastapp.utils import setup_tracer
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
lifespan_sync(app=app)
tracer = setup_tracer(__name__)
async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
# Start distributed tracing
functions_current_context = {
"traceparent": context.trace_context.Traceparent,
"tracestate": context.trace_context.Tracestate,
}
parent_context = TraceContextTextMapPropagator().extract(
carrier=functions_current_context
)
# Function logic
with tracer.start_as_current_span("wrapper", context=parent_context) as span:
response = await func.AsgiMiddleware(app).handle_async(
req=req, context=parent_context
)
return response