From 87980ac6ce922bae762f405e93a98fa008cade8b Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 11:46:27 -0700 Subject: [PATCH 01/10] Temporarily remove ilogger and ex attributes --- .../Implementation/LogRecordExtensions.cs | 8 +- .../OtlpLogExporterTests.cs | 281 ++++++++++-------- 2 files changed, 170 insertions(+), 119 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index 294ce6454f2..c4b14f45f7d 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -16,9 +16,7 @@ using System.Runtime.CompilerServices; using Google.Protobuf; -using OpenTelemetry.Internal; using OpenTelemetry.Logs; -using OpenTelemetry.Trace; using OtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1; using OtlpCommon = OpenTelemetry.Proto.Common.V1; using OtlpLogs = OpenTelemetry.Proto.Logs.V1; @@ -79,7 +77,10 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO var attributeValueLengthLimit = sdkLimitOptions.AttributeValueLengthLimit; var attributeCountLimit = sdkLimitOptions.AttributeCountLimit ?? int.MaxValue; - +/* + // Removing this temporarily for stable release + // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4776 + // https://github.com/open-telemetry/opentelemetry-dotnet/issues/3491 // First add the generic attributes like Category, EventId and Exception, // so they are less likely being dropped because of AttributeCountLimit. @@ -109,6 +110,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit); otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString(), attributeValueLengthLimit, attributeCountLimit); } +*/ bool bodyPopulatedFromFormattedMessage = false; if (logRecord.FormattedMessage != null) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index ed1aa8f5fc1..7866cf9ef8b 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -184,109 +184,112 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); - Assert.Equal(4, otlpLogRecord.Attributes.Count); - - var attribute = otlpLogRecord.Attributes[0]; + Assert.Equal(3, otlpLogRecord.Attributes.Count); + var index = 0; + var attribute = otlpLogRecord.Attributes[index]; +/* Assert.Equal("dotnet.ilogger.category", attribute.Key); Assert.Equal("OtlpLogExporterTests", attribute.Value.StringValue); - - attribute = otlpLogRecord.Attributes[1]; + attribute = otlpLogRecord.Attributes[++index]; +*/ Assert.Equal("name", attribute.Key); Assert.Equal("tomato", attribute.Value.StringValue); - attribute = otlpLogRecord.Attributes[2]; + attribute = otlpLogRecord.Attributes[++index]; Assert.Equal("price", attribute.Key); Assert.Equal(2.99, attribute.Value.DoubleValue); - attribute = otlpLogRecord.Attributes[3]; + attribute = otlpLogRecord.Attributes[++index]; Assert.Equal("{OriginalFormat}", attribute.Key); Assert.Equal("Hello from {name} {price}.", attribute.Value.StringValue); } - [Fact] - public void CheckToOtlpLogRecordLoggerCategory() - { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + /* + [Fact] + public void CheckToOtlpLogRecordLoggerCategory() { - builder.AddOpenTelemetry(options => + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - options.AddInMemoryExporter(logRecords); + builder.AddOpenTelemetry(options => + { + options.AddInMemoryExporter(logRecords); + }); }); - }); - var logger1 = loggerFactory.CreateLogger("CategoryA"); - logger1.LogInformation("Hello"); - Assert.Single(logRecords); + var logger1 = loggerFactory.CreateLogger("CategoryA"); + logger1.LogInformation("Hello"); + Assert.Single(logRecords); - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Single(otlpLogRecord.Attributes); + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Single(otlpLogRecord.Attributes); - var attribute = otlpLogRecord.Attributes[0]; - Assert.Equal("dotnet.ilogger.category", attribute.Key); - Assert.Equal("CategoryA", attribute.Value.StringValue); + var attribute = otlpLogRecord.Attributes[0]; + Assert.Equal("dotnet.ilogger.category", attribute.Key); + Assert.Equal("CategoryA", attribute.Value.StringValue); - logRecords.Clear(); - var logger2 = loggerFactory.CreateLogger(string.Empty); - logger2.LogInformation("Hello"); - Assert.Single(logRecords); + logRecords.Clear(); + var logger2 = loggerFactory.CreateLogger(string.Empty); + logger2.LogInformation("Hello"); + Assert.Single(logRecords); - logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Empty(otlpLogRecord.Attributes); - } + logRecord = logRecords[0]; + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Empty(otlpLogRecord.Attributes); + } - [Fact] - public void CheckToOtlpLogRecordEventId() - { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + [Fact] + public void CheckToOtlpLogRecordEventId() { - builder.AddOpenTelemetry(options => + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - options.IncludeFormattedMessage = true; - options.ParseStateValues = true; - options.AddInMemoryExporter(logRecords); + builder.AddOpenTelemetry(options => + { + options.IncludeFormattedMessage = true; + options.ParseStateValues = true; + options.AddInMemoryExporter(logRecords); + }); }); - }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new EventId(10, null), "Hello from {name} {price}.", "tomato", 2.99); - Assert.Single(logRecords); + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new EventId(10, null), "Hello from {name} {price}.", "tomato", 2.99); + Assert.Single(logRecords); - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); + Assert.NotNull(otlpLogRecord); + Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); - var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - // Event - Assert.Contains("Id", otlpLogRecordAttributes); - Assert.Contains("10", otlpLogRecordAttributes); + // Event + Assert.Contains("Id", otlpLogRecordAttributes); + Assert.Contains("10", otlpLogRecordAttributes); - logRecords.Clear(); + logRecords.Clear(); - logger.LogInformation(new EventId(10, "MyEvent10"), "Hello from {name} {price}.", "tomato", 2.99); - Assert.Single(logRecords); + logger.LogInformation(new EventId(10, "MyEvent10"), "Hello from {name} {price}.", "tomato", 2.99); + Assert.Single(logRecords); - logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); + logRecord = logRecords[0]; + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); - otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - // Event - Assert.Contains("Id", otlpLogRecordAttributes); - Assert.Contains("10", otlpLogRecordAttributes); - Assert.Contains("Name", otlpLogRecordAttributes); - Assert.Contains("MyEvent10", otlpLogRecordAttributes); - } + // Event + Assert.Contains("Id", otlpLogRecordAttributes); + Assert.Contains("10", otlpLogRecordAttributes); + Assert.Contains("Name", otlpLogRecordAttributes); + Assert.Contains("MyEvent10", otlpLogRecordAttributes); + } + */ [Fact] public void CheckToOtlpLogRecordTimestamps() @@ -485,43 +488,88 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Equal("state", otlpLogRecord.Body.StringValue); } - [Fact] - public void CheckToOtlpLogRecordExceptionAttributes() - { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + /* + [Fact] + public void CheckToOtlpLogRecordExceptionAttributes() { - builder.AddOpenTelemetry(options => + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - options.AddInMemoryExporter(logRecords); + builder.AddOpenTelemetry(options => + { + options.AddInMemoryExporter(logRecords); + }); }); - }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new Exception("Exception Message"), "Exception Occurred"); + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new Exception("Exception Message"), "Exception Occurred"); - var logRecord = logRecords[0]; - var loggedException = logRecord.Exception; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var logRecord = logRecords[0]; + var loggedException = logRecord.Exception; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes); + Assert.NotNull(otlpLogRecord); + var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes); - Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes); + Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes); - Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); - } + Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); + } + [Fact] + public void CheckToOtlpLogRecordRespectsAttributeLimits() + { + var sdkLimitOptions = new SdkLimitOptions + { + AttributeCountLimit = 2, + AttributeValueLengthLimit = 8, + }; + + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => + { + builder.AddOpenTelemetry(options => + { + options.AddInMemoryExporter(logRecords); + }); + }); + + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new NotSupportedException("I'm the exception message."), "Exception Occurred"); + + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); + + Assert.NotNull(otlpLogRecord); + Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); + + var exceptionTypeAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType); + Assert.NotNull(exceptionTypeAtt); + + // "NotSuppo" == first 8 chars from the exception typename "NotSupportedException" + Assert.Equal("NotSuppo", exceptionTypeAtt.Value.StringValue); + var exceptionMessageAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage); + Assert.NotNull(exceptionMessageAtt); + + // "I'm the " == first 8 chars from the exception message + Assert.Equal("I'm the ", exceptionMessageAtt.Value.StringValue); + + var exceptionStackTraceAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace); + Assert.Null(exceptionStackTraceAtt); + } + */ + + // Remove this when adding back the category, eventid and exception attributes [Fact] public void CheckToOtlpLogRecordRespectsAttributeLimits() { var sdkLimitOptions = new SdkLimitOptions { - AttributeCountLimit = 3, // 3 => LogCategory, exception.type and exception.message + AttributeCountLimit = 2, AttributeValueLengthLimit = 8, }; @@ -530,12 +578,13 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() { builder.AddOpenTelemetry(options => { + options.ParseStateValues = true; options.AddInMemoryExporter(logRecords); }); }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new NotSupportedException("I'm the exception message."), "Exception Occurred"); + var logger = loggerFactory.CreateLogger(string.Empty); + logger.LogInformation("OpenTelemetry {AttributeOne} {AttributeTwo} {AttributeThree}!", "I'm an attribute", "I too am an attribute", "I get dropped :("); var logRecord = logRecords[0]; var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); @@ -543,19 +592,19 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() Assert.NotNull(otlpLogRecord); Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); - var exceptionTypeAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType); - Assert.NotNull(exceptionTypeAtt); + var attribute = TryGetAttribute(otlpLogRecord, "AttributeOne"); + Assert.NotNull(attribute); - // "NotSuppo" == first 8 chars from the exception typename "NotSupportedException" - Assert.Equal("NotSuppo", exceptionTypeAtt.Value.StringValue); - var exceptionMessageAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage); - Assert.NotNull(exceptionMessageAtt); + // "I'm an a" == first 8 chars from the first attribute "I'm an attribute" + Assert.Equal("I'm an a", attribute.Value.StringValue); + attribute = TryGetAttribute(otlpLogRecord, "AttributeTwo"); + Assert.NotNull(attribute); - // "I'm the " == first 8 chars from the exception message - Assert.Equal("I'm the ", exceptionMessageAtt.Value.StringValue); + // "I too am" == first 8 chars from the second attribute "I too am an attribute" + Assert.Equal("I too am", attribute.Value.StringValue); - var exceptionStackTraceAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace); - Assert.Null(exceptionStackTraceAtt); + attribute = TryGetAttribute(otlpLogRecord, "AttributeThree"); + Assert.Null(attribute); } [Fact] @@ -686,7 +735,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeStrin // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -725,7 +774,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeBoolV // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -776,7 +825,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeIntVa // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -815,7 +864,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -854,7 +903,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -888,7 +937,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfTypeString var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); Assert.NotNull(otlpLogRecord); - Assert.Single(otlpLogRecord.Attributes); + Assert.Empty(otlpLogRecord.Attributes); } [Theory] @@ -923,7 +972,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfPrimitiveT var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); Assert.NotNull(otlpLogRecord); - Assert.Single(otlpLogRecord.Attributes); + Assert.Empty(otlpLogRecord.Attributes); } [Fact] @@ -954,7 +1003,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfDictionary // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -993,7 +1042,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfEnumerable // Assert. var logRecord = logRecords.Single(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.Equal(2, otlpLogRecord.Attributes.Count); + Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); Assert.Equal(scopeKey, actualScope.Key); @@ -1036,7 +1085,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopesAreAdded_C var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); - Assert.Equal(3, otlpLogRecord.Attributes.Count); + Assert.Equal(2, otlpLogRecord.Attributes.Count); Assert.Equal(2, allScopeValues.Count()); Assert.Contains(scopeValue1, allScopeValues); Assert.Contains(scopeValue2, allScopeValues); @@ -1077,7 +1126,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopeLevelsAreAd var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); - Assert.Equal(3, otlpLogRecord.Attributes.Count); + Assert.Equal(2, otlpLogRecord.Attributes.Count); Assert.Equal(2, allScopeValues.Count()); Assert.Contains(scopeValue1, allScopeValues); Assert.Contains(scopeValue2, allScopeValues); @@ -1123,7 +1172,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); - Assert.Equal(7, otlpLogRecord.Attributes.Count); + Assert.Equal(2, otlpLogRecord.Attributes.Count); Assert.Equal(2, allScopeValues.Count()); Assert.Contains(scopeValue1, allScopeValues); Assert.Contains(scopeValue2, allScopeValues); From 65aa7efb8bc2074e53f95ccaf869a63f98288b40 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 11:56:05 -0700 Subject: [PATCH 02/10] add changelog --- .../CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index fc9afc5e825..ce05d47c179 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +* Excluded attributes corresponding to `LogRecord.EventId`, +`LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. This +is done in order to move ahead with stable release of exporter. THe attributes +will be brought back in the pre-release version post stable release. +([#4781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4781)) + * Added extension method for configuring export processor options for otlp log exporter. ([#4733](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4733)) From 619d2bd6dfb95aa5385ebbd149dd4b0c9f377bf0 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 11:58:29 -0700 Subject: [PATCH 03/10] Update CHANGELOG.md --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index ce05d47c179..b4d4e5a4697 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -4,7 +4,7 @@ * Excluded attributes corresponding to `LogRecord.EventId`, `LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. This -is done in order to move ahead with stable release of exporter. THe attributes +is done in order to move ahead with stable release of exporter. The attributes will be brought back in the pre-release version post stable release. ([#4781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4781)) From e5c892f71ea3389746249e720cd7f05cbab5975c Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 12:07:00 -0700 Subject: [PATCH 04/10] format --- .../Implementation/LogRecordExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index c4b14f45f7d..ccbe7323e21 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -77,6 +77,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO var attributeValueLengthLimit = sdkLimitOptions.AttributeValueLengthLimit; var attributeCountLimit = sdkLimitOptions.AttributeCountLimit ?? int.MaxValue; + /* // Removing this temporarily for stable release // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4776 From 6ca7e06d35fb6b56b8524cb9baeff0a75bd2c168 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 12:09:23 -0700 Subject: [PATCH 05/10] rmv using --- .../OtlpLogExporterTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 7866cf9ef8b..26a0a6d7e54 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -23,7 +23,6 @@ using Moq; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; -using OpenTelemetry.Internal; using OpenTelemetry.Logs; using OpenTelemetry.Tests; using OpenTelemetry.Trace; From 3325b40588044a6bb2e74746e71b47dfc8fb42c8 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 12:14:54 -0700 Subject: [PATCH 06/10] format --- .../Implementation/LogRecordExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index ccbe7323e21..3fba6ff8cb8 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -78,7 +78,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO var attributeValueLengthLimit = sdkLimitOptions.AttributeValueLengthLimit; var attributeCountLimit = sdkLimitOptions.AttributeCountLimit ?? int.MaxValue; -/* + /* // Removing this temporarily for stable release // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4776 // https://github.com/open-telemetry/opentelemetry-dotnet/issues/3491 @@ -111,7 +111,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit); otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString(), attributeValueLengthLimit, attributeCountLimit); } -*/ + */ bool bodyPopulatedFromFormattedMessage = false; if (logRecord.FormattedMessage != null) From 79295b4e5489d952dd81ce2ccd12b54b94c31beb Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Thu, 17 Aug 2023 12:19:38 -0700 Subject: [PATCH 07/10] format test --- .../OtlpLogExporterTests.cs | 234 +++++++++--------- 1 file changed, 118 insertions(+), 116 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 26a0a6d7e54..6fc7f18115b 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -186,11 +186,13 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.Equal(3, otlpLogRecord.Attributes.Count); var index = 0; var attribute = otlpLogRecord.Attributes[index]; -/* + + /* Assert.Equal("dotnet.ilogger.category", attribute.Key); Assert.Equal("OtlpLogExporterTests", attribute.Value.StringValue); attribute = otlpLogRecord.Attributes[++index]; -*/ + */ + Assert.Equal("name", attribute.Key); Assert.Equal("tomato", attribute.Value.StringValue); @@ -204,90 +206,90 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() } /* - [Fact] - public void CheckToOtlpLogRecordLoggerCategory() + [Fact] + public void CheckToOtlpLogRecordLoggerCategory() + { + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + builder.AddOpenTelemetry(options => { - builder.AddOpenTelemetry(options => - { - options.AddInMemoryExporter(logRecords); - }); + options.AddInMemoryExporter(logRecords); }); + }); - var logger1 = loggerFactory.CreateLogger("CategoryA"); - logger1.LogInformation("Hello"); - Assert.Single(logRecords); + var logger1 = loggerFactory.CreateLogger("CategoryA"); + logger1.LogInformation("Hello"); + Assert.Single(logRecords); - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Single(otlpLogRecord.Attributes); + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Single(otlpLogRecord.Attributes); - var attribute = otlpLogRecord.Attributes[0]; - Assert.Equal("dotnet.ilogger.category", attribute.Key); - Assert.Equal("CategoryA", attribute.Value.StringValue); + var attribute = otlpLogRecord.Attributes[0]; + Assert.Equal("dotnet.ilogger.category", attribute.Key); + Assert.Equal("CategoryA", attribute.Value.StringValue); - logRecords.Clear(); - var logger2 = loggerFactory.CreateLogger(string.Empty); - logger2.LogInformation("Hello"); - Assert.Single(logRecords); + logRecords.Clear(); + var logger2 = loggerFactory.CreateLogger(string.Empty); + logger2.LogInformation("Hello"); + Assert.Single(logRecords); - logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Empty(otlpLogRecord.Attributes); - } + logRecord = logRecords[0]; + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Empty(otlpLogRecord.Attributes); + } - [Fact] - public void CheckToOtlpLogRecordEventId() + [Fact] + public void CheckToOtlpLogRecordEventId() + { + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + builder.AddOpenTelemetry(options => { - builder.AddOpenTelemetry(options => - { - options.IncludeFormattedMessage = true; - options.ParseStateValues = true; - options.AddInMemoryExporter(logRecords); - }); + options.IncludeFormattedMessage = true; + options.ParseStateValues = true; + options.AddInMemoryExporter(logRecords); }); + }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new EventId(10, null), "Hello from {name} {price}.", "tomato", 2.99); - Assert.Single(logRecords); + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new EventId(10, null), "Hello from {name} {price}.", "tomato", 2.99); + Assert.Single(logRecords); - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); + Assert.NotNull(otlpLogRecord); + Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); - var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - // Event - Assert.Contains("Id", otlpLogRecordAttributes); - Assert.Contains("10", otlpLogRecordAttributes); + // Event + Assert.Contains("Id", otlpLogRecordAttributes); + Assert.Contains("10", otlpLogRecordAttributes); - logRecords.Clear(); + logRecords.Clear(); - logger.LogInformation(new EventId(10, "MyEvent10"), "Hello from {name} {price}.", "tomato", 2.99); - Assert.Single(logRecords); + logger.LogInformation(new EventId(10, "MyEvent10"), "Hello from {name} {price}.", "tomato", 2.99); + Assert.Single(logRecords); - logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); + logRecord = logRecords[0]; + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + Assert.NotNull(otlpLogRecord); + Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); - otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - // Event - Assert.Contains("Id", otlpLogRecordAttributes); - Assert.Contains("10", otlpLogRecordAttributes); - Assert.Contains("Name", otlpLogRecordAttributes); - Assert.Contains("MyEvent10", otlpLogRecordAttributes); - } + // Event + Assert.Contains("Id", otlpLogRecordAttributes); + Assert.Contains("10", otlpLogRecordAttributes); + Assert.Contains("Name", otlpLogRecordAttributes); + Assert.Contains("MyEvent10", otlpLogRecordAttributes); + } */ [Fact] @@ -488,78 +490,78 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) } /* - [Fact] - public void CheckToOtlpLogRecordExceptionAttributes() + [Fact] + public void CheckToOtlpLogRecordExceptionAttributes() + { + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => { - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + builder.AddOpenTelemetry(options => { - builder.AddOpenTelemetry(options => - { - options.AddInMemoryExporter(logRecords); - }); + options.AddInMemoryExporter(logRecords); }); + }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new Exception("Exception Message"), "Exception Occurred"); + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new Exception("Exception Message"), "Exception Occurred"); - var logRecord = logRecords[0]; - var loggedException = logRecord.Exception; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var logRecord = logRecords[0]; + var loggedException = logRecord.Exception; + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); - Assert.NotNull(otlpLogRecord); - var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); - Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes); + Assert.NotNull(otlpLogRecord); + var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); + Assert.Contains(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.GetType().Name, otlpLogRecordAttributes); - Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes); + Assert.Contains(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.Message, otlpLogRecordAttributes); - Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); - } + Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); + } - [Fact] - public void CheckToOtlpLogRecordRespectsAttributeLimits() + [Fact] + public void CheckToOtlpLogRecordRespectsAttributeLimits() + { + var sdkLimitOptions = new SdkLimitOptions { - var sdkLimitOptions = new SdkLimitOptions - { - AttributeCountLimit = 2, - AttributeValueLengthLimit = 8, - }; + AttributeCountLimit = 2, + AttributeValueLengthLimit = 8, + }; - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => + var logRecords = new List(); + using var loggerFactory = LoggerFactory.Create(builder => + { + builder.AddOpenTelemetry(options => { - builder.AddOpenTelemetry(options => - { - options.AddInMemoryExporter(logRecords); - }); + options.AddInMemoryExporter(logRecords); }); + }); - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new NotSupportedException("I'm the exception message."), "Exception Occurred"); + var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); + logger.LogInformation(new NotSupportedException("I'm the exception message."), "Exception Occurred"); - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); + var logRecord = logRecords[0]; + var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); - Assert.NotNull(otlpLogRecord); - Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); + Assert.NotNull(otlpLogRecord); + Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); - var exceptionTypeAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType); - Assert.NotNull(exceptionTypeAtt); + var exceptionTypeAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType); + Assert.NotNull(exceptionTypeAtt); - // "NotSuppo" == first 8 chars from the exception typename "NotSupportedException" - Assert.Equal("NotSuppo", exceptionTypeAtt.Value.StringValue); - var exceptionMessageAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage); - Assert.NotNull(exceptionMessageAtt); + // "NotSuppo" == first 8 chars from the exception typename "NotSupportedException" + Assert.Equal("NotSuppo", exceptionTypeAtt.Value.StringValue); + var exceptionMessageAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage); + Assert.NotNull(exceptionMessageAtt); - // "I'm the " == first 8 chars from the exception message - Assert.Equal("I'm the ", exceptionMessageAtt.Value.StringValue); + // "I'm the " == first 8 chars from the exception message + Assert.Equal("I'm the ", exceptionMessageAtt.Value.StringValue); - var exceptionStackTraceAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace); - Assert.Null(exceptionStackTraceAtt); - } + var exceptionStackTraceAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace); + Assert.Null(exceptionStackTraceAtt); + } */ // Remove this when adding back the category, eventid and exception attributes From 576429cd6e95915f8d3287635061311ed660a817 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 18 Aug 2023 09:27:26 -0700 Subject: [PATCH 08/10] pr feedback --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index b4d4e5a4697..b3afcb87551 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -3,9 +3,7 @@ ## Unreleased * Excluded attributes corresponding to `LogRecord.EventId`, -`LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. This -is done in order to move ahead with stable release of exporter. The attributes -will be brought back in the pre-release version post stable release. +`LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. ([#4781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4781)) * Added extension method for configuring export processor options for otlp log From e6b314c237d6e6192f64bb3046c31a8f0bb6ae0c Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Fri, 18 Aug 2023 09:35:23 -0700 Subject: [PATCH 09/10] address feedback --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index b3afcb87551..6c45771e0a0 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -3,7 +3,8 @@ ## Unreleased * Excluded attributes corresponding to `LogRecord.EventId`, -`LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. +`LogRecord.CategoryName` and `LogRecord.Exception` from the exported data. This +is done as the semantic conventions for these attributes are not yet stable. ([#4781](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4781)) * Added extension method for configuring export processor options for otlp log From 1fbc66de544b342bff18704fa5f476d126d16b3c Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 21 Aug 2023 08:11:31 -0700 Subject: [PATCH 10/10] addres feedback --- .../OtlpLogExporterTests.cs | 43 ------------------- 1 file changed, 43 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 6fc7f18115b..7a32a4a34eb 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -520,51 +520,8 @@ public void CheckToOtlpLogRecordExceptionAttributes() Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); } - - [Fact] - public void CheckToOtlpLogRecordRespectsAttributeLimits() - { - var sdkLimitOptions = new SdkLimitOptions - { - AttributeCountLimit = 2, - AttributeValueLengthLimit = 8, - }; - - var logRecords = new List(); - using var loggerFactory = LoggerFactory.Create(builder => - { - builder.AddOpenTelemetry(options => - { - options.AddInMemoryExporter(logRecords); - }); - }); - - var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); - logger.LogInformation(new NotSupportedException("I'm the exception message."), "Exception Occurred"); - - var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); - - Assert.NotNull(otlpLogRecord); - Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); - - var exceptionTypeAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType); - Assert.NotNull(exceptionTypeAtt); - - // "NotSuppo" == first 8 chars from the exception typename "NotSupportedException" - Assert.Equal("NotSuppo", exceptionTypeAtt.Value.StringValue); - var exceptionMessageAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage); - Assert.NotNull(exceptionMessageAtt); - - // "I'm the " == first 8 chars from the exception message - Assert.Equal("I'm the ", exceptionMessageAtt.Value.StringValue); - - var exceptionStackTraceAtt = TryGetAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace); - Assert.Null(exceptionStackTraceAtt); - } */ - // Remove this when adding back the category, eventid and exception attributes [Fact] public void CheckToOtlpLogRecordRespectsAttributeLimits() {