Lifecycle Overview
UseObserve.flush() and Observe.shutdown() to control when finished spans are exported and when the SDK releases tracing resources.
Flush
Observe.flush() forces the current provider to export finished spans.
Flush spans
flush() when the process may terminate before the batch exporter sends spans in the background:
| Environment | Guidance |
|---|---|
| CLI scripts | Flush before process exit |
| CI jobs | Flush before the job step exits |
| Serverless handlers | Flush before returning when spans were created immediately before exit |
| Long-running web servers | Prefer graceful shutdown hooks instead of flushing on every request |
Shutdown
Observe.shutdown() disables instrumentations, shuts down the provider, and clears SDK state so the process can initialize again with different options.
Shut down tracing
Handle graceful shutdown
Reinitialization
Observe.initialize() rejects conflicting reinitialization while the SDK is active. To change exporter settings, shut down first:
Reinitialize with a new exporter
Observe.initialize({ instrumentModules }) call patches additional modules without replacing the provider.
Short-Lived Example
Short-lived job example

