Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTLP exporter flattens array attribute to multiple key value pairs with the same key name #2547

Closed
ThomsonTan opened this issue Oct 29, 2021 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Good for taking. Extra help will be provided by maintainers pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package

Comments

@ThomsonTan
Copy link
Contributor

ThomsonTan commented Oct 29, 2021

Bug Report

The current OTLP exporter below flattens nested array in Span.Atttributes (Activity.Tags in .NET) into a list of key value pairs with the same key for all these kv pairs. For example, activity.SetTag('arraykey', new int [] {1, 2, 3} is converted to JSON like list {{'arraykey': 1}, {'arraykey': 2}, {'arraykey': 3}} in OTLP. This could cause problem if the OTLP listener would like to process Span.Attributes as dictionary, or store them into table like data structure, because it requires inventing some new rules to handle the duplicated key names.

case int[] intArray:
foreach (var item in intArray)
{
PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, new OtlpCommon.AnyValue { IntValue = item }));
}

Instead of flatting the array into the top level of Span.Attributes, I tried below change which keeps the type of array in the Span.Attributes field, when then will be serialized to ArrayValue in OTLP and no longer producing duplicated keys. Please let me know if this will work and I'll make PR to fix all the nested arrays in Span.Attributes.

                    case int[] intArray:
                        var anyValue = new OtlpCommon.AnyValue { ArrayValue = new OtlpCommon.ArrayValue { } };
                        anyValue.ArrayValue.Values.Add(intArray.Select(item => new OtlpCommon.AnyValue { IntValue = item }));
                        PooledList<OtlpCommon.KeyValue>.Add(ref this.Tags, CreateOtlpKeyValue(key, anyValue));

                        break;
@ThomsonTan ThomsonTan added the bug Something isn't working label Oct 29, 2021
@reyang reyang added pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package good first issue Good for newcomers help wanted Good for taking. Extra help will be provided by maintainers labels Nov 7, 2021
@alanwest
Copy link
Member

Fixed in #3262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Good for taking. Extra help will be provided by maintainers pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
Development

No branches or pull requests

3 participants