Skip to content

Commit aad309b

Browse files
authored
Log EventId and Name separately in Console and OTLP Exporter (#2802)
1 parent 2aa8163 commit aad309b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public override ExportResult Export(in Batch<LogRecord> batch)
3636
this.WriteLine($"{"LogRecord.TraceId:".PadRight(RightPaddingLength)}{logRecord.TraceId}");
3737
this.WriteLine($"{"LogRecord.SpanId:".PadRight(RightPaddingLength)}{logRecord.SpanId}");
3838
this.WriteLine($"{"LogRecord.Timestamp:".PadRight(RightPaddingLength)}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
39-
this.WriteLine($"{"LogRecord.EventId:".PadRight(RightPaddingLength)}{logRecord.EventId}");
39+
this.WriteLine($"{"LogRecord.EventId:".PadRight(RightPaddingLength)}{logRecord.EventId.Id}");
40+
this.WriteLine($"{"LogRecord.EventName:".PadRight(RightPaddingLength)}{logRecord.EventId.Name}");
4041
this.WriteLine($"{"LogRecord.CategoryName:".PadRight(RightPaddingLength)}{logRecord.CategoryName}");
4142
this.WriteLine($"{"LogRecord.LogLevel:".PadRight(RightPaddingLength)}{logRecord.LogLevel}");
4243
this.WriteLine($"{"LogRecord.TraceFlags:".PadRight(RightPaddingLength)}{logRecord.TraceFlags}");

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord)
8585
}
8686
}
8787

88-
if (logRecord.EventId != 0)
88+
if (logRecord.EventId != default)
8989
{
90-
otlpLogRecord.Attributes.AddStringAttribute(nameof(logRecord.EventId), logRecord.EventId.ToString());
90+
otlpLogRecord.Attributes.AddIntAttribute(nameof(logRecord.EventId.Id), logRecord.EventId.Id);
91+
otlpLogRecord.Attributes.AddStringAttribute(nameof(logRecord.EventId.Name), logRecord.EventId.Name);
9192
}
9293

9394
if (logRecord.Exception != null)
@@ -124,5 +125,14 @@ private static void AddStringAttribute(this RepeatedField<OtlpCommon.KeyValue> r
124125
Value = new OtlpCommon.AnyValue { StringValue = value },
125126
});
126127
}
128+
129+
private static void AddIntAttribute(this RepeatedField<OtlpCommon.KeyValue> repeatedField, string key, int value)
130+
{
131+
repeatedField.Add(new OtlpCommon.KeyValue
132+
{
133+
Key = key,
134+
Value = new OtlpCommon.AnyValue { IntValue = value },
135+
});
136+
}
127137
}
128138
}

0 commit comments

Comments
 (0)