Skip to content

feat: add setAsyncLocalStorage for external AsyncLocalStorage injection#230

Closed
katreniak wants to merge 1 commit into
fastify:mainfrom
katreniak:brko/external-storage
Closed

feat: add setAsyncLocalStorage for external AsyncLocalStorage injection#230
katreniak wants to merge 1 commit into
fastify:mainfrom
katreniak:brko/external-storage

Conversation

@katreniak
Copy link
Copy Markdown

@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
Copy Markdown
Author

Closing in favour of #231

@katreniak katreniak closed this Oct 28, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant