After installing DogStatsD, you can emit events to your Datadog event stream with the following function:
event(<TITLE>, <TEXT>, <TIMESTAMP>, <HOSTNAME>, <AGGREGATION_KEY>, <PRIORITY>, <SOURCE_TYPE_NAME>, <ALERT_TYPE>, <TAGS>)
Definitions:
Parameter | Type | Required | Description |
---|---|---|---|
<TITLE> | String | Yes | The title of the event |
<TEXT> | String | Yes | The text body of the event |
<TIMESTAMP> | Integer | No | The epoch timestamp for the event (defaults to the current time from the DogStatsD server) |
<HOSTNAME> | String | No | The name of the host |
<AGGREGATION_KEY> | String | No | A key to use for aggregating events |
<PRIORITY> | String | No | Specifies the priority of the event (normal or low ). |
<SOURCE_TYPE_NAME> | String | No | The source type name |
<ALERT_TYPE> | String | No | error , warning , success , or info (defaults to info ) |
<TAGS> | List of strings | No | A list of tags associated with this event. |
View errors and exceptions in Datadog with a DogStatsD event:
from datadog import initialize, statsd
options = {
'statsd_host':'127.0.0.1',
'statsd_port':8125
}
initialize(**options)
statsd.event('An error occurred', 'Error message', alert_type='error', tags=['env:dev'])
require 'datadog/statsd'
statsd = Datadog::Statsd.new('localhost', 8125)
statsd.event('An error occurred', "Error message", alert_type: 'error', tags: ['env:dev'])
package main
import (
"log"
"time"
"github.com/DataDog/datadog-go/statsd"
)
func main() {
dogstatsdClient, err := statsd.New("127.0.0.1:8125")
if err != nil {
log.Fatal(err)
}
for {
dogstatsdClient.SimpleEvent("An error occurred", "Error message")
time.Sleep(10 * time.Second)
}
}
import com.timgroup.statsd.Event;
import com.timgroup.statsd.NonBlockingStatsDClientBuilder;
import com.timgroup.statsd.StatsDClient;
public class DogStatsdClient {
public static void main(String[] args) throws Exception {
StatsDClient Statsd = new NonBlockingStatsDClientBuilder()
.prefix("statsd").
.hostname("localhost")
.port(8125)
.build();
Event event = Event.builder()
.withTitle("An error occurred")
.withText("Error message")
.withAlertType(Event.AlertType.ERROR)
.build();
Statsd.recordEvent(event);
}
}
using StatsdClient;
public class DogStatsdClient
{
public static void Main()
{
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "127.0.0.1",
StatsdPort = 8125,
};
using (var dogStatsdService = new DogStatsdService())
{
dogStatsdService.Configure(dogstatsdConfig);
dogStatsdService.Event("An error occurred", "Error message", alertType: "error", date_happened='TIMESTAMP', tags: new[] { "env:dev" });
}
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use DataDog\DogStatsd;
$statsd = new DogStatsd(
array('host' => '127.0.0.1',
'port' => 8125,
)
);
$statsd->event('An error occurred.',
array( 'text' => 'Error message',
'alert_type' => 'error'
)
);
With the DogStatsD-PHP library you can submit events via TCP directly to the Datadog API. It’s slower but more reliable than using the Agent DogStatsD instance since events are forwarded from your application to the Agent using UDP. To use this, you must configure the library with your Datadog API and application keys instead of the local DogStatS instance:
<?php
require __DIR__ . '/vendor/autoload.php';
use DataDog\DogStatsd;
$statsd = new DogStatsd(
array('api_key' => '<DATADOG_API_KEY>',
'app_key' => '<DATADOG_APPLICATION_KEY>',
)
);
$statsd->event('An error occurred.',
array( 'text' => 'Error message',
'alert_type' => 'error'
)
);
Note:
try
/catch
code block to avoid warnings or errors on communication issues with the Datadog API.Additional helpful documentation, links, and articles: