Preserve distributed job context and expose grade 4 operational signals

This commit is contained in:
Artyom
2026-11-06 12:57:10 +03:00
parent 1a171d0d0f
commit 44d81fd80e
32 changed files with 1098 additions and 35 deletions
@@ -0,0 +1,22 @@
from collections.abc import Iterator
from contextlib import contextmanager
from opentelemetry.context import attach, detach
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
PROPAGATOR = TraceContextTextMapPropagator()
def capture_context() -> dict[str, str]:
carrier: dict[str, str] = {}
PROPAGATOR.inject(carrier)
return carrier
@contextmanager
def restored_context(carrier: dict[str, str] | None) -> Iterator[None]:
token = attach(PROPAGATOR.extract(carrier or {}))
try:
yield
finally:
detach(token)