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

[OneCollectorExporter] eventId support #1127

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace OpenTelemetry.Exporter.OneCollector;

internal sealed class LogRecordCommonSchemaJsonSerializer : CommonSchemaJsonSerializer<LogRecord>
{
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");
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down