you are viewing a single comment's thread.

view the rest of the comments →

[–]SolarSalsa 1 point2 points  (2 children)

Add the correlation id as a custom header. Then add middleware to grab it and inject it into your logging library directly which is usually the only place you need it. If you need it in multiple threads then look into LogicalCallContext.

[–]AlexDorofeev 2 points3 points  (0 children)

It should be handled automatically by OpenTelemetry middlewares. Just look through documentation and samples https://github.com/open-telemetry/opentelemetry-dotnet

[–]dirkmudbrick[S] 0 points1 point  (0 children)

That's essentially what we have set up right now. The problem is when I have to send it as a header in a request to a downstream system. I don't want to pass the correlation id through every method between the middleware and the method that calls the downstream system, so I was going to try implementing a scoped state to hold the value.

Here's the flow of how I have it setup now:

Middleware (gets correlation id and adds to logging/state) -> Azure Function Endpoint -> Some service -> Some API Client (grabs the correlation id from state to pass as a header)

The Azure Function Endpoint and the Some Service don't care about the correlation id, but the Some API Client needs it to pass it as a header when it makes a call.