From 106be5a1907b1f29b9e5fcf52e63150ad51f7852 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 26 Sep 2023 15:07:28 -0700 Subject: [PATCH 01/14] Add log exception attributes under feature flag --- .../Implementation/ExperimentalFeatures.cs | 43 +++++++++ .../Implementation/LogRecordExtensions.cs | 13 ++- .../OtlpLogExporter.cs | 4 +- .../OtlpLogExporterTests.cs | 95 +++++++++++-------- 4 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs new file mode 100644 index 00000000000..acb84bc15d6 --- /dev/null +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs @@ -0,0 +1,43 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using Microsoft.Extensions.Configuration; +using OpenTelemetry.Internal; + +namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; + +internal sealed class ExperimentalFeatures +{ + public const string EMITLOGEXCEPTIONATTRIBUTES = "OTEL_DOTNET_EMIT_EXCEPTION_LOG_ATTRIBUTES"; + + public ExperimentalFeatures() + : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) + { + } + + public ExperimentalFeatures(IConfiguration configuration) + { + if (configuration.TryGetBoolValue(EMITLOGEXCEPTIONATTRIBUTES, out var emitLogExceptionAttributes)) + { + this.EmitLogExceptionAttributes = emitLogExceptionAttributes; + } + } + + /// + /// Gets or sets a value indicating whether log exception attributes should be exported. + /// + public bool EmitLogExceptionAttributes { get; set; } = false; +} diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index 3fba6ff8cb8..8f510086758 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -16,7 +16,9 @@ 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; @@ -30,7 +32,8 @@ internal static void AddBatch( this OtlpCollector.ExportLogsServiceRequest request, SdkLimitOptions sdkLimitOptions, OtlpResource.Resource processResource, - in Batch logRecordBatch) + in Batch logRecordBatch, + ExperimentalFeatures experimentalFeatures) { var resourceLogs = new OtlpLogs.ResourceLogs { @@ -43,7 +46,7 @@ internal static void AddBatch( foreach (var logRecord in logRecordBatch) { - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, experimentalFeatures); if (otlpLogRecord != null) { scopeLogs.LogRecords.Add(otlpLogRecord); @@ -52,7 +55,7 @@ internal static void AddBatch( } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitOptions sdkLimitOptions) + internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitOptions sdkLimitOptions, ExperimentalFeatures experimentalFeatures) { OtlpLogs.LogRecord otlpLogRecord = null; @@ -104,14 +107,14 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO { otlpLogRecord.AddStringAttribute(nameof(logRecord.EventId.Name), logRecord.EventId.Name, attributeValueLengthLimit, attributeCountLimit); } + */ - if (logRecord.Exception != null) + if (experimentalFeatures.EmitLogExceptionAttributes && logRecord.Exception != null) { otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name, attributeValueLengthLimit, attributeCountLimit); 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/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs index 3a1b4551f98..784a3f41571 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs @@ -31,6 +31,7 @@ namespace OpenTelemetry.Exporter; internal sealed class OtlpLogExporter : BaseExporter { private readonly SdkLimitOptions sdkLimitOptions; + private readonly ExperimentalFeatures experimentalFeatures; private readonly IExportClient exportClient; private OtlpResource.Resource processResource; @@ -59,6 +60,7 @@ internal OtlpLogExporter( Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); this.sdkLimitOptions = sdkLimitOptions; + this.experimentalFeatures = new(); // Each of the Otlp exporters: Traces, Metrics, and Logs set the same value for `OtlpKeyValueTransformer.LogUnsupportedAttributeType` // and `ConfigurationExtensions.LogInvalidEnvironmentVariable` so it should be fine even if these exporters are used together. @@ -94,7 +96,7 @@ public override ExportResult Export(in Batch logRecordBatch) try { - request.AddBatch(this.sdkLimitOptions, this.ProcessResource, logRecordBatch); + request.AddBatch(this.sdkLimitOptions, this.ProcessResource, logRecordBatch, this.experimentalFeatures); if (!this.exportClient.SendExportRequest(request)) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 7a32a4a34eb..4845a7469a8 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -17,12 +17,14 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Reflection; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; 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; @@ -179,7 +181,7 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.Single(logRecords); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); @@ -223,7 +225,7 @@ public void CheckToOtlpLogRecordLoggerCategory() Assert.Single(logRecords); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Single(otlpLogRecord.Attributes); @@ -237,7 +239,7 @@ public void CheckToOtlpLogRecordLoggerCategory() Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -261,7 +263,7 @@ public void CheckToOtlpLogRecordEventId() Assert.Single(logRecords); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); @@ -278,7 +280,7 @@ public void CheckToOtlpLogRecordEventId() Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); @@ -307,7 +309,7 @@ public void CheckToOtlpLogRecordTimestamps() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log message"); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.True(otlpLogRecord.TimeUnixNano > 0); Assert.True(otlpLogRecord.ObservedTimeUnixNano > 0); @@ -328,7 +330,7 @@ public void CheckToOtlpLogRecordTraceIdSpanIdFlagWithNoActivity() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log when there is no activity."); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Null(Activity.Current); Assert.True(otlpLogRecord.TraceId.IsEmpty); @@ -361,7 +363,7 @@ public void CheckToOtlpLogRecordSpanIdTraceIdAndFlag() } var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Equal(expectedTraceId.ToString(), ActivityTraceId.CreateFromBytes(otlpLogRecord.TraceId.ToByteArray()).ToString()); Assert.Equal(expectedSpanId.ToString(), ActivitySpanId.CreateFromBytes(otlpLogRecord.SpanId.ToByteArray()).ToString()); @@ -393,7 +395,7 @@ public void CheckToOtlpLogRecordSeverityLevelAndText(LogLevel logLevel) Assert.Single(logRecords); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); #pragma warning disable CS0618 // Type or member is obsolete @@ -446,7 +448,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); if (includeFormattedMessage) @@ -465,7 +467,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); @@ -481,7 +483,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); @@ -489,9 +491,10 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Equal("state", otlpLogRecord.Body.StringValue); } - /* - [Fact] - public void CheckToOtlpLogRecordExceptionAttributes() + [Theory] + [InlineData("true")] + [InlineData("false")] + public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttributes) { var logRecords = new List(); using var loggerFactory = LoggerFactory.Create(builder => @@ -507,20 +510,38 @@ public void CheckToOtlpLogRecordExceptionAttributes() var logRecord = logRecords[0]; var loggedException = logRecord.Exception; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary { [ExperimentalFeatures.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) + .Build(); + + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new(configuration)); 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); + if (emitExceptionAttributes == "true") + { + 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.AttributeExceptionStacktrace, otlpLogRecordAttributes); - Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); + Assert.Contains(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); + Assert.Contains(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); + } + else + { + Assert.DoesNotContain(SemanticConventions.AttributeExceptionType, otlpLogRecordAttributes); + Assert.DoesNotContain(logRecord.Exception.GetType().Name, otlpLogRecordAttributes); + + Assert.DoesNotContain(SemanticConventions.AttributeExceptionMessage, otlpLogRecordAttributes); + Assert.DoesNotContain(logRecord.Exception.Message, otlpLogRecordAttributes); + + Assert.DoesNotContain(SemanticConventions.AttributeExceptionStacktrace, otlpLogRecordAttributes); + Assert.DoesNotContain(logRecord.Exception.ToInvariantString(), otlpLogRecordAttributes); + } } - */ [Fact] public void CheckToOtlpLogRecordRespectsAttributeLimits() @@ -545,7 +566,7 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() 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); + var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); @@ -657,7 +678,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsFalse_DoesNotContainScopeAttribu // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); var actualScope = TryGetAttribute(otlpLogRecord, expectedScopeKey); Assert.Null(actualScope); } @@ -692,7 +713,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeStrin // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -731,7 +752,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeBoolV // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -782,7 +803,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeIntVa // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -821,7 +842,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -860,7 +881,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -893,7 +914,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfTypeString // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -928,7 +949,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfPrimitiveT // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -960,7 +981,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfDictionary // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -999,7 +1020,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfEnumerable // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -1039,7 +1060,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopesAreAdded_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1080,7 +1101,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopeLevelsAreAd // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1126,7 +1147,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions); + var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); From f4e1b837314d261ccc3d84a280a680bd98ca43b1 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 26 Sep 2023 15:10:00 -0700 Subject: [PATCH 02/14] nullable --- .../Implementation/ExperimentalFeatures.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs index acb84bc15d6..651889fbfbe 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs @@ -14,6 +14,8 @@ // limitations under the License. // +#nullable enable + using Microsoft.Extensions.Configuration; using OpenTelemetry.Internal; From 001027b13a24a2146c799bab1aa8417376c9a091 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 26 Sep 2023 15:12:29 -0700 Subject: [PATCH 03/14] fix build --- .../Implementation/ExperimentalFeatures.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs index 651889fbfbe..b87be9490fc 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); From aabf44d66dde9afe071949f351895cb27b4cbcc7 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 26 Sep 2023 15:46:05 -0700 Subject: [PATCH 04/14] address feedback --- ...{ExperimentalFeatures.cs => ExperimentalOptions.cs} | 10 +++++----- .../Implementation/LogRecordExtensions.cs | 10 +++++----- .../OtlpLogExporter.cs | 6 +++--- .../OtlpLogExporterTests.cs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/{ExperimentalFeatures.cs => ExperimentalOptions.cs} (84%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs similarity index 84% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index b87be9490fc..df68f1490aa 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalFeatures.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,16 +21,16 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -internal sealed class ExperimentalFeatures +internal sealed class ExperimentalOptions { - public const string EMITLOGEXCEPTIONATTRIBUTES = "OTEL_DOTNET_EMIT_EXCEPTION_LOG_ATTRIBUTES"; + public const string EMITLOGEXCEPTIONATTRIBUTES = "OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES"; - public ExperimentalFeatures() + public ExperimentalOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) { } - public ExperimentalFeatures(IConfiguration configuration) + public ExperimentalOptions(IConfiguration configuration) { if (configuration.TryGetBoolValue(EMITLOGEXCEPTIONATTRIBUTES, out var emitLogExceptionAttributes)) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs index 8f510086758..35d83e9c60f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs @@ -31,9 +31,9 @@ internal static class LogRecordExtensions internal static void AddBatch( this OtlpCollector.ExportLogsServiceRequest request, SdkLimitOptions sdkLimitOptions, + ExperimentalOptions experimentalOptions, OtlpResource.Resource processResource, - in Batch logRecordBatch, - ExperimentalFeatures experimentalFeatures) + in Batch logRecordBatch) { var resourceLogs = new OtlpLogs.ResourceLogs { @@ -46,7 +46,7 @@ internal static void AddBatch( foreach (var logRecord in logRecordBatch) { - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, experimentalFeatures); + var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, experimentalOptions); if (otlpLogRecord != null) { scopeLogs.LogRecords.Add(otlpLogRecord); @@ -55,7 +55,7 @@ internal static void AddBatch( } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitOptions sdkLimitOptions, ExperimentalFeatures experimentalFeatures) + internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions) { OtlpLogs.LogRecord otlpLogRecord = null; @@ -109,7 +109,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO } */ - if (experimentalFeatures.EmitLogExceptionAttributes && logRecord.Exception != null) + if (experimentalOptions.EmitLogExceptionAttributes && logRecord.Exception != null) { otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name, attributeValueLengthLimit, attributeCountLimit); otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit); diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs index 784a3f41571..6a92202c9b7 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs @@ -31,7 +31,7 @@ namespace OpenTelemetry.Exporter; internal sealed class OtlpLogExporter : BaseExporter { private readonly SdkLimitOptions sdkLimitOptions; - private readonly ExperimentalFeatures experimentalFeatures; + private readonly ExperimentalOptions experimentalOptions; private readonly IExportClient exportClient; private OtlpResource.Resource processResource; @@ -60,7 +60,7 @@ internal OtlpLogExporter( Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); this.sdkLimitOptions = sdkLimitOptions; - this.experimentalFeatures = new(); + this.experimentalOptions = new(); // Each of the Otlp exporters: Traces, Metrics, and Logs set the same value for `OtlpKeyValueTransformer.LogUnsupportedAttributeType` // and `ConfigurationExtensions.LogInvalidEnvironmentVariable` so it should be fine even if these exporters are used together. @@ -96,7 +96,7 @@ public override ExportResult Export(in Batch logRecordBatch) try { - request.AddBatch(this.sdkLimitOptions, this.ProcessResource, logRecordBatch, this.experimentalFeatures); + request.AddBatch(this.sdkLimitOptions, this.experimentalOptions, this.ProcessResource, logRecordBatch); if (!this.exportClient.SendExportRequest(request)) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 4845a7469a8..d617494a673 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -511,7 +511,7 @@ public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttribut var logRecord = logRecords[0]; var loggedException = logRecord.Exception; var configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary { [ExperimentalFeatures.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) + .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) .Build(); var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new(configuration)); From 1e2f5524285346a3880f1c8cf910aff3b7192b8f Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 26 Sep 2023 17:40:28 -0700 Subject: [PATCH 05/14] changelog --- .../CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index f0f9461eff6..4e57e84d6ed 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +* Added ability to export attributes corresponding to `LogRecord.Exception` i.e. +`exception.type`, `exception.message` and `exception.stacktrace`. These +attributes will be exported when +`OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` environment variable will be +set to `true`. +([#4892](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4892)) + * Bumped the version of `Google.Protobuf` used by the project to `3.22.5` so that consuming applications can be published as NativeAOT successfully. Also, a new performance feature can be used instead of reflection emit, which is From 982891fc0ec4218352d40c2352ae87958a812160 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 14:56:14 -0700 Subject: [PATCH 06/14] refactor --- ...xtensions.cs => OtlpLogRecordProcessor.cs} | 52 ++++++++----- .../OtlpLogExporter.cs | 7 +- .../OtlpLogExporterTests.cs | 76 +++++++++++++------ 3 files changed, 88 insertions(+), 47 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/{LogRecordExtensions.cs => OtlpLogRecordProcessor.cs} (79%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs similarity index 79% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs index bc0e8ce5dfa..cfbe5803458 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/LogRecordExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,15 +26,23 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -internal static class LogRecordExtensions +internal class OtlpLogRecordProcessor { - internal static void AddBatch( - this OtlpCollector.ExportLogsServiceRequest request, - SdkLimitOptions sdkLimitOptions, - ExperimentalOptions experimentalOptions, + private readonly SdkLimitOptions sdkLimitOptions; + private readonly ExperimentalOptions experimentalOptions; + + public OtlpLogRecordProcessor(SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions) + { + this.sdkLimitOptions = sdkLimitOptions; + this.experimentalOptions = experimentalOptions; + } + + internal OtlpCollector.ExportLogsServiceRequest BuildExportRequest( OtlpResource.Resource processResource, in Batch logRecordBatch) { + var request = new OtlpCollector.ExportLogsServiceRequest(); + var resourceLogs = new OtlpLogs.ResourceLogs { Resource = processResource, @@ -46,16 +54,18 @@ internal static void AddBatch( foreach (var logRecord in logRecordBatch) { - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, experimentalOptions); + var otlpLogRecord = this.ToOtlpLog(logRecord); if (otlpLogRecord != null) { scopeLogs.LogRecords.Add(otlpLogRecord); } } + + return request; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions) + internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord) { OtlpLogs.LogRecord otlpLogRecord = null; @@ -78,8 +88,8 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO otlpLogRecord.SeverityText = logRecord.Severity.Value.ToShortName(); } - var attributeValueLengthLimit = sdkLimitOptions.LogRecordAttributeValueLengthLimit; - var attributeCountLimit = sdkLimitOptions.LogRecordAttributeCountLimit ?? int.MaxValue; + var attributeValueLengthLimit = this.sdkLimitOptions.LogRecordAttributeValueLengthLimit; + var attributeCountLimit = this.sdkLimitOptions.LogRecordAttributeCountLimit ?? int.MaxValue; /* // Removing this temporarily for stable release @@ -109,11 +119,11 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO } */ - if (experimentalOptions.EmitLogExceptionAttributes && logRecord.Exception != null) + if (this.experimentalOptions.EmitLogExceptionAttributes && logRecord.Exception != null) { - otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name, attributeValueLengthLimit, attributeCountLimit); - otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit); - otlpLogRecord.AddStringAttribute(SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString(), attributeValueLengthLimit, attributeCountLimit); + AddStringAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionType, logRecord.Exception.GetType().Name, attributeValueLengthLimit, attributeCountLimit); + AddStringAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionMessage, logRecord.Exception.Message, attributeValueLengthLimit, attributeCountLimit); + AddStringAttribute(otlpLogRecord, SemanticConventions.AttributeExceptionStacktrace, logRecord.Exception.ToInvariantString(), attributeValueLengthLimit, attributeCountLimit); } bool bodyPopulatedFromFormattedMessage = false; @@ -136,7 +146,7 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO } else if (OtlpKeyValueTransformer.Instance.TryTransformTag(attribute, out var result, attributeValueLengthLimit)) { - otlpLogRecord.AddAttribute(result, attributeCountLimit); + AddAttribute(otlpLogRecord, result, attributeCountLimit); } } } @@ -186,7 +196,7 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog) { if (OtlpKeyValueTransformer.Instance.TryTransformTag(scopeItem, out var result, attributeValueLengthLimit)) { - otlpLog.AddAttribute(result, attributeCountLimit); + AddAttribute(otlpLog, result, attributeCountLimit); } } } @@ -201,7 +211,7 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void AddAttribute(this OtlpLogs.LogRecord logRecord, OtlpCommon.KeyValue attribute, int maxAttributeCount) + private static void AddAttribute(OtlpLogs.LogRecord logRecord, OtlpCommon.KeyValue attribute, int maxAttributeCount) { if (logRecord.Attributes.Count < maxAttributeCount) { @@ -214,22 +224,22 @@ private static void AddAttribute(this OtlpLogs.LogRecord logRecord, OtlpCommon.K } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void AddStringAttribute(this OtlpLogs.LogRecord logRecord, string key, string value, int? maxValueLength, int maxAttributeCount) + private static void AddStringAttribute(OtlpLogs.LogRecord logRecord, string key, string value, int? maxValueLength, int maxAttributeCount) { var attributeItem = new KeyValuePair(key, value); if (OtlpKeyValueTransformer.Instance.TryTransformTag(attributeItem, out var result, maxValueLength)) { - logRecord.AddAttribute(result, maxAttributeCount); + AddAttribute(logRecord, result, maxAttributeCount); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void AddIntAttribute(this OtlpLogs.LogRecord logRecord, string key, int value, int maxAttributeCount) + private static void AddIntAttribute(OtlpLogs.LogRecord logRecord, string key, int value, int maxAttributeCount) { var attributeItem = new KeyValuePair(key, value); if (OtlpKeyValueTransformer.Instance.TryTransformTag(attributeItem, out var result)) { - logRecord.AddAttribute(result, maxAttributeCount); + AddAttribute(logRecord, result, maxAttributeCount); } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs index 6a92202c9b7..ce7610d2e90 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs @@ -33,6 +33,7 @@ internal sealed class OtlpLogExporter : BaseExporter private readonly SdkLimitOptions sdkLimitOptions; private readonly ExperimentalOptions experimentalOptions; private readonly IExportClient exportClient; + private readonly OtlpLogRecordProcessor otlpLogRecordProcessor; private OtlpResource.Resource processResource; @@ -82,6 +83,8 @@ internal OtlpLogExporter( { this.exportClient = exporterOptions.GetLogExportClient(); } + + this.otlpLogRecordProcessor = new OtlpLogRecordProcessor(this.sdkLimitOptions, this.experimentalOptions); } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); @@ -92,11 +95,9 @@ public override ExportResult Export(in Batch logRecordBatch) // Prevents the exporter's gRPC and HTTP operations from being instrumented. using var scope = SuppressInstrumentationScope.Begin(); - var request = new OtlpCollector.ExportLogsServiceRequest(); - try { - request.AddBatch(this.sdkLimitOptions, this.experimentalOptions, this.ProcessResource, logRecordBatch); + var request = this.otlpLogRecordProcessor.BuildExportRequest(this.ProcessResource, logRecordBatch); if (!this.exportClient.SendExportRequest(request)) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index d617494a673..244a51fa958 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -180,8 +180,10 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.Single(logRecords); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); @@ -308,8 +310,10 @@ public void CheckToOtlpLogRecordTimestamps() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log message"); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.True(otlpLogRecord.TimeUnixNano > 0); Assert.True(otlpLogRecord.ObservedTimeUnixNano > 0); @@ -329,8 +333,11 @@ public void CheckToOtlpLogRecordTraceIdSpanIdFlagWithNoActivity() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log when there is no activity."); + + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Null(Activity.Current); Assert.True(otlpLogRecord.TraceId.IsEmpty); @@ -362,8 +369,10 @@ public void CheckToOtlpLogRecordSpanIdTraceIdAndFlag() expectedSpanId = activity.SpanId; } + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Equal(expectedTraceId.ToString(), ActivityTraceId.CreateFromBytes(otlpLogRecord.TraceId.ToByteArray()).ToString()); Assert.Equal(expectedSpanId.ToString(), ActivitySpanId.CreateFromBytes(otlpLogRecord.SpanId.ToByteArray()).ToString()); @@ -394,8 +403,10 @@ public void CheckToOtlpLogRecordSeverityLevelAndText(LogLevel logLevel) logger.Log(logLevel, "Hello from {name} {price}.", "tomato", 2.99); Assert.Single(logRecords); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); #pragma warning disable CS0618 // Type or member is obsolete @@ -447,8 +458,10 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) logger.LogInformation("OpenTelemetry {Greeting} {Subject}!", "Hello", "World"); Assert.Single(logRecords); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); if (includeFormattedMessage) @@ -467,7 +480,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); @@ -483,7 +496,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); @@ -514,7 +527,9 @@ public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttribut .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) .Build(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new(configuration)); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new(configuration)); + + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); @@ -565,8 +580,10 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() 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 otlpLogRecordProcessor = new OtlpLogRecordProcessor(sdkLimitOptions, new()); + var logRecord = logRecords[0]; - var otlpLogRecord = logRecord.ToOtlpLog(sdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); @@ -678,7 +695,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsFalse_DoesNotContainScopeAttribu // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var actualScope = TryGetAttribute(otlpLogRecord, expectedScopeKey); Assert.Null(actualScope); } @@ -713,7 +731,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeStrin // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -752,7 +771,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeBoolV // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -803,7 +823,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeIntVa // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -842,7 +863,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -881,7 +903,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -914,7 +937,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfTypeString // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -949,7 +973,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfPrimitiveT // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -981,7 +1006,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfDictionary // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -1020,7 +1046,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfEnumerable // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -1060,7 +1087,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopesAreAdded_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1101,7 +1129,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopeLevelsAreAd // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1147,7 +1176,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); From fc2cfe27f0f15a98b8b2ce76880520bb9b7c46a6 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 15:02:59 -0700 Subject: [PATCH 07/14] update readme --- .../README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 568370008e7..e74b18f983c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -220,6 +220,17 @@ values of the log record limits * `OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT` * `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT` +## Environment Variables for Experimental Features + +### Otlp Log Exporter + +* `OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` + +When set to `true`, it enables export of attributes corresponding to +`LogRecord.Exception`. The attributes are `exception.type`, `exception.message` +and `exception.stacktrace`. + + ## Configure HttpClient The `HttpClientFactory` option is provided on `OtlpExporterOptions` for users From 98530eef2bcd5fc180064f9f1a48a6bc2addac3b Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 15:04:41 -0700 Subject: [PATCH 08/14] fix md --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index e74b18f983c..4b111755c61 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -230,7 +230,6 @@ When set to `true`, it enables export of attributes corresponding to `LogRecord.Exception`. The attributes are `exception.type`, `exception.message` and `exception.stacktrace`. - ## Configure HttpClient The `HttpClientFactory` option is provided on `OtlpExporterOptions` for users From 559fa87e98ffadf2497ac77b22ce5091eb3ef1b3 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 15:42:42 -0700 Subject: [PATCH 09/14] address feedback --- .../Implementation/OtlpLogRecordProcessor.cs | 2 +- .../OtlpLogExporter.cs | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs index cfbe5803458..3816a5da6ec 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs @@ -26,7 +26,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -internal class OtlpLogRecordProcessor +internal sealed class OtlpLogRecordProcessor { private readonly SdkLimitOptions sdkLimitOptions; private readonly ExperimentalOptions experimentalOptions; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs index ce7610d2e90..53497791b38 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs @@ -30,8 +30,6 @@ namespace OpenTelemetry.Exporter; /// internal sealed class OtlpLogExporter : BaseExporter { - private readonly SdkLimitOptions sdkLimitOptions; - private readonly ExperimentalOptions experimentalOptions; private readonly IExportClient exportClient; private readonly OtlpLogRecordProcessor otlpLogRecordProcessor; @@ -60,9 +58,6 @@ internal OtlpLogExporter( Debug.Assert(exporterOptions != null, "exporterOptions was null"); Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null"); - this.sdkLimitOptions = sdkLimitOptions; - this.experimentalOptions = new(); - // Each of the Otlp exporters: Traces, Metrics, and Logs set the same value for `OtlpKeyValueTransformer.LogUnsupportedAttributeType` // and `ConfigurationExtensions.LogInvalidEnvironmentVariable` so it should be fine even if these exporters are used together. OtlpKeyValueTransformer.LogUnsupportedAttributeType = (string tagValueType, string tagKey) => @@ -84,7 +79,7 @@ internal OtlpLogExporter( this.exportClient = exporterOptions.GetLogExportClient(); } - this.otlpLogRecordProcessor = new OtlpLogRecordProcessor(this.sdkLimitOptions, this.experimentalOptions); + this.otlpLogRecordProcessor = new OtlpLogRecordProcessor(sdkLimitOptions, new()); } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); From 21f188baacfe9ae84ec57c3b3d955e1335aeab2a Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 17:34:14 -0700 Subject: [PATCH 10/14] pr feedback --- .../Implementation/ExperimentalOptions.cs | 2 +- ...ocessor.cs => OtlpLogRecordTransformer.cs} | 4 +- .../README.md | 7 ++-- .../OtlpLogExporterTests.cs | 42 +++++++++---------- 4 files changed, 28 insertions(+), 27 deletions(-) rename src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/{OtlpLogRecordProcessor.cs => OtlpLogRecordTransformer.cs} (98%) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs index df68f1490aa..2734ad8a158 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs @@ -23,7 +23,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; internal sealed class ExperimentalOptions { - public const string EMITLOGEXCEPTIONATTRIBUTES = "OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES"; + public const string EMITLOGEXCEPTIONATTRIBUTES = "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES"; public ExperimentalOptions() : this(new ConfigurationBuilder().AddEnvironmentVariables().Build()) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs similarity index 98% rename from src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs rename to src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs index 3816a5da6ec..62b368ffe12 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordProcessor.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs @@ -26,12 +26,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; -internal sealed class OtlpLogRecordProcessor +internal sealed class OtlpLogRecordTransformer { private readonly SdkLimitOptions sdkLimitOptions; private readonly ExperimentalOptions experimentalOptions; - public OtlpLogRecordProcessor(SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions) + public OtlpLogRecordTransformer(SdkLimitOptions sdkLimitOptions, ExperimentalOptions experimentalOptions) { this.sdkLimitOptions = sdkLimitOptions; this.experimentalOptions = experimentalOptions; diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 5cc0af972eb..2f53e327ecc 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -222,11 +222,12 @@ values of the log record limits ### Otlp Log Exporter -* `OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` +* `OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` When set to `true`, it enables export of attributes corresponding to -`LogRecord.Exception`. The attributes are `exception.type`, `exception.message` -and `exception.stacktrace`. +`LogRecord.Exception`. The attributes `exception.type`, `exception.message` and +`exception.stacktrace` are defined in +[specification](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/exceptions/exceptions-logs.md#attributes). ## Configure HttpClient diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 244a51fa958..affd96ef08e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -180,7 +180,7 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -310,7 +310,7 @@ public void CheckToOtlpLogRecordTimestamps() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log message"); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -334,7 +334,7 @@ public void CheckToOtlpLogRecordTraceIdSpanIdFlagWithNoActivity() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log when there is no activity."); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -369,7 +369,7 @@ public void CheckToOtlpLogRecordSpanIdTraceIdAndFlag() expectedSpanId = activity.SpanId; } - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -403,7 +403,7 @@ public void CheckToOtlpLogRecordSeverityLevelAndText(LogLevel logLevel) logger.Log(logLevel, "Hello from {name} {price}.", "tomato", 2.99); Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -458,7 +458,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) logger.LogInformation("OpenTelemetry {Greeting} {Subject}!", "Hello", "World"); Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -527,7 +527,7 @@ public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttribut .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) .Build(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new(configuration)); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new(configuration)); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -580,7 +580,7 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() 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 otlpLogRecordProcessor = new OtlpLogRecordProcessor(sdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(sdkLimitOptions, new()); var logRecord = logRecords[0]; var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); @@ -695,7 +695,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsFalse_DoesNotContainScopeAttribu // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var actualScope = TryGetAttribute(otlpLogRecord, expectedScopeKey); Assert.Null(actualScope); @@ -731,7 +731,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeStrin // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -771,7 +771,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeBoolV // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -823,7 +823,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeIntVa // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -863,7 +863,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -903,7 +903,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -937,7 +937,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfTypeString // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); @@ -973,7 +973,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfPrimitiveT // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); @@ -1006,7 +1006,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfDictionary // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -1046,7 +1046,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfEnumerable // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); @@ -1087,7 +1087,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopesAreAdded_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) @@ -1129,7 +1129,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopeLevelsAreAd // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) @@ -1176,7 +1176,7 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordProcessor(DefaultSdkLimitOptions, new()); + var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) From 2413e1db51b433b581bde83c7a106a168a54836a Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 19:01:45 -0700 Subject: [PATCH 11/14] fix build --- .../OtlpLogExporter.cs | 6 +- .../OtlpLogExporterTests.cs | 88 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs index 53497791b38..715ec0de263 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs @@ -31,7 +31,7 @@ namespace OpenTelemetry.Exporter; internal sealed class OtlpLogExporter : BaseExporter { private readonly IExportClient exportClient; - private readonly OtlpLogRecordProcessor otlpLogRecordProcessor; + private readonly OtlpLogRecordTransformer otlpLogRecordTransformer; private OtlpResource.Resource processResource; @@ -79,7 +79,7 @@ internal OtlpLogExporter( this.exportClient = exporterOptions.GetLogExportClient(); } - this.otlpLogRecordProcessor = new OtlpLogRecordProcessor(sdkLimitOptions, new()); + this.otlpLogRecordTransformer = new OtlpLogRecordTransformer(sdkLimitOptions, new()); } internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource(); @@ -92,7 +92,7 @@ public override ExportResult Export(in Batch logRecordBatch) try { - var request = this.otlpLogRecordProcessor.BuildExportRequest(this.ProcessResource, logRecordBatch); + var request = this.otlpLogRecordTransformer.BuildExportRequest(this.ProcessResource, logRecordBatch); if (!this.exportClient.SendExportRequest(request)) { diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index affd96ef08e..0c2e6c06f9b 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -180,10 +180,10 @@ public void OtlpLogRecordTestWhenStateValuesArePopulated() Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Equal("Hello from tomato 2.99.", otlpLogRecord.Body.StringValue); @@ -310,10 +310,10 @@ public void CheckToOtlpLogRecordTimestamps() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log message"); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.True(otlpLogRecord.TimeUnixNano > 0); Assert.True(otlpLogRecord.ObservedTimeUnixNano > 0); @@ -334,10 +334,10 @@ public void CheckToOtlpLogRecordTraceIdSpanIdFlagWithNoActivity() var logger = loggerFactory.CreateLogger("OtlpLogExporterTests"); logger.LogInformation("Log when there is no activity."); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Null(Activity.Current); Assert.True(otlpLogRecord.TraceId.IsEmpty); @@ -369,10 +369,10 @@ public void CheckToOtlpLogRecordSpanIdTraceIdAndFlag() expectedSpanId = activity.SpanId; } - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Equal(expectedTraceId.ToString(), ActivityTraceId.CreateFromBytes(otlpLogRecord.TraceId.ToByteArray()).ToString()); Assert.Equal(expectedSpanId.ToString(), ActivitySpanId.CreateFromBytes(otlpLogRecord.SpanId.ToByteArray()).ToString()); @@ -403,10 +403,10 @@ public void CheckToOtlpLogRecordSeverityLevelAndText(LogLevel logLevel) logger.Log(logLevel, "Hello from {name} {price}.", "tomato", 2.99); Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); #pragma warning disable CS0618 // Type or member is obsolete @@ -458,10 +458,10 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) logger.LogInformation("OpenTelemetry {Greeting} {Subject}!", "Hello", "World"); Assert.Single(logRecords); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); if (includeFormattedMessage) @@ -480,7 +480,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); @@ -496,7 +496,7 @@ public void CheckToOtlpLogRecordBodyIsPopulated(bool includeFormattedMessage) Assert.Single(logRecords); logRecord = logRecords[0]; - otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); @@ -527,9 +527,9 @@ public void CheckToOtlpLogRecordExceptionAttributes(string emitExceptionAttribut .AddInMemoryCollection(new Dictionary { [ExperimentalOptions.EMITLOGEXCEPTIONATTRIBUTES] = emitExceptionAttributes }) .Build(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new(configuration)); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new(configuration)); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); var otlpLogRecordAttributes = otlpLogRecord.Attributes.ToString(); @@ -580,10 +580,10 @@ public void CheckToOtlpLogRecordRespectsAttributeLimits() 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 otlpLogRecordProcessor = new OtlpLogRecordTransformer(sdkLimitOptions, new()); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(sdkLimitOptions, new()); var logRecord = logRecords[0]; - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Equal(1u, otlpLogRecord.DroppedAttributesCount); @@ -695,8 +695,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsFalse_DoesNotContainScopeAttribu // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); var actualScope = TryGetAttribute(otlpLogRecord, expectedScopeKey); Assert.Null(actualScope); } @@ -731,8 +731,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeStrin // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -771,8 +771,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeBoolV // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -823,8 +823,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeIntVa // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -863,8 +863,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -903,8 +903,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_ContainsScopeAttributeDoubl // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -937,8 +937,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfTypeString // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -973,8 +973,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfPrimitiveT // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.NotNull(otlpLogRecord); Assert.Empty(otlpLogRecord.Attributes); } @@ -1006,8 +1006,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfDictionary // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -1046,8 +1046,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeStateIsOfEnumerable // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); Assert.Single(otlpLogRecord.Attributes); var actualScope = TryGetAttribute(otlpLogRecord, scopeKey); Assert.NotNull(actualScope); @@ -1087,8 +1087,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopesAreAdded_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1129,8 +1129,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndMultipleScopeLevelsAreAd // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); @@ -1176,8 +1176,8 @@ public void ToOtlpLog_WhenOptionsIncludeScopesIsTrue_AndScopeIsUsedInLogMethod_C // Assert. var logRecord = logRecords.Single(); - var otlpLogRecordProcessor = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); - var otlpLogRecord = otlpLogRecordProcessor.ToOtlpLog(logRecord); + var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new()); + var otlpLogRecord = otlpLogRecordTransformer.ToOtlpLog(logRecord); var allScopeValues = otlpLogRecord.Attributes .Where(_ => _.Key == scopeKey1 || _.Key == scopeKey2) .Select(_ => _.Value.StringValue); From d73f493af05be9fa83a485ee3838f43270569f15 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Mon, 2 Oct 2023 23:14:05 -0700 Subject: [PATCH 12/14] file header --- .../Implementation/OtlpLogRecordTransformer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs index 62b368ffe12..3a7be7f04c8 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpLogRecordTransformer.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); From ab4cb52f50fed600435854890cf186aacb02c7b7 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 3 Oct 2023 09:52:28 -0700 Subject: [PATCH 13/14] fix name --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 7bb7db95bf4..07dfc8fd1c8 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -5,8 +5,8 @@ * Added ability to export attributes corresponding to `LogRecord.Exception` i.e. `exception.type`, `exception.message` and `exception.stacktrace`. These attributes will be exported when -`OTEL_DOTNET_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` environment variable will be -set to `true`. +`OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` environment +variable will be set to `true`. ([#4892](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4892)) * Bumped the version of `Google.Protobuf` used by the project to `3.22.5` so From d17aa2363a3e30ad93dd2e89d1389e77a0c4b008 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 3 Oct 2023 09:59:47 -0700 Subject: [PATCH 14/14] fix changelog sequence --- .../CHANGELOG.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 07dfc8fd1c8..90f64dd9c0a 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -2,13 +2,6 @@ ## Unreleased -* Added ability to export attributes corresponding to `LogRecord.Exception` i.e. -`exception.type`, `exception.message` and `exception.stacktrace`. These -attributes will be exported when -`OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` environment -variable will be set to `true`. -([#4892](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4892)) - * Bumped the version of `Google.Protobuf` used by the project to `3.22.5` so that consuming applications can be published as NativeAOT successfully. Also, a new performance feature can be used instead of reflection emit, which is @@ -19,6 +12,13 @@ variable will be set to `true`. and `OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT`. ([#4887](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4887)) +* Added ability to export attributes corresponding to `LogRecord.Exception` i.e. +`exception.type`, `exception.message` and `exception.stacktrace`. These +attributes will be exported when +`OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES` environment +variable will be set to `true`. +([#4892](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4892)) + ## 1.6.0 Released 2023-Sep-05