flush()

Signature

flush() -> 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

from respan import Respan, get_client, workflow
respan = Respan(api_key="your-api-key")
@workflow(name="quick_task")
def quick_task():
return "done"
quick_task()
# Flush via Respan instance
respan.flush()
# Or flush via client
get_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.