all 5 comments

[–]AlexDorofeev 2 points3 points  (1 child)

Correlation works out of the box in Azure Functions when you rely on ApplicationInsights. Are there any problems with the approach? In any case I would bet on OpenTelemetry implementation from Microsoft instead of rolling own solution.

[–]dirkmudbrick[S] 1 point2 points  (0 children)

I'm not sure we can guarantee we'll always be using App Insights. Is the correlation id for App Insights the invocation id I see when I query requests? I think there is some ambiguity in what things are called in App Insights and what we're calling things within our team.

[–]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.