Skip to content

Commit

Permalink
Cache printed GraphQL Query for Tracing (#6543)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Sep 25, 2023
1 parent ee46c0c commit da6efd2
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ namespace HotChocolate.Diagnostics;
public class ActivityEnricher
{
private readonly InstrumentationOptions _options;
private readonly ConditionalWeakTable<ISyntaxNode, string> _queryCache = new();

/// <summary>
/// Initializes a new instance of <see cref="ActivityEnricher"/>.
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit da6efd2

Please sign in to comment.