asp.net core webapi - How to include CorrelationId in microservice architecture? -
i creating microservices architecture using asp.net core web api. services decoupled each other, , may deployed in different environments. every service has own logging. when requests flows through these services fail in of service, need way of tracing series of events source, if means traversing multiple services.
handle issue, service originates request creates correlationid , pass next service. 2nd service pass 3rd service , on. if exception occurs corresponding service log exception message along correlationid.
i wanted know best place caller of service pass correlationid?
should caller pass correlationid in httpheader or should pass part method parameter below
this service getting called
public class requestdto { public string correlationid {get;set;} public string someotherdata {get;set;} } public service2controller:controller { public task<in> dosomething(requestdto request) { // add correlationid in current request items collection // global exception handling can access , log // along exception httpcontext.items.add("correlationid", request.correlationid); } }
in approach above if there exception before method invoked, correlationid not available global exception handler logging.
any suggestions? or alternate approach
the correlation identifier should not add yourself, framework sends messages should this. way developer can't forget , has consistent behaviour on place.
put messageid
, correlationid
in headers of message. on first message, both same. on second message, correlationid
set messageid
of previous one.
you set unique conversationid
never changes, track messages spawning 1 originator. useful when using pub/sub and/or calling originator of message.
Comments
Post a Comment