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 ofatom/0) - A list of atoms from metadata to attach as attribute to the log event The default value is[].:metadata_map(map ofatom/0keys andString.t/0values) - Remapping of metadata keys to different attribute names. Example: Plug adds arequest_idmetadata key to log events, but semantic convention for OTel is to usehttp.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 is1000.:max_buffer_size(non_neg_integer/0) - Max amount of log events to store before sending them The default value is5000.