Otel.Trace.SpanExporter (otel v0.4.1)

Copy Markdown View Source

Trace export pipeline — timer-driven take from SpanStorage + OTLP encode + HTTP POST. Single GenServer absorbing what was previously split between SpanProcessor (queue + timer + drain) and a HTTP-only Exporter.

Lifecycle

TriggerAction
:loop self-message every @scheduled_delay_mstake one batch (@max_export_batch_size) of :completed spans, encode, POST
force_flush/1drain all completed spans synchronously
terminate/2drain remaining spans before exit

OTLP HTTP transport

POSTs OTLP/protobuf via Req. User config is read from Application.get_env(:otel, :req_options, []) on every export and forwarded to Req.post/1 — anything Req accepts (TLS, auth, timeouts, retry overrides, mock plugs) works.

The SDK only forces :body (the encoded protobuf). Defaults via Keyword.put_new:

  • :base_urlhttp://localhost:4318 if absent
  • :url/v1/traces if absent
  • :retry → predicate matching the OTLP-spec retryable response codes (opentelemetry-proto/docs/specification.md L564-575: 429 / 502 / 503 / 504 SHOULD be retried, all other 4xx / 5xx MUST NOT) plus network-level exceptions. Backoff strategy (exponential + jitter) and Retry-After honoring come from Req's default :retry_delay, which satisfies the spec MUST in opentelemetry-specification/specification/protocol/exporter.md L182-202.
  • content-type: application/x-protobuf and user-agent headers merged into the user's :headers

:max_retries is left to Req's default (3 retries = 4 attempts) — the OTLP spec mandates the strategy but not a specific attempt count.

References

  • OTel Trace SDK §Batching processor: opentelemetry-specification/specification/trace/sdk.md L1086-L1118
  • OTel Trace SDK §SpanExporter: opentelemetry-specification/specification/trace/sdk.md L1119-L1207
  • OTLP retryable response codes: opentelemetry-proto/docs/specification.md L565-L573

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

force_flush(timeout \\ 30000)

@spec force_flush(timeout :: timeout()) :: :ok

start_link(opts \\ [])

@spec start_link(opts :: keyword()) :: GenServer.on_start()