get_client()

Overview

get_client() returns a RespanClient instance bound to the singleton tracer. Use it inside decorated functions to read trace/span IDs, update the current span, add events, record exceptions, and control export.

from respan import get_client

Usage

from respan import Respan, get_client, workflow
respan = Respan(api_key="your-api-key")
@workflow(name="my_workflow")
def my_workflow():
client = get_client()
# Read IDs
trace_id = client.get_current_trace_id()
span_id = client.get_current_span_id()
# Update span
client.update_current_span(
respan_params={"customer_identifier": "user-123"}
)
# Add events
client.add_event("processing_started", {"items": 10})
return trace_id
print(my_workflow())

RespanClient methods

MethodDescription
get_current_trace_id()Get active trace ID as hex string.
get_current_span_id()Get active span ID as hex string.
update_current_span()Update attributes, status, and Respan params on the current span.
add_event()Add a timestamped event to the current span.
record_exception()Record an exception on the current span.
get_context_value()Read a value from the OpenTelemetry context.
set_context_value()Set a value in the OpenTelemetry context.
is_recording()Check if the current span is recording.
get_tracer()Get the OpenTelemetry tracer for manual span creation.
flush()Force flush pending spans.
get_span_buffer()Get a span buffer for manual batch collection.
process_spans()Process collected spans through the processor pipeline.