flush()

Signature

1flush() -> None

Flushes all pending spans through the processor pipeline to exporters. Available on both Respan and RespanClient. The Python SDK drains pending spans automatically on normal process exit, so short-lived scripts do not need a final flush() only to make their last trace appear. Use flush() when your code needs an explicit export checkpoint while the process is still running.

Example

1from respan import Respan, get_client, workflow
2
3respan = Respan(api_key="your-api-key")
4
5@workflow(name="quick_task")
6def quick_task():
7 return "done"
8
9quick_task()
10
11# Flush via Respan instance
12respan.flush()
13
14# Or flush via client
15get_client().flush()

Do not add a final flush() to short-lived Python scripts only for normal process exit; the SDK drains pending spans automatically. Use flush() for explicit checkpoints, tests that read exported traces before exit, critical operations, and serverless/Lambda invocations that may freeze before process-exit hooks run. In long-running applications with batch processing enabled, spans are flushed automatically at regular intervals.