We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
So I am trying to include the request-id in my logging, but it doesn't work with koa-morgan.
Here's my code:
import Koa from "koa" import morgan from "koa-morgan" import rTracer from "cls-rtracer" const app = new Koa() app.use(rTracer.koaMiddleware()) app.use(getMorgan()) app.use(() => { console.log("it works here", getReqId()) }) app.listen(8080) const getReqId = () => { return (rTracer.id() ?? "") as string } const getMorgan = () => { morgan.token("reqId", getReqId) return morgan("it doesn't work here :reqId") }
then when I run the app
> curl --location --request GET 'localhost:8080/' it works here fc7170b0-b328-11ed-b4d4-11d1313525c1 it doesn't work here -
The text was updated successfully, but these errors were encountered:
I end up setting the echoHeader option to true and getting the request-id from the response header. Works for me.
echoHeader
true
import Koa from "koa" import morgan from "koa-morgan" import rTracer from "cls-rtracer" const app = new Koa() app.use(rTracer.koaMiddleware({ echoHeader: true, }) ) app.use(getMorgan()) app.use(() => { console.log("it works here", getReqId()) }) app.listen(8080) const getReqId = () => { return (rTracer.id() ?? "") as string } const getMorgan = () => { morgan.token("reqId", (req, res) => { return (res.getHeader("x-request-id") ?? "") as string }) return morgan("now it works :reqId") }
Sorry, something went wrong.
Thanks for sharing the workaround! Unfortunately, not all libraries play nicely with ALS.
No branches or pull requests
So I am trying to include the request-id in my logging, but it doesn't work with koa-morgan.
Here's my code:
then when I run the app
The text was updated successfully, but these errors were encountered: