stevejgordon / CorrelationId

An ASP.NET Core middleware component which synchronises a correlation ID for cross API request logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question - How do you configure correlation id via request header?

tomkerkhove opened this issue · comments

I've noticed the following in the README which was interesting:

In cases where the incoming request includes an existing correlation ID in the header, the TraceIdentifier will be updated to that ID. This allows logging and diagnostics to be correlated for a single user transaction and to track the path of a user request through multiple API services.

So I've created a basic setup like this:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    services.AddCorrelationId();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseCorrelationId(new CorrelationIdOptions
    {
        UpdateTraceIdentifier = true
    });

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseMvc();
}

However, when I try this a new correlation id is being generated:

image

Am I missing something?

The problem is that you are setting CorrelationId as query parameter, not as header value.
Please do consider using that as header.
Is that really the case that you have to use only query params for that?

Lol, I am such a moron 😂

Thanks for pointing that out, we don't really need query params 😅
Although it could make sense in webhook scenarios though, but not customer need.