36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using System.Diagnostics;
|
|
using OpenTelemetry;
|
|
|
|
namespace Nexus.Api.Observability;
|
|
|
|
/// <summary>
|
|
/// Removes content-bearing attributes before an activity reaches an exporter.
|
|
/// Standard HTTP exception recording is disabled separately so exception
|
|
/// events cannot contain messages or stack traces.
|
|
/// </summary>
|
|
public sealed class NexusTelemetryRedactionProcessor : BaseProcessor<Activity>
|
|
{
|
|
private static readonly HashSet<string> RedactedTagNames = new(
|
|
[
|
|
"url.query",
|
|
"url.full",
|
|
"url.path",
|
|
"http.url",
|
|
"http.target",
|
|
"exception.message",
|
|
"exception.stacktrace",
|
|
"db.statement",
|
|
"db.query.text"
|
|
],
|
|
StringComparer.OrdinalIgnoreCase);
|
|
|
|
public override void OnEnd(Activity activity)
|
|
{
|
|
foreach (var tag in activity.TagObjects.ToArray())
|
|
{
|
|
if (RedactedTagNames.Contains(tag.Key))
|
|
activity.SetTag(tag.Key, null);
|
|
}
|
|
}
|
|
}
|