Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using EventIdHash to compare messages in telemetry logs #6526

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ internal class RedactedErrorLogCollector
private TaskCompletionSource<bool> _tcs = new(TaskOptions);
private bool _isEnabled = true;

private ConcurrentDictionary<uint, int> _logCounts = new();
private ConcurrentDictionary<uint, int> _logCountsReserve = new();
private ConcurrentDictionary<LogKey, int> _logCounts = new();
private ConcurrentDictionary<LogKey, int> _logCountsReserve = new();

public List<List<LogMessageData>>? GetLogs()
{
Expand All @@ -44,7 +44,7 @@ internal class RedactedErrorLogCollector
{
var logSize = log.GetApproximateSerializationSize();
// modify the message to add the final log count
var eventId = EventIdHash.Compute(log.Message, log.StackTrace);
var eventId = new LogKey(log.Message, log.StackTrace);
if (logCounts.TryGetValue(eventId, out var count) && count > 1)
{
log.Count = count;
Expand Down Expand Up @@ -91,9 +91,9 @@ public void EnqueueLog(string message, TelemetryLogLevel logLevel, DateTimeOffse
{
if (Volatile.Read(ref _isEnabled))
{
var eventId = EventIdHash.Compute(message, stackTrace);
var logKey = new LogKey(message, stackTrace);
var logCounts = _logCounts;
var newCount = logCounts.AddOrUpdate(eventId, addValue: 1, updateValueFactory: static (_, prev) => prev + 1);
var newCount = logCounts.AddOrUpdate(logKey, addValue: 1, updateValueFactory: static (_, prev) => prev + 1);
if (newCount != 1)
{
// already have this log, so don't enqueue it again
Expand Down Expand Up @@ -143,4 +143,10 @@ public void DisableCollector()
{
}
}

private readonly record struct LogKey(string Message, string? StackTrace)
{
public readonly string Message = Message;
public readonly string? StackTrace = StackTrace;
}
}
Loading