Skip to main content

Signature

record_exception(
    exception: Exception,
    attributes: Dict = None,
    timestamp: int = None,
    escaped: bool = False,
) -> bool
Returns True if the exception was recorded successfully.

Parameters

ParameterTypeDescription
exceptionExceptionThe exception to record.
attributesDict | NoneAdditional attributes for the exception event.
timestampint | NoneUnix timestamp in nanoseconds. Defaults to current time.
escapedboolWhether the exception escaped the span’s scope.

Example

from respan_tracing import RespanTelemetry, task, get_client

telemetry = RespanTelemetry(api_key="your-api-key")

@task(name="validate_input")
def validate_input(data):
    client = get_client()
    try:
        if not data:
            raise ValueError("Input data is empty")
        return data
    except Exception as e:
        client.record_exception(e, {"phase": "validation"})
        return None

validate_input("")
Decorators automatically record unhandled exceptions. Use record_exception() when you catch and handle exceptions but still want them visible in the trace.