Request-scoped storage support? (AsyncLocalStorage) #9490
Unanswered
cliffordfajardo
asked this question in
Q&A
Replies: 1 comment
-
Related: remix-run/react-router#11565 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background context: using remix-express template which exposes underlying express server
Question:
Is there a way to pass request context down into util functions in remix without needing to explicitly pass
Request
orResponse
object to a utility function?Outside of Remix / Other frameworks
Solidstart
With SolidStart, you can access the current request from nearly anywhere like this using getRequestEvent (powered by AsyncLocalStorage)
Python Flask
In Python with the Flask webframework, we have the
g
object, which is a commonly used to manage resources during a request. For example, we can augmentg
object with custom property and then later referenceg
in our utility function in another file (more on - https://flask.palletsprojects.com/en/2.3.x/appcontext/).then in our util method, we can reference that traceid we set earlier^
Are there similar concepts or recommended patterns with Remix?
Existing Solution(s) with Remix:
If we have access to express server (which we do with remix-express template), I know we can use middleware to augment
req
andres
object with session specific information. Something likereq.traceId
.Goal
The goal i'm aiming for is to associate each log line with a
traceId
for easier grouping. Sure this middlewarereq.traceId
works, but it's limited to be used only when you have access to thereq
object, aka within the network call. But if you are in the middle of a util method, you can't easily access the current req object, unless you pass it down this req into each util method.References
g
objectBeta Was this translation helpful? Give feedback.
All reactions