request_id, user_id, trace/span context) are still available inside event handlers later in the async call chain.
This is commonly used in:
- web servers (FastAPI, Fastify, Express/Nest adapters)
- observability and distributed tracing (OpenTelemetry)
- structured logging/correlation IDs
What this maps to per runtime
- Python uses
ContextVars(contextvars.ContextVar). - TypeScript (Node/Bun) uses
AsyncLocalStorage.
emit(...) time and restores it when handlers execute, so handler code sees the same request-local values.
Why this matters
Without propagation, handler code often loses request-local state after async boundaries and queue scheduling.With propagation, event handlers can log/trace as if they were still running in the original request scope.
- Python
- TypeScript
Web server style examples
These patterns are typical in frameworks where each incoming request gets a request-local context object.- Python
- TypeScript
Browser runtime note
AsyncLocalStorage is a Node/Bun API and is not available in browser runtimes.
In browsers:
- Bubus still works normally for events.
- ambient async context propagation via
AsyncLocalStorageis not available. - pass correlation/tracing fields explicitly in event payloads when you need that metadata.