@@ -40,10 +40,12 @@ event(<TITLE>, <TEXT>, <TIMESTAMP>, <HOSTNAME>, <AGGREGATION_KEY>, <PRIORITY>, <
40
40
41
41
View errors and exceptions in Datadog with a DogStatsD event:
42
42
43
- {{< tabs >}}
44
- {{% tab "Python" %}}
45
43
46
- {{< code-block lang="python" filename="event.py" >}}
44
+ {{< code-lang-tabs langs="python,ruby,go,java,php,csharp">}}
45
+
46
+
47
+ {{< code-wrapper lang="python" filename="event.py" >}}
48
+ ``` python
47
49
from datadog import initialize, statsd
48
50
49
51
options = {
@@ -54,23 +56,22 @@ options = {
54
56
initialize(** options)
55
57
56
58
statsd.event(' An error occurred' , ' Error message' , alert_type = ' error' , tags = [' env:dev' ])
57
- {{< /code-block >}}
59
+ ```
58
60
59
- {{% /tab %}}
60
- {{% tab "Ruby" %}}
61
+ {{< /code-wrapper >}}
61
62
62
- {{< code-block lang="ruby" filename="event.rb" >}}
63
+ {{< code-wrapper lang="ruby" filename="event.rb" >}}
64
+ ``` ruby
63
65
require ' datadog/statsd'
64
66
65
67
statsd = Datadog ::Statsd .new (' localhost' , 8125 )
66
68
67
69
statsd.event(' An error occurred' , " Error message" , alert_type: ' error' , tags: [' env:dev' ])
68
- {{< /code-block >}}
69
-
70
- {{% /tab %}}
71
- {{% tab "Go" %}}
70
+ ```
71
+ {{< /code-wrapper >}}
72
72
73
- {{< code-block lang="go" filename="event.go" >}}
73
+ {{< code-wrapper lang="go" filename="event.go" >}}
74
+ ``` go
74
75
package main
75
76
76
77
import (
@@ -92,12 +93,11 @@ func main() {
92
93
time.Sleep (10 * time.Second )
93
94
}
94
95
}
95
- {{< /code-block >}}
96
-
97
- {{% /tab %}}
98
- {{% tab "Java" %}}
96
+ ```
97
+ {{< /code-wrapper >}}
99
98
100
- {{< code-block lang="java" filename="event.java" >}}
99
+ {{< code-wrapper lang="java" filename="event.java" >}}
100
+ ``` java
101
101
import com.timgroup.statsd.Event ;
102
102
import com.timgroup.statsd.NonBlockingStatsDClientBuilder ;
103
103
import com.timgroup.statsd.StatsDClient ;
@@ -121,12 +121,11 @@ public class DogStatsdClient {
121
121
Statsd . recordEvent(event);
122
122
}
123
123
}
124
- {{< /code-block >}}
125
-
126
- {{% /tab %}}
127
- {{% tab ".NET" %}}
124
+ ```
125
+ {{< /code-wrapper >}}
128
126
129
- {{< code-block lang="csharp" filename="event.cs" >}}
127
+ {{< code-wrapper lang="csharp" filename="event.cs" >}}
128
+ ``` csharp
130
129
using StatsdClient ;
131
130
132
131
public class DogStatsdClient
@@ -146,12 +145,11 @@ public class DogStatsdClient
146
145
}
147
146
}
148
147
}
149
- {{< /code-block >}}
150
-
151
- {{% /tab %}}
152
- {{% tab "PHP" %}}
148
+ ```
149
+ {{< /code-wrapper >}}
153
150
154
- {{< code-block lang="php" filename="event.php" >}}
151
+ {{< code-wrapper lang="php" filename="event.php" >}}
152
+ ``` php
155
153
<?php
156
154
157
155
require __DIR__ . '/vendor/autoload.php';
@@ -169,12 +167,17 @@ $statsd->event('An error occurred.',
169
167
'alert_type' => 'error'
170
168
)
171
169
);
172
- {{< /code-block >}}
170
+ ```
173
171
174
172
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.
175
173
To use this, you must configure the library with your [ Datadog API and application keys] [ 1 ] instead of the local DogStatS instance:
176
174
177
- {{< code-block lang="php" filename="event_through_api.php" >}}
175
+ [ 1 ] : /developers/dogstatsd/
176
+
177
+ {{< /code-wrapper >}}
178
+
179
+ {{< code-wrapper lang="php" filename="event_through_api.php" >}}
180
+ ``` php
178
181
<?php
179
182
180
183
require __DIR__ . '/vendor/autoload.php';
@@ -192,21 +195,21 @@ $statsd->event('An error occurred.',
192
195
'alert_type' => 'error'
193
196
)
194
197
);
195
- {{< /code-block >}}
198
+ ```
199
+ {{< /code-wrapper >}}
200
+
201
+ {{< code-lang-tabs langs="python,ruby,go,java,php,csharp">}}
196
202
197
203
** Note** :
198
204
199
205
* Sending events with this method uses cURL for API requests.
200
206
* You should use a ` try ` /` catch ` code block to avoid warnings or errors on communication issues with the Datadog API.
201
207
202
208
[ 1 ] : https://app.datadoghq.com/account/settings#api
203
- {{% /tab %}}
204
- {{< /tabs >}}
205
209
206
210
## Further reading
207
211
208
212
{{< partial name="whats-next/whats-next.html" >}}
209
213
210
214
211
- [1]: /developers/dogstatsd/
212
215
[ 2 ] : /events/
0 commit comments