-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
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:
- The
Headers
collection includes a key forX-Correlation-ID
, causingcorrelationId.IsNullOrEmpty()
to return false. - The middleware assumes the header is valid, bypassing the logic to generate a new Correlation ID.
- The system logs and traces requests with an empty Correlation ID, breaking log correlation.
Reproduction Steps
- Create a new ABP Blazor project using the ABP CLI or ABP Suite.
- Enable distributed logging or request tracking in the application.
- Make an HTTP request (e.g., an API call from a Blazor component).
- Inspect the outgoing HTTP request headers using a network monitoring tool (e.g., browser developer tools or Postman).
- Observe the behavior in the HTTP API middleware when handling the request.
Expected behavior
- The
X-Correlation-ID
header should be populated with a valid, unique value in outgoing HTTP requests from the Blazor project. - The HTTP API middleware should receive this header and use it as the Correlation ID.
Actual behavior
- The
X-Correlation-ID
header is included but contains an empty value in outgoing HTTP requests. - The HTTP API middleware does not generate a new Correlation ID, as the empty value bypasses the null or empty check.
- 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