Skip to content

Commit

Permalink
Allow serialization of Unicode characters for Exception type (#375)
Browse files Browse the repository at this point in the history
* Allow serialization of Unicode characters for Exception type
  • Loading branch information
utpilla authored May 26, 2022
1 parent dcf0156 commit 827eb25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
`StatusDescription`.
[359](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/359)

* Allow serialization of non-ASCII characters for
`LogRecord.Exception.GetType().FullName`.
[375](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/375)

## 1.2.6 [2022-Apr-21]

* Set GenevaMetricExporter temporality preference back to Delta.
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ internal int SerializeLogRecord(LogRecord logRecord)
if (logRecord.Exception != null)
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, "env_ex_type");
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, logRecord.Exception.GetType().FullName);
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, logRecord.Exception.GetType().FullName);
cntFields += 1;

cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, "env_ex_msg");
Expand Down
13 changes: 11 additions & 2 deletions test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,15 @@ public void SerializationTestWithILoggerLogWithTemplates(bool hasTableNameMappin
logger.LogInformation("Hello World!"); // unstructured logging
logger.LogError(new InvalidOperationException("Oops! Food is spoiled!"), "Hello from {food} {price}.", "artichoke", 3.99);

// Exception with a non-ASCII character in its type name
logger.LogError(new CustomException\u0418(), "Hello from {food} {price}.", "artichoke", 3.99);

var loggerWithDefaultCategory = loggerFactory.CreateLogger("DefaultCategory");
loggerWithDefaultCategory.LogInformation("Basic test");
loggerWithDefaultCategory.LogInformation("\u0418"); // Include non-ASCII characters in the message

// logRecordList should have 12 logRecord entries as there were 12 Log calls
Assert.Equal(12, logRecordList.Count);
// logRecordList should have 14 logRecord entries as there were 14 Log calls
Assert.Equal(14, logRecordList.Count);

var m_buffer = typeof(GenevaLogExporter).GetField("m_buffer", BindingFlags.NonPublic | BindingFlags.Static).GetValue(exporter) as ThreadLocal<byte[]>;

Expand Down Expand Up @@ -924,5 +928,10 @@ private void AssertFluentdForwardModeForLogRecord(GenevaExporterOptions exporter
// Epilouge
Assert.Equal("DateTime", timeFormat["TimeFormat"]);
}

// A custom exception class with non-ASCII character in the type name
private class CustomException\u0418 : Exception
{
}
}
}

0 comments on commit 827eb25

Please sign in to comment.