Sunday 31 March 2019

Preferred approach for passing contextual data around?

Hi,I’ll use a Koa app as an example, but the workflow seems to be the same for any call flow(I guess).In my app I have middleware that tacks on a correlation id at the beginning of the request.I’d like to log that correlation id in the controller. That’s easy, it in the context passed to the controller.The controller is now going to call a service, which will call a random microservice.I’d like to tack the correlation id as a header value on the call to the microservice. I’d also like to log it as info with the service calls log entry.My question is how should I be passing the data around?const t = service(a,b, correlationId)?Seems like a crosscutting concern polluting my API.Is there a different way? I’ve seen context saving packages, feels a little to magical, but maybe it’s magic or polluting the api?I’m doing Singleton instances for the services because there is some initial state that’s computed.

Submitted March 31, 2019 at 09:09PM by bfdill

No comments:

Post a Comment