Protobuf in Elixir

Protox is a great library to allow Protobuf to be used in Elixir.
While developing a span catcher for OpenTelemetry I found that I needed to decode a protobuf format message.

Here is the repo if you are interested:

https://github.com/chriseyre2000/span_eater

To construct the protobuf file I looked at the readme of opentelemetry_exporter, which pointed me to the protobuf definitions:

https://github.com/open-telemetry/opentelemetry-proto/tree/v0.11.0

I chose to simplify these into a single file (it’s not that large).

Protobuf is a wire format serializer. This means that if you send a Protobuf message any language that can use protobuf can read the message (provided that both side have the definition).

Given that this proto file has been implemented by a number of OpenTelemetry consumers it can be assumed to be stable.

Working with OpenTelemetry in Elixir

I have created two github projects to demonstrate using OpenTelemetry (admittedly badly).

The first project https://github.com/chriseyre2000/something_to_measure is a simple GenServer that has a method that can be used to generate OpenTelemetry Spans.

The second project https://github.com/chriseyre2000/span_eater is a simple GenServer that consumes spans on the default port that OpenTelemetry sends them on.

In production you would typically have a sidecar application to capture and rebroadcast the messages.

In OpenTelemetry terms a Span is a time interval during which a given process ran. These can be nested. The result is that an Observability tool could capture the spans and construct a visualisation of what was happening. Spans are more useful than raw log data as it has a controlled meaning which would need to be inferred.

span_eater currently just logs that it has received the message. I am planning to make it more sophisticated, and then build a LiveBook to host it in. Currently it is useful to remove the log messages that otherwise get generated:
`

[info]  client error exporting spans {:failed_connect,
 [{:to_address, {'localhost', 4318}}, {:inet, [:inet], :econnrefused}]}

These messages typically flood the logs of a locally run application that is instrumented to publish OpenTelemetry data

I have just worked out how to decode the Protobuf data sent over the wire. We can now listen to OpenTelemetry messages sent by our local machine.