Events with DogStatsD

Submission

After installing DogStatsD, you can emit events to your Datadog event explorer with the following function:

event(<title>, <message>, <alert_type>, <aggregation_key>, <source_type_name>, <date_happened>, <priority>, <tags>, <hostname>)

Definitions:

ParameterTypeRequiredDescription
<title>StringYesThe title of the event
<message>StringYesThe text body of the event
<alert_type>StringNoerror, warning, success, or info (defaults to info)
<aggregation_key>StringNoA key to use for aggregating events
<source_type_name>StringNoThe source type name (defaults to my_apps)
<date_happened>IntegerNoThe epoch timestamp for the event (defaults to the current time from the DogStatsD server)
<priority>StringNoSpecifies the priority of the event (normal or low)
<tags>List of stringsNoA list of tags associated with this event
<hostname>StringNoThe name of the host

Examples

Run the following code to view errors and exceptions in Datadog with a DogStatsD event. Remember to flush/close the client when it is no longer needed.

require 'datadog/statsd'

statsd = Datadog::Statsd.new('localhost', 8125)

statsd.event('An error occurred', "Error message", alert_type: 'error', tags: ['env:dev'])

Note:

  • Sending events with this method uses cURL for API requests.
  • You should use a try/catch code block to avoid warnings or errors on communication issues with the Datadog API.

Further reading