Log EventId and Name separately in Console and OTLP Exporter (#2802)

This commit is contained in:
Cijo Thomas 2022-01-20 09:09:24 -08:00 committed by GitHub
parent 2aa816314c
commit aad309b944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -36,7 +36,8 @@ namespace OpenTelemetry.Exporter
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}");

View File

@ -85,9 +85,10 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
}
}
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)
@ -124,5 +125,14 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
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 },
});
}
}
}