Skip to content

Commit

Permalink
Log EventId and Name separately in Console and OTLP Exporter (#2802)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jan 20, 2022
1 parent 2aa8163 commit aad309b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public override ExportResult Export(in Batch<LogRecord> batch)
this.WriteLine($"{"LogRecord.TraceId:".PadRight(RightPaddingLength)}{logRecord.TraceId}");
this.WriteLine($"{"LogRecord.SpanId:".PadRight(RightPaddingLength)}{logRecord.SpanId}");
this.WriteLine($"{"LogRecord.Timestamp:".PadRight(RightPaddingLength)}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
this.WriteLine($"{"LogRecord.EventId:".PadRight(RightPaddingLength)}{logRecord.EventId}");
this.WriteLine($"{"LogRecord.EventId:".PadRight(RightPaddingLength)}{logRecord.EventId.Id}");
this.WriteLine($"{"LogRecord.EventName:".PadRight(RightPaddingLength)}{logRecord.EventId.Name}");
this.WriteLine($"{"LogRecord.CategoryName:".PadRight(RightPaddingLength)}{logRecord.CategoryName}");
this.WriteLine($"{"LogRecord.LogLevel:".PadRight(RightPaddingLength)}{logRecord.LogLevel}");
this.WriteLine($"{"LogRecord.TraceFlags:".PadRight(RightPaddingLength)}{logRecord.TraceFlags}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord)
}
}

if (logRecord.EventId != 0)
if (logRecord.EventId != default)
{
otlpLogRecord.Attributes.AddStringAttribute(nameof(logRecord.EventId), logRecord.EventId.ToString());
otlpLogRecord.Attributes.AddIntAttribute(nameof(logRecord.EventId.Id), logRecord.EventId.Id);
otlpLogRecord.Attributes.AddStringAttribute(nameof(logRecord.EventId.Name), logRecord.EventId.Name);
}

if (logRecord.Exception != null)
Expand Down Expand Up @@ -124,5 +125,14 @@ private static void AddStringAttribute(this RepeatedField<OtlpCommon.KeyValue> r
Value = new OtlpCommon.AnyValue { StringValue = value },
});
}

private static void AddIntAttribute(this RepeatedField<OtlpCommon.KeyValue> repeatedField, string key, int value)
{
repeatedField.Add(new OtlpCommon.KeyValue
{
Key = key,
Value = new OtlpCommon.AnyValue { IntValue = value },
});
}
}
}

0 comments on commit aad309b

Please sign in to comment.