Skip to content

Commit

Permalink
Cache redaction results
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Feb 7, 2025
1 parent 02d20a4 commit 0052195
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tracer/src/Datadog.Trace/Debugger/Snapshots/Redaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using Datadog.Trace.Debugger.Caching;
using Datadog.Trace.Debugger.Configurations;
using Datadog.Trace.Logging;
using TypeExtensions = Datadog.Trace.Debugger.Helpers.TypeExtensions;
Expand Down Expand Up @@ -172,6 +173,10 @@ internal static class Redaction
"xsrftoken"
];

private static ConcurrentAdaptiveCache<Type, bool> _redactedTypesCache = new(evictionPolicyKind:EvictionPolicy.LFU);

private static ConcurrentAdaptiveCache<string, bool> _redactedKeywordsCache = new(evictionPolicyKind: EvictionPolicy.LFU);

internal static bool IsSafeToCallToString(Type type)
{
return TypeExtensions.IsSimple(type) ||
Expand Down Expand Up @@ -271,13 +276,15 @@ internal static bool IsRedactedKeyword(string name)

internal static bool ShouldRedact(string name, Type type, out RedactionReason redactionReason)
{
if (IsRedactedKeyword(name))
var redactedKeyword = _redactedKeywordsCache.GetOrAdd(name, IsRedactedKeyword);
if (redactedKeyword)
{
redactionReason = RedactionReason.Identifier;
return true;
}

if (IsRedactedType(type))
var redactedType = _redactedTypesCache.GetOrAdd(type, IsRedactedType);
if (redactedType)
{
redactionReason = RedactionReason.Type;
return true;
Expand Down

0 comments on commit 0052195

Please sign in to comment.