Mali request ID metadata middleware sources request ID into context
Mali request ID metadata middleware. If the call has metadata with the request ID (or specified property) sets it into the context into target property. If request ID is not present creates one using UUID and sets it into metadata and context.
Param | Type | Description |
---|---|---|
options | Options |
|
options.name | String |
Optional name of the metadata object property. Default: 'requestId' |
options.target | String | Boolean |
Optional name of the ctx property to set request id into. If not provided it is equal to options.name . |
options.generator | function |
Synchronous function to generate the request id if not present. Has to return a string. Default: uuid library. |
Example
const rid = require('@malijs/requestid')
app.use(rid())
app.use('myFn', async (ctx, next) => {
console.log(ctx.requestId) // request ID from metadata
await next()
})
Apache-2.0