From 90c0223c13905d952b44ceb4f2c74f695db5ae60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Mon, 7 Oct 2024 21:45:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88404=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=B7=AF=E5=BE=84=E7=9A=84=E5=9F=8B=E7=82=B9=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8DTraceItem=E8=BF=87=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CubeDemoNC/CubeDemoNC.csproj | 2 +- CubeSSO/CubeSSO.csproj | 2 +- NewLife.Cube/NewLife.Cube.csproj | 2 +- NewLife.CubeNC/NewLife.CubeNC.csproj | 2 +- NewLife.CubeNC/WebMiddleware/TracerMiddleware.cs | 12 ++++++++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CubeDemoNC/CubeDemoNC.csproj b/CubeDemoNC/CubeDemoNC.csproj index 36f4a511..266d05a9 100644 --- a/CubeDemoNC/CubeDemoNC.csproj +++ b/CubeDemoNC/CubeDemoNC.csproj @@ -38,7 +38,7 @@ - + diff --git a/CubeSSO/CubeSSO.csproj b/CubeSSO/CubeSSO.csproj index c7563175..2ecd91fc 100644 --- a/CubeSSO/CubeSSO.csproj +++ b/CubeSSO/CubeSSO.csproj @@ -23,7 +23,7 @@ - + diff --git a/NewLife.Cube/NewLife.Cube.csproj b/NewLife.Cube/NewLife.Cube.csproj index 461a4c31..44db86bd 100644 --- a/NewLife.Cube/NewLife.Cube.csproj +++ b/NewLife.Cube/NewLife.Cube.csproj @@ -99,7 +99,7 @@ - + diff --git a/NewLife.CubeNC/NewLife.CubeNC.csproj b/NewLife.CubeNC/NewLife.CubeNC.csproj index 3a39f3cb..92e09a3c 100644 --- a/NewLife.CubeNC/NewLife.CubeNC.csproj +++ b/NewLife.CubeNC/NewLife.CubeNC.csproj @@ -50,7 +50,7 @@ - + diff --git a/NewLife.CubeNC/WebMiddleware/TracerMiddleware.cs b/NewLife.CubeNC/WebMiddleware/TracerMiddleware.cs index 61908331..52adf5a5 100644 --- a/NewLife.CubeNC/WebMiddleware/TracerMiddleware.cs +++ b/NewLife.CubeNC/WebMiddleware/TracerMiddleware.cs @@ -1,4 +1,5 @@ using System.Net; +using NewLife.Collections; using NewLife.Log; using NewLife.Web; using HttpContext = Microsoft.AspNetCore.Http.HttpContext; @@ -46,10 +47,11 @@ public async Task Invoke(HttpContext ctx) { req.EnableBuffering(); - var buf = new Byte[1024]; + var buf = Pool.Shared.Rent(1024); var count = await req.Body.ReadAsync(buf, 0, buf.Length); span.AppendTag("\r\n<=\r\n" + buf.ToStr(null, 0, count)); req.Body.Position = 0; + Pool.Shared.Return(buf); flag = true; } @@ -95,11 +97,12 @@ public async Task Invoke(HttpContext ctx) res.ContentType != null && res.ContentType.StartsWithIgnoreCase(TagTypes)) { - var buf = new Byte[1024]; + var buf = Pool.Shared.Rent(1024); var p = res.Body.Position; var count = await res.Body.ReadAsync(buf, 0, buf.Length); span.AppendTag("\r\n=>\r\n" + buf.ToStr(null, 0, count)); res.Body.Position = p; + Pool.Shared.Return(buf); flag = true; } @@ -117,6 +120,11 @@ public async Task Invoke(HttpContext ctx) } } } + else if (code == 404) + { + // 取消404找不到路径的埋点,避免TraceItem过多 + span?.Abandon(); + } } } catch (Exception ex)