Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Create correlation ids for API requests originating from a Blazor Server app

$
0
0

My Blazor server application calls an external API. For each request to this API I want to send a unique correlation id (as a X-Correlation-Id header).

I'm trying to use Activity.Current.Id.ToString(); but this remains the same for the entirety of the user's session.

Activity.Current.TraceId.ToString(); is similar, except that on first load of the app it is different then changes to value that remains the same for the rest of the users session.

Obviously I can just manually set the X-Correlation-Id header to a new Guid every time I make the request. I would prefer not to do this as I want to log this correlation out in various components of my Blazor app and I don't want to pass the value around.

I have tried wrapping the code that generates the new guid in an injected service that stores the current value in a class variable, but this is an unpleasant work around.

I'm not using open telemetry, I'm using the System.Diagnostics classes. These concepts are new to me.


Viewing all articles
Browse latest Browse all 4839

Trending Articles