Skip to content

Correlation ID Not Included in Request Headers in ABP Blazor Project #21419

@tsiorvasabyte

Description

@tsiorvasabyte

Is there an existing issue for this?

  • I have searched the existing issues

Description

In an ABP Blazor application, the X-Correlation-ID header is not being properly populated in outgoing HTTP request headers. This causes the HTTP API middleware to handle an empty Correlation ID, which leads to inconsistencies in distributed tracing and logging.

Specifically, the middleware logic on the HTTP API side contains the following:

var correlationId = context.Request.Headers[_options.HttpHeaderName];
if (correlationId.IsNullOrEmpty())
{
    correlationId = Guid.NewGuid().ToString("N");
    context.Request.Headers[_options.HttpHeaderName] = correlationId;
}

Due to the AddHeaders behavior in the Blazor project, the X-Correlation-ID header is always present but empty. As a result:

  1. The Headers collection includes a key for X-Correlation-ID, causing correlationId.IsNullOrEmpty() to return false.
  2. The middleware assumes the header is valid, bypassing the logic to generate a new Correlation ID.
  3. The system logs and traces requests with an empty Correlation ID, breaking log correlation.

Reproduction Steps

  1. Create a new ABP Blazor project using the ABP CLI or ABP Suite.
  2. Enable distributed logging or request tracking in the application.
  3. Make an HTTP request (e.g., an API call from a Blazor component).
  4. Inspect the outgoing HTTP request headers using a network monitoring tool (e.g., browser developer tools or Postman).
  5. Observe the behavior in the HTTP API middleware when handling the request.

Expected behavior

  1. The X-Correlation-ID header should be populated with a valid, unique value in outgoing HTTP requests from the Blazor project.
  2. The HTTP API middleware should receive this header and use it as the Correlation ID.

Actual behavior

  1. The X-Correlation-ID header is included but contains an empty value in outgoing HTTP requests.
  2. The HTTP API middleware does not generate a new Correlation ID, as the empty value bypasses the null or empty check.
  3. This results in logs and traces with invalid Correlation IDs, causing inconsistencies.

Regression?

  • ABP Version: 8.3.2
  • UI Framework: Blazor
  • Project Type: Blazor WASM
  • Environment: Development

Known Workarounds

To mitigate the issue, I replaced the existing DefaultCorrelationIdProvider implementation with a custom one in the Blazor application. This ensures that the Correlation ID is always set before outgoing requests.

Then, in the Blazor project’s Startup or Program.cs, I replaced the default implementation:

services.Replace(ServiceDescriptor.Singleton<ICorrelationIdProvider, CustomCorrelationIdProvider>());

This ensures that a valid Correlation ID is always provided for outgoing requests, resolving the issue until a proper fix is implemented in the ABP framework.

Version

8.3.2

User Interface

Blazor

Database Provider

EF Core (Default)

Tiered or separate authentication server

Tiered

Operation System

Windows (Default)

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions