Loggability::LogDevice::

Datadog class

A log device that sends logs to Datadog’s HTTP endpoint for receiving logs

Constants

DEFAULT_ENDPOINT

Datadog’s HTTP endpoint URL for sending logs to

DEFAULT_OPTIONS

Override the default HTTP device options for sending logs to DD

MAX_BATCH_BYTESIZE

The max size in bytes of all messages in the batch. Limiting the total messages size to 4MB to leave room for other info such as tags, metadata, etc. Datadog’s max size for the entire payload is 5MB

MAX_BATCH_SIZE

The max number of messages that can be sent to datadog in a single payload

MAX_MESSAGE_BYTESIZE

The max size in bytes for a single message. Limiting the message size to 200kB to leave room for other info such as tags, metadata, etc. DataDog’s max size for a single log entry is 256kB

Attributes

api_key R

The configured Datadog API key

hostname R

The name of the current host

Public Class Methods

new( api_key, endpoint=DEFAULT_ENDPOINT, options={} )

Create a new Datadog

# File lib/loggability/log_device/datadog.rb, line 46
def initialize( api_key, endpoint=DEFAULT_ENDPOINT, options={} )
        if endpoint.is_a?( Hash )
                options = endpoint
                endpoint = DEFAULT_ENDPOINT
        end

        super( endpoint, options )

        @api_key = api_key
        @hostname = Socket.gethostname
end

Public Instance Methods

format_log_message( message )

Format an individual log message for Datadog.

# File lib/loggability/log_device/datadog.rb, line 73
def format_log_message( message )
        return {
                hostname: self.hostname,
                message: message
        }.to_json
end
make_batch_request()

Overridden to add the configured API key to the headers of each request.

# File lib/loggability/log_device/datadog.rb, line 82
def make_batch_request
        request = super

        request[ 'DD-API-KEY' ] = self.api_key

        return request
end