ericzon / logger-wrapper-with-cls

Example of cls showing how to forward request id through application flow.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLS-EXAMPLE

Simple example of CLS (Continuation-Local Storage) showing how to forward request id through application flow.

Logger used: Pino.js

Working with node versions >= 10.15.x (lts)

Environment

PORT: <3000 by default>

Install

npm i

Start

npm start

Then go to http://localhost:{PORT}/ping and check the logs:

[1548759313580] INFO: Server listening in 3000
[1548759322510] INFO: saying hello...
    requestId: "cjrhnb9fw000074yfhq6bri6z"
[1548759322513] INFO: Ping says: Hello Ping
    requestId: "cjrhnb9fw000074yfhq6bri6z"

If we repeat the request, we can check how new a requestId is attached during all the application flow.

[1548759324016] INFO: saying hello...
    requestId: "cjrhnbals000174yf7z9hg4h8"
[1548759324016] INFO: Ping says: Hello Ping
    requestId: "cjrhnbals000174yf7z9hg4h8"

You can customize ids sending a value in 'X-Request-Id' header.

Credits

Example adapted from these posts:

About

Example of cls showing how to forward request id through application flow.


Languages

Language:JavaScript 100.0%