Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
tsiorvasabyte opened this issue Nov 21, 2024 · 3 comments
Closed
1 task done
Assignees
Labels

Comments

@tsiorvasabyte
Copy link

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

@maliming
Copy link
Member

Fix the problem by #21427

@ikappas
Copy link
Contributor

ikappas commented Nov 27, 2024

@maliming Thank you for fixing this issue on 9.0 branch

Could you please back-port this fix on the 8.0 branch since we have a couple of projects on .NET 8.0 LTS that we need this patched there too.

Also, it is my understanding that the fix bypasses the CorrelationId assignment/handling if not explicitly set.

This does not directly solve the inconsistency of the Blazor Web Assembly project where we need to explicitly configure a CustomCorrelationIdProvider to pass the correlation ids from the client to the server.

Is this expected behaviour, or should Abp be handling that in similar manner like app.UseCorrelationId() ? or am I missing something?

@maliming
Copy link
Member

maliming commented Nov 27, 2024

hi

Could you please back-port this fix on the 8.0 branch

ok, I will do that. #21468

we need to explicitly configure a CustomCorrelationIdProvider to pass the correlation ids from the client to the server.

We do not set CorrelationId in the angular and blazor wasm by default.

I think you can use your CustomCorrelationIdProvider.

UseCorrelationId will set CorrelationId in MVC tiered structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants