add_event()
Signature
1 add_event( 2 name: str, 3 attributes: Dict = None, 4 timestamp: int = None, 5 ) -> bool
Returns True if the event was added successfully.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | str | Event name. |
attributes | Dict | None | Key-value pairs attached to the event. |
timestamp | int | None | Unix timestamp in nanoseconds. Defaults to current time. |
Example
1 from respan import Respan, task, get_client 2 3 respan = Respan(api_key="your-api-key") 4 5 @task(name="process_batch") 6 def 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 15 process_batch([1, 2, 3])