Tips for effective use of Telemetry in Elixir

Naming

  • Events should all follow a naming scheme, like [:my_lib, :function_call, ...]

Spans

Make Telemetry events suitable for spans, which allow their use in tracing:

  • When starting a function call, execute a [:lib, function, :start] event.
  • When finishing a function call, execute a [:lib, function, :stop] event.
  • If something inside the function call raises or throws an exception, execute a [:lib, :function, :exception] event.

For functions which use result tuples, include the error on events metadata inside an optional :error key.

Metadata

Allow users to add more metadata. This is often useful for users who want to add additional context or business related metrics to each event.

Code structure

See Use a single module for telemetry and include all of your context and docs in that module and Test your events on Telemetry Conventions for code examples.

I haven’t used it yet, but you should probably use the Telemetry Registry library (a project from the EEF Observability WG).

See also