record_exception()

Signature

1record_exception(
2 exception: Exception,
3 attributes: Dict = None,
4 timestamp: int = None,
5 escaped: bool = False,
6) -> 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

1from respan import Respan, task, get_client
2
3respan = Respan(api_key="your-api-key")
4
5@task(name="validate_input")
6def validate_input(data):
7 client = get_client()
8 try:
9 if not data:
10 raise ValueError("Input data is empty")
11 return data
12 except Exception as e:
13 client.record_exception(e, {"phase": "validation"})
14 return None
15
16validate_input("")

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