Home > Software engineering >  How can I pass correlationId across various classes without adding it to all method calls?
How can I pass correlationId across various classes without adding it to all method calls?

Time:07-07

I’m using Java Spring Boot and I have a hexagonal / ports and adaptors structure to my code.

Im trying to set up correlation IDs in my logging. My understanding is that my API gateway should generate a unique ID for each request then pass that in the API call. I need to then make sure all subsequent internal API calls also pass this correlation ID around and include it in all logging.

But since the port and adapters are split in the code, how can I pass this ID from the port side to the adaptor side without changing all the interim business logic to include this ID in all method calls?

CodePudding user response:

Spring-cloud-starter-sleuth is available which supports this out of the box,just add this dependency and then you would have traceId-common across all services and gateway and spanId - unique correlation is per microservice. You can read more about it in topic distributed tracing.

  • Related