View Source OtelMetricExporter.LogHandler (OTel Metric Exporter v0.3.6)

A Logger handler that forwards log events to OTel collector via OTLP protocol.

This can be installed as a handler for the :logger application.

Example:

# Add and configure the handler
config :my_app, :logger, [
  {:handler, OtelMetricExporter.LogHandler, :logger_std_h, %{
    config: %{
      metadata_map: %{
        request_id: "http.request.id"
      }
    },
  }}
]

# Configure the resource and endpoint
config :otel_metric_exporter,
  otlp_protocol: :http_protobuf,
  otlp_endpoint: otlp_endpoint,
  resource: %{
    name: "metrics",
    service: %{name: service_name, version: version},
    instance: %{id: instance_id}
  }

It should then be explicitly attached by executing Logger.add_handlers(:my_app) in Application.start/2 callback of your application.

Options

Options starting with otlp_ and the resource option will be take automatically from the :otel_metric_exporter app configuration, but can be overridden when adding the handler.

  • :metadata (list of atom/0) - A list of atoms from metadata to attach as attribute to the log event The default value is [].

  • :metadata_map (map of atom/0 keys and String.t/0 values) - Remapping of metadata keys to different attribute names. Example: Plug adds a request_id metadata key to log events, but semantic convention for OTel is to use http.request.id. This can be achieved by specifying this field to %{request_id: "http.request.id"} The default value is %{}.

  • :debounce_ms (non_neg_integer/0) - Period to accumulate logs before sending them The default value is 5000.

  • :max_buffer_size (non_neg_integer/0) - Max amount of log events to store before sending them The default value is 10000.

  • :otlp_endpoint (String.t/0) - Required. Endpoint to send data to.

  • :otlp_protocol - Protocol to use for OTLP export. Currently only :http_protobuf is supported. The default value is :http_protobuf.

  • :otlp_headers (map of String.t/0 keys and String.t/0 values) - Headers to send with OTLP requests. The default value is %{}.

  • :otlp_compression - Compression to use for OTLP requests. Allowed values are :gzip and nil. 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 is 10.

  • :resource (map/0) - Resource attributes to send with collected data. The default value is %{}.