No release in over 3 years
Low commit activity in last 3 years
A logging device for sending logs to DataDog in JSON format.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0

Runtime

 Project Readme

Lumberjack DataDog Device

Continuous Integration Regression Test Ruby Style Guide Gem Version

This gem provides a logging device that produces JSON output that matches the standard fields defined for DataDog logging.

  • The time will be sent as "timestamp" with a precision in microseconds.

  • The severity will be sent as "status" with a string label (DEBUG, INFO, WARN, ERROR, FATAL).

  • The progname will be sent as "logger.name"

  • The pid will be sent as "pid".

  • The message will be sent as "message". In addition, if the message is an exception, the error message, class, and backtrace will be sent as "error.message", "error.kind", and "error.trace".

  • If the "error" tag contains an exception, it will be sent as "error.message", "error.kind", and "error.trace".

  • A duration can be sent as a number of seconds in the "duration" tag or as a number of milliseconds in the "duration_ms" tag or as a number of microsectons in the "duration_micros" tag or as a number of nanoseconds in the "duration_ns" tag.

  • All other tags are sent as is. If a tag name includes a dot, it will be sent as a nested JSON structure.

This device extends from Lumberjack::JsonDevice. It is not tied to Data Dog in any way other than that it is opinionated about how to map and format some log tags. It can be used with other services or pipelines without issue.

You can optionally specify a maximum message length with the max_message_length option on the device. Doing so will trucate the message payload to keep it under this number of characters. This option is provided because JSON payloads get messed up and cannot be parsed if they get too big.

Example

You could log an HTTP request to some of the DataDog standard fields like this:

logger.tag("http.method" => request.method, "http.url" => request.url) do
  logger.info("#{request.method} #{request.path} finished in #{elapsed_time} seconds",
    duration: elapsed_time,
    "http.status_code" => response.status
  )
end

Installation

Add this line to your application's Gemfile:

gem 'lumberjack_data_dog_device'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lumberjack_data_dog_device

Contributing

Open a pull request on GitHub.

Please use the standardrb syntax and lint your code with standardrb --fix before submitting.

License

The gem is available as open source under the terms of the MIT License.