get_current_trace_id()

Signature

1get_current_trace_id() -> Optional[str]

Returns the current trace ID as a 32-character hex string, or None when no span is active.

Example

1from respan import Respan, get_client, workflow
2
3respan = Respan(api_key="your-api-key")
4
5@workflow(name="trace_demo")
6def trace_demo():
7 client = get_client()
8 trace_id = client.get_current_trace_id()
9 print(f"Trace ID: {trace_id}") # e.g. "0af7651916cd43dd8448eb211c80319c"
10 return trace_id
11
12trace_demo()