add_event()

Signature

1add_event(
2 name: str,
3 attributes: Dict = None,
4 timestamp: int = None,
5) -> 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

1from respan import Respan, task, get_client
2
3respan = Respan(api_key="your-api-key")
4
5@task(name="process_batch")
6def process_batch(items):
7 client = get_client()
8 client.add_event("batch_started", {"item_count": len(items)})
9
10 results = [item * 2 for item in items]
11
12 client.add_event("batch_completed", {"result_count": len(results)})
13 return results
14
15process_batch([1, 2, 3])