Skip to main content

Overview

flush() forces immediate export of all pending spans to Keywords AI. Useful before application shutdown or when you need to ensure data is sent immediately.

Signature

Basic Usage

Before Application Exit

Periodic Flushing

Serverless Functions

Express Middleware

Testing

With shutdown()

For complete cleanup, use shutdown() instead of flush(). shutdown() flushes and then closes the tracer.

Best Practices

  • Call flush() before application exit to ensure no data is lost
  • Use shutdown() for complete cleanup instead of just flush()
  • In serverless environments, always flush before function completion
  • For critical operations, flush immediately after completion
  • Flush is automatically called periodically when batching is enabled
  • Flushing is synchronous and waits for export to complete
  • In long-running processes, prefer shutdown() over flush() when done