diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 0d14c37089e..dad06df3640 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -9,9 +9,10 @@ please check the latest changes ## Unreleased -* Null values in primitive arrays are preserved through otlp. +* Null values in string arrays are preserved according to [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/common.md). - ([#1919](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1919)) + ([#1919](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1919)) and + ([#1945](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1945)). * When using OpenTelemetry.Extensions.Hosting you can now bind `OtlpExporterOptions` to `IConfiguration` using the `Configure` extension (ex: diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index b549cb72ef1..dca8e21890e 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -465,27 +465,6 @@ public bool ForEach(KeyValuePair activityTag) PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = item })); } - break; - case bool?[] boolArray: - foreach (var item in boolArray) - { - PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, item == null ? null : new OtlpCommon.AnyValue { BoolValue = item.Value })); - } - - break; - case double?[] doubleArray: - foreach (var item in doubleArray) - { - PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, item == null ? null : new OtlpCommon.AnyValue { DoubleValue = item.Value })); - } - - break; - case long?[] longArray: - foreach (var item in longArray) - { - PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, item == null ? null : new OtlpCommon.AnyValue { IntValue = item.Value })); - } - break; default: PooledList.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { StringValue = activityTag.Value.ToString() })); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs index 737af1fa6cd..8567061db4e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs @@ -273,24 +273,16 @@ public void ToOtlpSpanTest() } [Fact] - public void ToOtlpSpanActivitiesWithNullArraysTest() + public void ToOtlpSpanActivitiesWithNullArrayTest() { using var activitySource = new ActivitySource(nameof(this.ToOtlpSpanTest)); using var rootActivity = activitySource.StartActivity("root", ActivityKind.Client); + Assert.NotNull(rootActivity); var stringArr = new string[] { "test", string.Empty, null }; rootActivity.SetTag("stringArray", stringArr); - var boolArr = new bool?[] { true, false, null }; - rootActivity.SetTag("boolArray", boolArr); - - var doubleArr = new double?[] { 1.0, 0.0, null }; - rootActivity.SetTag("doubleArray", doubleArr); - - var longArr = new long?[] { 1, 0, null }; - rootActivity.SetTag("longArray", longArr); - var otlpSpan = rootActivity.ToOtlpSpan(); Assert.NotNull(otlpSpan); @@ -302,30 +294,6 @@ public void ToOtlpSpanActivitiesWithNullArraysTest() Assert.Equal("test", stringArray[0].Value.StringValue); Assert.Equal(string.Empty, stringArray[1].Value.StringValue); Assert.Null(stringArray[2].Value); - - var boolArray = otlpSpan.Attributes.Where(kvp => kvp.Key == "boolArray").ToList(); - - Assert.NotNull(boolArray); - Assert.Equal(3, boolArray.Count()); - Assert.True(boolArray[0].Value.BoolValue); - Assert.False(boolArray[1].Value.BoolValue); - Assert.Null(boolArray[2].Value); - - var doubleArray = otlpSpan.Attributes.Where(kvp => kvp.Key == "doubleArray").ToList(); - - Assert.NotNull(doubleArray); - Assert.Equal(3, doubleArray.Count()); - Assert.Equal(1.0, doubleArray[0].Value.DoubleValue); - Assert.Equal(0.0, doubleArray[1].Value.DoubleValue); - Assert.Null(doubleArray[2].Value); - - var longArray = otlpSpan.Attributes.Where(kvp => kvp.Key == "longArray").ToList(); - - Assert.NotNull(longArray); - Assert.Equal(3, longArray.Count()); - Assert.Equal(1, longArray[0].Value.IntValue); - Assert.Equal(0, longArray[1].Value.IntValue); - Assert.Null(longArray[2].Value); } [Fact]