Skip to content

Conversation

@katreniak
Copy link

@katreniak katreniak commented Oct 27, 2025

Add a global setter function to allow injecting an external AsyncLocalStorage instance. This enables sharing a single AsyncLocalStorage across multiple request sources in applications that handle requests from various origins.

Use cases:

  • Fastify HTTP requests
  • Queue consumers (e.g., RabbitMQ, SQS)
  • Scheduled tasks and timers
  • Other HTTP servers or frameworks
  • WebSocket connections

Previously, the plugin sticked to its own AsyncLocalStorage instance, making it difficult to maintain a unified request context across different entry points. By providing setAsyncLocalStorage(), users can now create a central AsyncLocalStorage instance and share it across all request handlers, without coupling non-HTTP code to Fastify.

Usage:

  const sharedALS = new AsyncLocalStorage()
  setAsyncLocalStorage(sharedALS)
  app.register(fastifyRequestContext)

Checklist

Add a global setter function to allow injecting an external AsyncLocalStorage
instance. This enables sharing a single AsyncLocalStorage across multiple
request sources in applications that handle requests from various origins.

Use cases:
- Fastify HTTP requests
- Queue consumers (e.g., RabbitMQ, SQS)
- Scheduled tasks and timers
- Other HTTP servers or frameworks
- WebSocket connections

Previously, the plugin sticked to its own AsyncLocalStorage instance, making it
difficult to maintain a unified request context across different entry points.
By providing setAsyncLocalStorage(), users can now create a central
AsyncLocalStorage instance and share it across all request handlers, without
coupling non-HTTP code to Fastify.

Usage:
```
  const sharedALS = new AsyncLocalStorage()
  setAsyncLocalStorage(sharedALS)
  app.register(fastifyRequestContext)
```
@katreniak
Copy link
Author

Closing in favour of #231

@katreniak katreniak closed this Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant