|
4 | 4 | from time import time |
5 | 5 | from asyncio import sleep |
6 | 6 | from urllib.parse import urlparse, quote |
| 7 | +from opentelemetry import trace |
7 | 8 |
|
8 | 9 | import azure.functions as func |
9 | 10 |
|
@@ -71,8 +72,25 @@ async def start_new(self, |
71 | 72 | request_url = self._get_start_new_url( |
72 | 73 | instance_id=instance_id, orchestration_function_name=orchestration_function_name) |
73 | 74 |
|
| 75 | + # Get the current span |
| 76 | + current_span = trace.get_current_span() |
| 77 | + span_context = current_span.get_span_context() |
| 78 | + |
| 79 | + # Get the traceparent and tracestate from the span context |
| 80 | + # Follows the W3C Trace Context specification for traceparent |
| 81 | + # https://www.w3.org/TR/trace-context/#traceparent-header |
| 82 | + trace_id = format(span_context.trace_id, '032x') |
| 83 | + span_id = format(span_context.span_id, '016x') |
| 84 | + trace_flags = format(span_context.trace_flags, '02x') |
| 85 | + trace_parent = f"00-{trace_id}-{span_id}-{trace_flags}" |
| 86 | + |
| 87 | + trace_state = span_context.trace_state |
| 88 | + |
74 | 89 | response: List[Any] = await self._post_async_request( |
75 | | - request_url, self._get_json_input(client_input)) |
| 90 | + request_url, |
| 91 | + self._get_json_input(client_input), |
| 92 | + trace_parent, |
| 93 | + trace_state) |
76 | 94 |
|
77 | 95 | status_code: int = response[0] |
78 | 96 | if status_code <= 202 and response[1]: |
|
0 commit comments