MCPcopy Index your code
hub / github.com/github/copilot-sdk / trace_context

Function trace_context

python/copilot/_telemetry.py:27–48  ·  view source on GitHub ↗

Context manager that sets the trace context from W3C headers for the block's duration.

(traceparent: str | None, tracestate: str | None)

Source from the content-addressed store, hash-verified

25
26@contextmanager
27def trace_context(traceparent: str | None, tracestate: str | None) -> Generator[None, None, None]:
28 """Context manager that sets the trace context from W3C headers for the block's duration."""
29 try:
30 from opentelemetry import context, propagate
31 except ImportError:
32 yield
33 return
34
35 if not traceparent:
36 yield
37 return
38
39 carrier: dict[str, str] = {"traceparent": traceparent}
40 if tracestate:
41 carrier["tracestate"] = tracestate
42
43 ctx = propagate.extract(carrier, context=context.get_current())
44 token = context.attach(ctx)
45 try:
46 yield
47 finally:
48 context.detach(token)

Calls 1

get_currentMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…