Closed synsteve closed 3 years ago
I will make a built-in function which can read these properties and use it as tracing IDs. Could you post the "official" specification about these headers?
I think that this is the specification: https://www.w3.org/TR/trace-context/#traceparent-header
Yep, thanks AndreMaz & icebob
There's a regex for it in my code above it it helps with the 4 sections being:
@synsteve I've done something :) Could you try it? Because I can't test it in a real environment with coming tracing data.
You can define a rootCallOptions
in service settings which can be an Object
or a Function
. In you case you need the Function
which gets the req
and you can fill the options
which will be passed to the root api.rest
action call as calling options.
Here is an example for your use-case:
https://github.com/moleculerjs/moleculer-web/blob/94591713e1975a26ee13041418ed07c717002e7f/examples/dev/index.js#L25-L51
Please try it with npm i moleculerjs/moleculer-web
and if it's good I can release a new beta version.
Hi @icebob - works a treat! I used your example code and then when I breakpoint in the onBeforeCall callback, ctx.parentID, ctx.requestID, ctx.span.parentID and ctx.tracing are all set to the correct values.
Nice job!
Hi @icebob - has this made it into the beta yet?
Thanks.
Sorry, I forgot it. I've just released in https://github.com/moleculerjs/moleculer-web/releases/tag/v0.10.0-beta3
I've been trying to get my multiple moleculer-web applications to produce a consistent distributed trace but have found a problem with parent spans.
Using the x-correlation-id or x-request-id header does work for the main trace id, but I can't set the parent span id (ctx.parentID) properly.
The span for the api.rest call is created before I can set the ctx.parentID
I tried to use a global middleware:
That looks for the appropriate header and sets the req.$ctx properties, but I think because when the rest action is called, the internal tracing middleware is called before the api middleware above, it doesn't give the api span a parentID.
The only way around this would be to either code for this directly in the httpHandler or provide for some callback before the call to the rest action in which I could detect the headers and set the parentID in the options passed to this.actions.rest