From 21e899b8bdb90216302f5489f8e2036e55a17e7a Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 29 Jul 2023 09:42:23 +0800 Subject: [PATCH 1/3] Update AbpCorrelationIdMiddleware.cs --- .../Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs index 2e78d9f666..c73f8641ad 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs @@ -21,9 +21,12 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency public async Task InvokeAsync(HttpContext context, RequestDelegate next) { - var correlationId = _correlationIdProvider.Get(); - CheckAndSetCorrelationIdOnResponse(context, _options, correlationId); - await next(context); + var correlationId = GetCorrelationIdFromRequest(context); + using (_correlationIdProvider.Change(correlationId)) + { + CheckAndSetCorrelationIdOnResponse(context, _options, correlationId); + await next(context); + } } protected virtual void CheckAndSetCorrelationIdOnResponse( From 570209818de6d535c4dfcd0619c86bb653aca7f9 Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 29 Jul 2023 09:49:32 +0800 Subject: [PATCH 2/3] Update AbpCorrelationIdMiddleware.cs --- .../AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs index c73f8641ad..de93914d71 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs @@ -29,6 +29,18 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency } } + protected virtual string GetCorrelationIdFromRequest(HttpContext context) + { + string correlationId = context.Request.Headers[_options.HttpHeaderName]; + if (correlationId.IsNullOrEmpty()) + { + correlationId = Guid.NewGuid().ToString("N"); + context.Request.Headers[_options.HttpHeaderName] = correlationId; + } + + return correlationId; + } + protected virtual void CheckAndSetCorrelationIdOnResponse( HttpContext httpContext, AbpCorrelationIdOptions options, From a56288753c94e681cf010a1f1bc50b73cb0a56f0 Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 29 Jul 2023 10:02:27 +0800 Subject: [PATCH 3/3] Update AbpCorrelationIdMiddleware.cs --- .../Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs index de93914d71..a5f954c260 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using System.Threading.Tasks; @@ -29,9 +30,9 @@ public class AbpCorrelationIdMiddleware : IMiddleware, ITransientDependency } } - protected virtual string GetCorrelationIdFromRequest(HttpContext context) + protected virtual string? GetCorrelationIdFromRequest(HttpContext context) { - string correlationId = context.Request.Headers[_options.HttpHeaderName]; + var correlationId = context.Request.Headers[_options.HttpHeaderName]; if (correlationId.IsNullOrEmpty()) { correlationId = Guid.NewGuid().ToString("N");