Skip to content

Commit

Permalink
Rolling back OTLP null array change for non-strings (#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin-Tan committed Mar 31, 2021
1 parent 539a2cd commit 9ebc1ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 57 deletions.
5 changes: 3 additions & 2 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,27 +465,6 @@ public bool ForEach(KeyValuePair<string, object> activityTag)
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = item }));
}

break;
case bool?[] boolArray:
foreach (var item in boolArray)
{
PooledList<OtlpCommon.KeyValue>.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<OtlpCommon.KeyValue>.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<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, item == null ? null : new OtlpCommon.AnyValue { IntValue = item.Value }));
}

break;
default:
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { StringValue = activityTag.Value.ToString() }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]
Expand Down

0 comments on commit 9ebc1ce

Please sign in to comment.