This is a telemetry exporter that collects specified metrics
and then exports them to an OTel endpoint. It uses metric definitions
from :telemetry_metrics library.
Example usage:
OtelMetricExporter.start_link(
otlp_protocol: :http_protobuf,
otlp_endpoint: otlp_endpoint,
otlp_headers: headers,
otlp_compression: :gzip,
export_period: :timer.seconds(30),
metrics: [
Telemetry.Metrics.counter("plug.request.stop.duration"),
Telemetry.Metrics.sum("plug.request.stop.duration"),
Telemetry.Metrics.last_value("plug.request.stop.duration"),
Telemetry.Metrics.distribution("plug.request.stop.duration",
reporter_options: [buckets: [0, 10, 100, 1000]] # Optional histogram buckets.
),
]
)Default histogram buckets are [0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000]
See all available options in start_link/2 documentation. Options provided to the start_link/2
function will be merged with the options provided via config :otel_metric_exporter configuraiton.
Summary
Functions
Returns a specification to start this module under a supervisor.
Start the exporter. It maintains some pieces of global state: ets table and a :persistent_term key.
This means that only one exporter instance can be started at a time.
Types
@type compression() :: :gzip | nil
@type option() :: {:metrics, [Telemetry.Metrics.t()]} | {:export_period, pos_integer()} | {:name, atom()} | {:otlp_endpoint, binary()} | {:otlp_protocol, protocol()} | {:otlp_headers, %{optional(binary()) => binary()}} | {:otlp_timeout, pos_integer()} | {:logs, map() | keyword()} | {:otlp_compression, compression()} | {:otlp_concurrent_requests, non_neg_integer()} | {:resource, %{optional(atom() | binary()) => term()}}
@type protocol() :: :http_protobuf | :http_json
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link([option()]) :: Supervisor.on_start()
Start the exporter. It maintains some pieces of global state: ets table and a :persistent_term key.
This means that only one exporter instance can be started at a time.
Options
Options can be provided directly or specified in the config :otel_metric_exporter configuration. It's recommended
to configure global options in :otel_metric_exporter config, and specify metrics where you add this module to the
supervision tree.
:metrics- Required. List of telemetry metrics to track.:export_period(pos_integer/0) - Period in milliseconds between metric exports. The default value is60000.:name(atom/0) - If you require multiple exporters, give each exporter a unique name. The default value is:otel_metric_exporter.:otlp_endpoint(String.t/0) - Endpoint to send data to.:otlp_protocol- Protocol to use for OTLP export. Currently only:http_protobufis supported. The default value is:http_protobuf.:otlp_headers(map ofString.t/0keys andString.t/0values) - Headers to send with OTLP requests. The default value is%{}.:otlp_timeout(pos_integer/0) - Timeout for OTLP requests. The default value is10000.:logs- Overrides for logs.:otlp_endpoint(String.t/0) - Endpoint to send data to.:otlp_protocol- Protocol to use for OTLP export. Currently only:http_protobufis supported.:otlp_headers(map ofString.t/0keys andString.t/0values) - Headers to send with OTLP requests.:otlp_timeout(pos_integer/0) - Timeout for OTLP requests.:exporter- The default value is:otlp.
:otlp_compression- Compression to use for OTLP requests. Allowed values are:gzipandnil. The default value is:gzip.:otlp_concurrent_requests(non_neg_integer/0) - Number of concurrent requests to send to the OTLP endpoint. The default value is10.:resource- Resource attributes to send with collected data. The default value is%{}.