Legion. OpenTelemetry. Adapter behaviour
(Legion v0.7.0)
View Source
Behaviour Legion.OpenTelemetry uses to shape, trace and export spans.
Most adapters implement only span_attributes/1, and
Legion.OpenTelemetry.Adapter.OTel traces their spans. A vendor adapter
adds exporter_config/1, which Legion.OpenTelemetry.Exporter sends spans
with. An adapter that implements start_span/3 is its own tracer and
implements the other tracer callbacks too, which mirror
ReqLLM.OpenTelemetry.Adapter; start_span/3 must not make the span
current. Every tracer callback gets the attach options plus :span_kind
(:internal, :client for chat, :server for MCP calls). Only
OpenTelemetry span contexts become current, so nothing nests under a span
handle of another shape.
Example - tag every span with the deployment environment
defmodule MyApp.OTelAdapter do
@behaviour Legion.OpenTelemetry.Adapter
@impl true
def span_attributes(attrs),
do: Map.put(attrs, :"deployment.environment.name", "production")
end
Legion.OpenTelemetry.attach(adapter: MyApp.OTelAdapter)
Summary
Callbacks
The opentelemetry_exporter options (:exporter) and resource attributes
(:resource) to export to the vendor with, built from its settings.
Raises on invalid settings.
The attributes a span starts with, rewritten. Keys are atoms.
Callbacks
@callback available?() :: boolean()
The opentelemetry_exporter options (:exporter) and resource attributes
(:resource) to export to the vendor with, built from its settings.
Raises on invalid settings.
The attributes a span starts with, rewritten. Keys are atoms.