diff --git a/src/HotChocolate/Diagnostics/src/Diagnostics/ActivityEnricher.cs b/src/HotChocolate/Diagnostics/src/Diagnostics/ActivityEnricher.cs index daec6c69560..788a963fa7f 100644 --- a/src/HotChocolate/Diagnostics/src/Diagnostics/ActivityEnricher.cs +++ b/src/HotChocolate/Diagnostics/src/Diagnostics/ActivityEnricher.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; using Microsoft.AspNetCore.Http; @@ -26,6 +27,7 @@ namespace HotChocolate.Diagnostics; public class ActivityEnricher { private readonly InstrumentationOptions _options; + private readonly ConditionalWeakTable _queryCache = new(); /// /// Initializes a new instance of . @@ -108,7 +110,13 @@ public virtual void EnrichSingleRequest( if (request.Query is not null && (_options.RequestDetails & RequestDetails.Query) == RequestDetails.Query) { - activity.SetTag("graphql.http.request.query.body", request.Query.Print()); + if (!_queryCache.TryGetValue(request.Query, out var query)) + { + query = request.Query.Print(); + _queryCache.Add(request.Query, query); + } + + activity.SetTag("graphql.http.request.query.body", query); } if (request.OperationName is not null &&