Open telemetry: how to include an array of primitive values in attributes

We’ve just started using OpenTelemetry — OpenTelemetry API v1.0.0-rc.3.2 to integrate our APM with Datadog. According to the Open Telemetry specification

  • The attribute value, which is either:
    • A primitive type: string, boolean, double precision floating point (IEEE 754-1985) or signed 64 bit integer.
    • An array of primitive type values. The array MUST be homogeneous, i.e. it MUST NOT contain values of different types. For protocols that do not natively support array values such values SHOULD be represented as JSON strings. There’s also Span attributes: array of primitives · Issue #111 · open-telemetry/opentelemetry-erlang · GitHub which seems to imply that opentelemetry-erlang supports arrays of primitives in span attributes. However when I try to add span attributes with an array
OpenTelemetry.Span.start_span(span_ctx, [{"key1", ["one", "two"]}])

in the otel collector logs I see that attribute come through as EMPTY. Is it currently possible to use arrays or is there still some work to do?

@tristan I saw you mention that you were scanning for Open Telemetry questions so I hope you don’t mind me tagging you here.

Hey, yea, @'ing me is fine :). Have you checked to make sure it isn’t being dropped on accident by the Erlang/Elixir code? Like by using the stdout trace exporter? If its there then it could be the protobuf conversion (we may even need to update the protobufs used in the exporter). I’ll have to look later, just wanted to throw some stuff out there in case you had time to investigate more before I do later today.

Hey, I took another look. With the following code

OpenTelemetry.Span.set_attribute(span_ctx, "list_test", [1, 2])

the output I see in the otel-collector logs is

otel-collector_1 | -> list_test: EMPTY(<Unknown OpenTelemetry attribute value type "EMPTY">)

I’ve got the following versions in mix.exs

{:opentelemetry, "~> 1.0.0-rc.3"},
{:opentelemetry_api, "~> 1.0.0-rc.3.2"},
{:opentelemetry_exporter, "~> 1.0.0-rc.3"},

Should also note that we’re using http for the exporter protocol.

Hm, I think I see a bug in the encoding of arrays that could possibly be the cause – I think the proto, or at least the latest proto, requires the Erlang term before encoding to be {array_value, [{value, {int_value, 1}}, ...]} but we are passing {array_value, [{value, 1}, ...]}. Will need to setup a test to make sure the change works.

That sounds promising, many thanks for taking a look.

I did a quick test against the collector exporting to zipkin and this patch seems to work exporter: update trace protos to v0.11.0 by tsloughter · Pull Request #314 · open-telemetry/opentelemetry-erlang · GitHub

Many thanks for taking a look! I did try and run my project with your patched version but I’m not entirely sure how to reference it. I used

{:opentelemetry, git: "", ref: "trace-protos-0.11.0", override: true},

but I got this error

* opentelemetry (
  could not find an app file at "_build/dev/lib/opentelemetry/ebin/". Another app file was found in the same directory "_build/dev/lib/opentelemetry/ebin/", try changing the dependency name to :otel_elixir_tests

If you know how get your branch running against an app let me know and I’ll give it a test.

Since it is in a subdirectory you need to include the sparse option:

{:opentelemetry_exporter, github: “open-telemetry/opentelemetry-erlang”, sparse: “apps/opentelemetry_exporter”, override: true},