stevejgordon / CorrelationId

An ASP.NET Core middleware component which synchronises a correlation ID for cross API request logging.
MIT License
560 stars 106 forks source link

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

Closed tomkerkhove closed 5 years ago

tomkerkhove commented 5 years ago

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?

d1mnewz commented 5 years ago

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?

tomkerkhove commented 5 years ago

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.