swadhinbiswas feat(py): add Python package with app framework, type stubs, and docs · 7/8/2026
9ae675f
19 lines · 535 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import contextvars

_trace_id_var: contextvars.ContextVar[str | None] = contextvars.ContextVar(
    "trace_id", default=None
)
_span_id_var: contextvars.ContextVar[str | None] = contextvars.ContextVar(
    "span_id", default=None
)


def get_current_trace_id() -> str | None:
    """Return the current OpenTelemetry trace ID as a hex string, or None."""
    return _trace_id_var.get()


def get_current_span_id() -> str | None:
    """Return the current OpenTelemetry span ID as a hex string, or None."""
    return _span_id_var.get()