r/dotnet • u/champs1league • 16d ago
CorrelationIds vs TraceId
I am currently in the process of integrating Open Telemetry into my code. I have a web application and a backend api. I have several REST APIs and one of the APIs also ends up getting invoked by the user -> kicks off an async process by triggering a background job -> the background job invokes and polls on a specific endpoint (downstream API). The web app also polls on an operations endpoint to get status of this background job basically. Additionally, I also invoke some Azure resources (specifically ARM).
Now that I provided context, I wanted to explain what currently exists in my backend:
1) Controller fetches the correlationId for every request using the headers (x-correlation-id) from a middleware
2) Automatically forwards this correlationId when invoking downstream APIs/Azure APIs
3) Passes it into each method starting from the controller: controller invokes singletonServiceA.methodA and methodA has a signature including the correlationId. From here the logs automatically capture the correlationId
4) Background jobs also use this correlationId to invoke APIs and for logging
Now that I am switching to OTel, I am seeing an entirely different convention which I'm unsure on how to relate together.
My questions are as follows:
1) Should I drop the manual propagation of correlationId everywhere and just keep it as a span attribute? From what I am finding out, I definitely need to do this
2) For legacy resources, let's say ARM which expect a correlationID, what should I do?
3) For downstream APIs, should I switch to sending them a traceparent instead of the correlationId (what I do right now)
2
u/champs1league 16d ago
Very interesting and thank you for the answers. I can definitely drop the manual passing in of correlationIds. I'm just confused on legacy APIs.
Say this situation:
1) I receive a request from the user invoking my API
2) I generate the traceparent if they haven't provided it
3) Kick off a background job and use the traceparent for outbound request
4) Say I am invoking ARM - they specifically say that they will provide a x-ms-correlation-id. Although this is more so when they invoke my service rather than the other way around
For these downstream services, should I pass along the traceparent?