diff --git a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md index b17bc47694..4de8d3d852 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md @@ -14,6 +14,10 @@ exception is present on `LogRecord`s. ([#1082](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1082)) +* Added support for sending common schema `eventId` field when `EventId.Id` is + non-zero on `LogRecord`s. + ([#1127](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1127)) + ## 0.1.0-alpha.2 Released 2023-Mar-6 diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs index b2d2f7f957..9af77e3f22 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/LogRecordCommonSchemaJsonSerializer.cs @@ -23,6 +23,7 @@ namespace OpenTelemetry.Exporter.OneCollector; internal sealed class LogRecordCommonSchemaJsonSerializer : CommonSchemaJsonSerializer { + private static readonly JsonEncodedText EventIdProperty = JsonEncodedText.Encode("eventId"); private static readonly JsonEncodedText SeverityTextProperty = JsonEncodedText.Encode("severityText"); private static readonly JsonEncodedText SeverityNumberProperty = JsonEncodedText.Encode("severityNumber"); private static readonly JsonEncodedText BodyProperty = JsonEncodedText.Encode("body"); @@ -120,13 +121,10 @@ protected override void SerializeItemToJson(Resource resource, LogRecord item, C writer.WriteStartObject(CommonSchemaJsonSerializationHelper.DataProperty); - /* TODO: There doesn't seem to be a spot in common schema defined for - event.id so we will drop for now. - if (item.EventId.Id != 0) { writer.WriteNumber(EventIdProperty, item.EventId.Id); - }*/ + } var logLevel = (int)item.LogLevel; writer.WriteString(SeverityTextProperty, LogLevelToSeverityTextMappings[logLevel]); diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs index 5c1b506325..a42e14d2db 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/LogRecordCommonSchemaJsonSerializerTests.cs @@ -83,6 +83,19 @@ public void LogRecordCategoryNameAndEventNameJsonTest(string categoryName, strin json); } + [Fact] + public void LogRecordEventIdJsonTest() + { + string json = GetLogRecordJson(1, (index, logRecord) => + { + logRecord.EventId = new(18); + }); + + Assert.Equal( + "{\"ver\":\"4.0\",\"name\":\"Namespace.Name\",\"time\":\"2032-01-18T10:11:12Z\",\"iKey\":\"o:tenant-token\",\"data\":{\"eventId\":18,\"severityText\":\"Trace\",\"severityNumber\":1}}\n", + json); + } + [Fact] public void LogRecordTimestampJsonTest() {