From 1af7f012f4f99b4fb19b44a8489c9ff7c066de9d Mon Sep 17 00:00:00 2001 From: Yedidya Date: Fri, 5 Feb 2021 11:07:59 +0200 Subject: [PATCH] http request example --- sections/production/assigntransactionid.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sections/production/assigntransactionid.md b/sections/production/assigntransactionid.md index c734695a..3251f6f9 100644 --- a/sections/production/assigntransactionid.md +++ b/sections/production/assigntransactionid.md @@ -25,13 +25,11 @@ app.get('/getUserData/{id}', async (req, res, next) => { // At any point in the app after cls-rtracer middleware was initialized, even when 'req' object doesn't exist, the TransactionId is reachable const transactionId = rTracer.id(); - logger.info(`user ${user.id} data was fetched successfully`, { transactionId }); res.json(user); } catch (err) { - - // As next step I'd recommand using rTracer.id() from inside the logger component, to prevent from using it all over the code + // If not for the example, I'd recommand using rTracer.id() from inside the logger component, to prevent from using it all over the code logger.error(`error while fetching user id ${req.params.id} data`, { transactionId: rTracer.id(), error: err }); next(err); @@ -53,10 +51,14 @@ app.use(rTracer.expressMiddleware({ headerName: 'x-transaction-id' })); +const axios = require("axios"); + +// Now, the external service will automaticlly get the current TransactionId as header +const response = await axios.get('https://externalService.com/api/getAllUsers'); ```

-### Good: Logs with an assigned TransactionId - can be used it as filter to see only a single flow +### Good: Logs with an assigned TransactionId - can be used as filter to see only a single flow ![alt text](https://i.ibb.co/YjJwgbN/logs-with-transaction-id.jpg "Logs with transaction id")