TowerOpentelemetry (TowerOpentelemetry v0.2.1)

Copy Markdown View Source

A Tower reporter that records captured exceptions as OpenTelemetry span events, following the OTEL semantic conventions for exceptions.

Usage

Add :tower and :tower_opentelemetry to your dependencies, then configure the reporter:

# config/config.exs
config :tower, reporters: [TowerOpentelemetry]

When Tower captures an unhandled exception, exit, throw or Logger error, this reporter records it as an exception event on the currently active span and marks the span status as :error. If no span is active (for example, a crash in a background process), a short-lived span named "tower.event" is started so the event still reaches the OTEL pipeline.

Recorded attributes

Per the semantic conventions, the following attributes are attached to the span event:

  • exception.type — the fully-qualified exception module name, or Exit/Throw/Message for non-exception kinds.
  • exception.messageException.message/1 for exceptions, otherwise inspect/1 of the reason.
  • exception.stacktraceException.format_stacktrace/1, when a stacktrace is available. Omitted otherwise, per the spec.
  • exception.escaped — always true, since Tower only reports exceptions that escaped their original scope.

In addition, event.id, event.kind and event.level are attached for correlation with Tower's normalized event stream.

Coexisting with other reporters

This reporter is fully compatible with other Tower reporters. For example, to ship exceptions to both Sentry and an OTEL backend at the same time:

config :tower, reporters: [Tower.Sentry, TowerOpentelemetry]