add_event()

Signature

add_event(
name: str,
attributes: Dict = None,
timestamp: int = None,
) -> bool

Returns True if the event was added successfully.

Parameters

ParameterTypeDescription
namestrEvent name.
attributesDict | NoneKey-value pairs attached to the event.
timestampint | NoneUnix timestamp in nanoseconds. Defaults to current time.

Example

from respan import Respan, task, get_client
respan = Respan(api_key="your-api-key")
@task(name="process_batch")
def process_batch(items):
client = get_client()
client.add_event("batch_started", {"item_count": len(items)})
results = [item * 2 for item in items]
client.add_event("batch_completed", {"result_count": len(results)})
return results
process_batch([1, 2, 3])