OtlpShipper.Encoder (otlp_shipper v0.1.1)

Copy Markdown View Source

Constructs OTLP export envelopes using generated protobuf encoders.

Summary

Functions

Encodes log records or metric messages under a single resource and scope.

Functions

encode(signal, items, resource)

@spec encode(:logs | :metrics, [map()], map()) ::
  {:ok, binary()} | {:error, :invalid_payload | :invalid_signal}

Encodes log records or metric messages under a single resource and scope.

Inputs are OTLP message maps, not raw Logger events or metric definitions. Malformed protobuf values return a tagged error without exposing the payload.

iex> {:ok, resource} = OtlpShipper.Resource.new(service_name: "checkout")
iex> record = %{body: OtlpShipper.Value.encode("ready")}
iex> {:ok, bytes} = OtlpShipper.Encoder.encode(:logs, [record], resource)
iex> is_binary(bytes)
true