instrument_exporter_otlp (instrument v1.0.0)

View Source

OTLP HTTP exporter for spans.

Exports spans to an OpenTelemetry Collector or compatible backend using the OTLP/HTTP protocol with JSON encoding.

Example Usage

  %% Export to local collector
  instrument_exporter:register(instrument_exporter_otlp:new(#{
      endpoint => "http://localhost:4318"
  })),
 
  %% Export to remote collector with authentication
  instrument_exporter:register(instrument_exporter_otlp:new(#{
      endpoint => "https://otel-collector.example.com:4318",
      headers => #{
          <<"Authorization">> => <<"Bearer token123">>
      },
      compression => gzip
  })),

Configuration Options

  • endpoint - Base URL of the OTLP receiver (required)
  • headers - Additional HTTP headers (default: #{})
  • compression - Compression: none | gzip (default: none)
  • timeout - Request timeout in ms (default: 10000)

Summary

Functions

Exports spans to the OTLP endpoint.

Forces a flush (handled by exporter manager).

Initializes the exporter.

Creates a new OTLP exporter configuration.

Shuts down the exporter.

Functions

export(Spans, State)

-spec export([#span{name :: binary(),
                    ctx ::
                        #span_ctx{trace_id :: <<_:128>> | undefined,
                                  span_id :: <<_:64>> | undefined,
                                  trace_flags :: 0 | 1,
                                  trace_state :: [{binary(), binary()}],
                                  is_remote :: boolean()},
                    parent_ctx ::
                        #span_ctx{trace_id :: <<_:128>> | undefined,
                                  span_id :: <<_:64>> | undefined,
                                  trace_flags :: 0 | 1,
                                  trace_state :: [{binary(), binary()}],
                                  is_remote :: boolean()} |
                        undefined,
                    tracer ::
                        #tracer{name :: binary(),
                                version :: binary() | undefined,
                                schema_url :: binary() | undefined,
                                resource ::
                                    #resource{attributes :: map(), schema_url :: binary() | undefined} |
                                    undefined} |
                        undefined,
                    kind :: client | server | producer | consumer | internal,
                    start_time :: integer(),
                    end_time :: integer() | undefined,
                    attributes :: map(),
                    events ::
                        [#span_event{name :: binary(),
                                     timestamp :: integer(),
                                     attributes :: map(),
                                     dropped_attributes_count :: non_neg_integer()}],
                    links ::
                        [#span_link{ctx ::
                                        #span_ctx{trace_id :: <<_:128>> | undefined,
                                                  span_id :: <<_:64>> | undefined,
                                                  trace_flags :: 0 | 1,
                                                  trace_state :: [{binary(), binary()}],
                                                  is_remote :: boolean()},
                                    attributes :: map(),
                                    dropped_attributes_count :: non_neg_integer()}],
                    status :: unset | ok | {error, binary()},
                    is_recording :: boolean(),
                    dropped_attributes_count :: non_neg_integer(),
                    dropped_events_count :: non_neg_integer(),
                    dropped_links_count :: non_neg_integer()}],
             #state{endpoint :: binary(),
                    traces_path :: binary(),
                    headers :: [{binary(), binary()}],
                    compression :: none | gzip,
                    timeout :: pos_integer()}) ->
                {ok,
                 #state{endpoint :: binary(),
                        traces_path :: binary(),
                        headers :: [{binary(), binary()}],
                        compression :: none | gzip,
                        timeout :: pos_integer()}} |
                {error, retryable,
                 #state{endpoint :: binary(),
                        traces_path :: binary(),
                        headers :: [{binary(), binary()}],
                        compression :: none | gzip,
                        timeout :: pos_integer()}} |
                {error, permanent,
                 #state{endpoint :: binary(),
                        traces_path :: binary(),
                        headers :: [{binary(), binary()}],
                        compression :: none | gzip,
                        timeout :: pos_integer()}} |
                {error,
                 term(),
                 #state{endpoint :: binary(),
                        traces_path :: binary(),
                        headers :: [{binary(), binary()}],
                        compression :: none | gzip,
                        timeout :: pos_integer()}}.

Exports spans to the OTLP endpoint.

force_flush(State)

-spec force_flush(#state{endpoint :: binary(),
                         traces_path :: binary(),
                         headers :: [{binary(), binary()}],
                         compression :: none | gzip,
                         timeout :: pos_integer()}) ->
                     {ok,
                      #state{endpoint :: binary(),
                             traces_path :: binary(),
                             headers :: [{binary(), binary()}],
                             compression :: none | gzip,
                             timeout :: pos_integer()}}.

Forces a flush (handled by exporter manager).

init(Config)

-spec init(map()) ->
              {ok,
               #state{endpoint :: binary(),
                      traces_path :: binary(),
                      headers :: [{binary(), binary()}],
                      compression :: none | gzip,
                      timeout :: pos_integer()}} |
              {error, term()}.

Initializes the exporter.

new(Config)

-spec new(map()) -> #{module := module(), config := map()}.

Creates a new OTLP exporter configuration.

shutdown(State)

-spec shutdown(#state{endpoint :: binary(),
                      traces_path :: binary(),
                      headers :: [{binary(), binary()}],
                      compression :: none | gzip,
                      timeout :: pos_integer()}) ->
                  ok.

Shuts down the exporter.