From 827eb256890889aeb72d0d641beb92ebd9819b94 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Wed, 25 May 2022 19:25:46 -0700 Subject: [PATCH] Allow serialization of Unicode characters for Exception type (#375) * Allow serialization of Unicode characters for Exception type --- src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md | 4 ++++ .../GenevaLogExporter.cs | 2 +- .../GenevaLogExporterTests.cs | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index 098f363cdd..8d34b86063 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -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. diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs index 60089b093e..175421f70c 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs @@ -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"); diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs index 9d591c2f0d..45a4833f4e 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs @@ -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; @@ -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 + { + } } }