Dynamically add values to the current rTracer Ids
OllyNural opened this issue · 3 comments
Is there any way to add new Ids to the existing ones that are already set up with rTracer?
e.g after having set it up with
app.use(rTracer.koaMiddleware({
requestIdFactory: (req) => ({
correlationId: req.get('X-CorrelationId') || randomUUID(),
otherVars...
}),
}));
And then later on, for example after we finish some authentication middleware, and we want to store some extra information only available after that middleware has completed.
So after we can add like Third Party contextual information or where the request came from etc.
Thanks!
You can simply access the object you've generated as the request id and mutate it. Think of the object as if it were request context.
const requestCtx = rTracer.id();
console.log(requestCtx.correlationId); // this is your request id
requestCtx.otherVars = 'foobar'; // this field will be stored in the object
Ah brilliant, that's easy enough. Thank you very much, appreciate that, I'll give that a go
Very nice, simple but clean library.
The above example works perfect!
I'll close this, thanks for the very speedy response :)