Skip to content

Commit

Permalink
[Dynamic Instrumentation] DEBUG-3132 Add Memoization Cache for Redact…
Browse files Browse the repository at this point in the history
…ion Logic (#6292)

## Summary of changes
This PR introduces caching functionality to optimize redaction decisions
by implementing memoization using our Adaptive Cache system.

## Reason for change
Redaction decision-making can be computationally expensive.
  • Loading branch information
dudikeleti authored Feb 13, 2025
1 parent 8303395 commit 9d84a8d
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void InitSnapshotsSink()

// Set configs relevant for DI and Exception Debugging, using DI's environment keys.
DebuggerSnapshotSerializer.SetConfig(debuggerSettings);
Redaction.SetConfig(debuggerSettings.RedactedIdentifiers, debuggerSettings.RedactedExcludedIdentifiers, debuggerSettings.RedactedTypes);
Redaction.Instance.SetConfig(debuggerSettings.RedactedIdentifiers, debuggerSettings.RedactedExcludedIdentifiers, debuggerSettings.RedactedTypes);

// Set up the snapshots sink.
var snapshotSlicer = SnapshotSlicer.Create(debuggerSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private Expression GetItemAtIndex(JsonTextReader reader, List<ParameterExpressio

if (indexOrKey.Type == typeof(string) &&
indexOrKey is ConstantExpression expr &&
Redaction.ShouldRedact(expr.Value?.ToString(), expr.Type, out _))
Redaction.Instance.ShouldRedact(expr.Value?.ToString(), expr.Type, out _))
{
AddError($"{source?.ToString() ?? "N/A"}[{indexOrKey?.ToString() ?? "N/A"}]", "The property or field is redacted.");
return RedactedValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private Expression GetReference(JsonTextReader reader, List<ParameterExpression>

var constantValue = constant.Value?.ToString();

if (Redaction.ShouldRedact(constantValue, constant.Type, out _))
if (Redaction.Instance.ShouldRedact(constantValue, constant.Type, out _))
{
AddError(reader.Value?.ToString() ?? "N/A", "The property or field is redacted.");
return RedactedValue();
Expand Down Expand Up @@ -242,7 +242,7 @@ private Expression MemberPathExpression(Expression expression, ConstantExpressio

try
{
if (Redaction.ShouldRedact(propertyOrFieldValue, propertyOrField.Type, out _))
if (Redaction.Instance.ShouldRedact(propertyOrFieldValue, propertyOrField.Type, out _))
{
AddError($"{expression}.{propertyOrFieldValue}", "The property or field is redacted.");
return RedactedValue();
Expand Down
2 changes: 1 addition & 1 deletion tracer/src/Datadog.Trace/Debugger/LiveDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task InitializeAsync()
_subscriptionManager.SubscribeToChanges(_subscription);

DebuggerSnapshotSerializer.SetConfig(Settings);
Redaction.SetConfig(Settings.RedactedIdentifiers, Settings.RedactedExcludedIdentifiers, Settings.RedactedTypes);
Redaction.Instance.SetConfig(Settings.RedactedIdentifiers, Settings.RedactedExcludedIdentifiers, Settings.RedactedTypes);
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) => CheckUnboundProbes();

await StartAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static bool SerializeInternal(
{
try
{
if (Redaction.ShouldRedact(variableName, type, out var redactionReason))
if (Redaction.Instance.ShouldRedact(variableName, type, out var redactionReason))
{
if (variableName != null)
{
Expand Down
Loading

0 comments on commit 9d84a8d

Please sign in to comment.