Customized logging in API routes is challenging #2046
davidhousedev
started this conversation in
Feedback
Replies: 1 comment 1 reply
-
Great call out @davidhousedev. What if we provided it to the API route handler? For example: export async function api(request, {log: {error}}) {
error(new Error('it broke'));
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have customized the logging methods via
hydrogen.config.ts
such that our log statements are JSON-serialized for easier serialization by log aggregation tools (like Datadog). These custom loggers work well in server components because we can destructurelog
from the server component props and all logging methods are available to us.However, in API routes, e.g. when submitting a
<Form />
, it's much more challenging to use our custom loggers. The only method we've found is to destructurehydrogenConfig
from the second argument to the API route. Once we have access to the object, we also need to manually pass therequest
in to the log in order to preserve the same behavior of the server component contextualized logger.In an ideal world, we wouldn't need to take a different approach for customized logging in API routes vs server components.
Beta Was this translation helpful? Give feedback.
All reactions