GithubHelp home page GithubHelp logo

Can you set a unique id? about cls-rtracer HOT 7 CLOSED

TannerS avatar TannerS commented on May 19, 2024
Can you set a unique id?

from cls-rtracer.

Comments (7)

TannerS avatar TannerS commented on May 19, 2024 1

ok ill look, thank you, ill close this but i may have question in future :) thanks!

from cls-rtracer.

puzpuzpuz avatar puzpuzpuz commented on May 19, 2024

Hi. requestIdFactory config param serves exactly this purpose:

const rTracer = require('cls-rtracer');

app.register(rTracer.fastifyPlugin, {
  // This function will be used to initialize the request id at the beginning of each request.
  requestIdFactory: (req) => req.traceId
});

const fakeEndpoint = async (req, res) => {
  console.log('here is my 3rd-party request id: ' + rTracer.id());
};

from cls-rtracer.

TannerS avatar TannerS commented on May 19, 2024

hey @puzpuzpuz , dumb question, this is assuming app is the server and your adding it like a middleware? this may not work for us, the server lib we use doesnt allow custom middlewares, is there any other option?

from cls-rtracer.

TannerS avatar TannerS commented on May 19, 2024

or do we need the fastify?

from cls-rtracer.

puzpuzpuz avatar puzpuzpuz commented on May 19, 2024

If you don't have a web server or don't use one of the supported frameworks, you should use AsyncLocalStorage directly instead of cls-rtracer.

from cls-rtracer.

TannerS avatar TannerS commented on May 19, 2024

@puzpuzpuz hello, thanks for the reply, and ya we do have a web server but its a custom company made one that doesnt allow injection of middlewares (really stupid i know crys), so inthis example, we would need to set the id on an method (now that i look at it, no request at all object just a normal function) then use that trace id rest of the code base that calls the id function, if that is able to so with AsyncLocalStorage, do you have any examples? thanks !

or is there any possible way to make this lib work?

from cls-rtracer.

puzpuzpuz avatar puzpuzpuz commented on May 19, 2024

if that is able to so with AsyncLocalStorage, do you have any examples?

That's not cls-rtracer API, so you should refer to the standard library documentation: https://nodejs.org/api/async_context.html#class-asynclocalstorage

from cls-rtracer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.