Skip to content

Commit

Permalink
Cache redaction results
Browse files Browse the repository at this point in the history
  • Loading branch information
dudikeleti committed Nov 15, 2024
1 parent 1527d43 commit 5d8e91e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 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.Util;
using TypeExtensions = Datadog.Trace.Debugger.Helpers.TypeExtensions;
Expand Down Expand Up @@ -169,6 +170,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 @@ -243,7 +248,7 @@ internal static bool IsRedactedType(Type type)
return RedactedTypes.Contains(typeFullName);
}

public static bool IsRedactedKeyword(string name)
internal static bool IsRedactedKeyword(string name)
{
if (string.IsNullOrEmpty(name))
{
Expand All @@ -256,13 +261,15 @@ public static bool IsRedactedKeyword(string name)

public 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 5d8e91e

Please sign in to comment.