Class: Loggability::LogDevice::Datadog
- Inherits:
-
Http
- Object
- Loggability::LogDevice
- Http
- Loggability::LogDevice::Datadog
- Defined in:
- lib/loggability/log_device/datadog.rb
Overview
A log device that sends logs to Datadog’s HTTP endpoint for receiving logs
Constant Summary collapse
- DEFAULT_ENDPOINT =
Datadog’s HTTP endpoint URL for sending logs to
URI( "https://http-intake.logs.datadoghq.com/v1/input" )
- MAX_BATCH_SIZE =
The max number of messages that can be sent to datadog in a single payload
480
- 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
204_800
- 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
4_194_304
- DEFAULT_OPTIONS =
Override the default HTTP device options for sending logs to DD
{ max_batch_size: MAX_BATCH_SIZE, max_message_bytesize: MAX_MESSAGE_BYTESIZE, max_batch_bytesize: MAX_BATCH_BYTESIZE, }
Constants inherited from Http
Http::DEFAULT_BATCH_INTERVAL, Http::DEFAULT_EXECUTOR_CLASS, Http::DEFAULT_MAX_BATCH_SIZE, Http::DEFAULT_MAX_MESSAGE_BYTESIZE, Http::DEFAULT_MAX_QUEUE_BYTESIZE, Http::DEFAULT_WRITE_TIMEOUT
Constants inherited from Loggability::LogDevice
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
The configured Datadog API key.
-
#hostname ⇒ Object
readonly
The name of the current host.
Attributes inherited from Http
#batch_interval, #endpoint, #executor, #executor_class, #last_send_time, #logs_queue, #logs_queue_bytesize, #max_batch_bytesize, #max_batch_size, #max_message_bytesize, #max_queue_bytesize, #timer_task, #write_timeout
Instance Method Summary collapse
-
#format_log_message(message) ⇒ Object
Format an individual log
message
for Datadog. -
#initialize(api_key, endpoint = DEFAULT_ENDPOINT, options = {}) ⇒ Datadog
constructor
Create a new Datadog.
-
#make_batch_request ⇒ Object
Overridden to add the configured API key to the headers of each request.
Methods inherited from Http
#batch_ready?, #close, #get_next_log_payload, #http_client, #running?, #send_logs, #start, #start_executor, #start_timer_task, #stop, #write
Methods inherited from Loggability::LogDevice
#close, create, load_device_type, parse_device_spec, #write
Constructor Details
#initialize(api_key, endpoint = DEFAULT_ENDPOINT, options = {}) ⇒ Datadog
Create a new Datadog
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/loggability/log_device/datadog.rb', line 46 def initialize( api_key, endpoint=DEFAULT_ENDPOINT, ={} ) if endpoint.is_a?( Hash ) = endpoint endpoint = DEFAULT_ENDPOINT end super( endpoint, ) @api_key = api_key @hostname = Socket.gethostname end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
The configured Datadog API key
69 70 71 |
# File 'lib/loggability/log_device/datadog.rb', line 69 def api_key @api_key end |
#hostname ⇒ Object (readonly)
The name of the current host
65 66 67 |
# File 'lib/loggability/log_device/datadog.rb', line 65 def hostname @hostname end |
Instance Method Details
#format_log_message(message) ⇒ Object
Format an individual log message
for Datadog.
73 74 75 76 77 78 |
# File 'lib/loggability/log_device/datadog.rb', line 73 def ( ) return { hostname: self.hostname, message: }.to_json end |
#make_batch_request ⇒ Object
Overridden to add the configured API key to the headers of each request.
82 83 84 85 86 87 88 |
# 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 |