View Source LoggerJSON.Formatters.Datadog (logger_json v6.0.3)

Custom Erlang's :logger formatter which writes logs in a structured format that can be consumed by Datadog.

This formatter adheres to the default standard attribute list as much as possible.

Formatter Configuration

The formatter can be configured with the following options:

  • :hostname (optional) - changes how the syslog.hostname is set in logs. By default, it uses :system which uses :inet.gethostname/0 to resolve the value. If you are running in an environment where the hostname is not correct, you can hard code it by setting hostname to a string. In places where the hostname is inaccurate but also dynamic (like Kubernetes), you can set hostname to :unset to exclude it entirely. You'll then be relying on dd-agent to determine the hostname.

For list of shared options see "Shared options" in LoggerJSON.

Metadata

For list of other well-known metadata keys see "Metadata" in LoggerJSON.

Examples

%{
  "domain" => ["elixir"],
  "logger" => %{
    "file_name" => "/Users/andrew/Projects/os/logger_json/test/formatters/datadog_test.exs",
    "line" => 44,
    "method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest.test logs an LogEntry of a given level/1",
    "thread_name" => "#PID<0.234.0>"
  },
  "message" => "Hello",
  "syslog" => %{
    "hostname" => "MacBook-Pro",
    "severity" => "notice",
    "timestamp" => "2024-04-11T23:03:39.726Z"
  }
}