You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/observability.md
+69-18Lines changed: 69 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,6 @@ Correlating events can be hard, especially if your applications have a large cod
15
15
16
16
All of these observability features are documented below.
17
17
18
-
19
18
## OpenTelemetry [_opentelemetry]
20
19
21
20
The client supports OpenTelemetry’s [zero-code instrumentation](https://opentelemetry.io/docs/zero-code/js/) to enable tracking each client request as an [OpenTelemetry span](https://opentelemetry.io/docs/concepts/signals/traces/#spans). These spans follow all of the [semantic OpenTelemetry conventions for Elasticsearch](https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/) except for `db.query.text`.
@@ -36,7 +35,6 @@ To start sending Elasticsearch trace data to your OpenTelemetry endpoint, follow
The client is an event emitter. This means that you can listen for its events to add additional logic to your code, without needing to change the client’s internals or how you use the client. You can find the events' names by accessing the `events` key of the client:
|`serialization`| Emitted before starting serialization and compression. If you want to measure this phase duration, you should measure the time elapsed between this event and `request`.<br><br>```js<br>client.diagnostic.on('serialization', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
73
-
|`request`| Emitted before sending the actual request to {{es}} *(emitted multiple times in case of retries)*.<br><br>```js<br>client.diagnostic.on('request', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
74
-
|`deserialization`| Emitted before starting deserialization and decompression. If you want to measure this phase duration, you should measure the time elapsed between this event and `response`. *(This event might not be emitted in certain situations)*.<br><br>```js<br>client.diagnostic.on('deserialization', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
75
-
|`response`| Emitted once {{es}} response has been received and parsed.<br><br>```js<br>client.diagnostic.on('response', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
76
-
|`sniff`| Emitted when the client ends a sniffing request.<br><br>```js<br>client.diagnostic.on('sniff', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
77
-
|`resurrect`| Emitted if the client is able to resurrect a dead node.<br><br>```js<br>client.diagnostic.on('resurrect', (err, result) => {<br> console.log(err, result)<br>})<br>```<br> |
70
+
#### `serialization`
71
+
72
+
Emitted before starting serialization and compression. If you want to measure this phase duration, you should measure the time elapsed between this event and `request`.
Emitted before starting deserialization and decompression. If you want to measure this phase duration, you should measure the time elapsed between this event and `response`.
93
+
94
+
This event might not be emitted in certain situations:
95
+
96
+
* When `asStream` is set to true, the response is returned in its raw stream form before deserialization occurs
97
+
* When a response is terminated early due to content length being too large
98
+
* When a response is terminated early by an `AbortController`
The values of `result` in `serialization`, `request`, `deserialization`, `response` and `sniff` are:
80
137
@@ -113,7 +170,6 @@ request: {
113
170
};
114
171
```
115
172
116
-
117
173
### Events order [_events_order]
118
174
119
175
The event order is described in the following graph, in some edge cases, the order is not guaranteed. You can find in [`test/acceptance/events-order.test.js`](https://github.com/elastic/elasticsearch-js/blob/main/test/acceptance/events-order.test.js) how the order changes based on the situation.
@@ -134,7 +190,6 @@ serialization
134
190
└─▶ response
135
191
```
136
192
137
-
138
193
## Correlation ID [_correlation_id]
139
194
140
195
Correlating events can be hard, especially if there are many events at the same time. The client offers you an automatic (and configurable) system to help you handle this problem.
@@ -176,7 +231,7 @@ const client = new Client({
176
231
// it takes two parameters, the request parameters and options
177
232
generateRequestId:function (params, options) {
178
233
// your id generation logic
179
-
// must be syncronous
234
+
// must be synchronous
180
235
return'id'
181
236
}
182
237
})
@@ -193,7 +248,6 @@ client.search({
193
248
}).then(console.log, console.log)
194
249
```
195
250
196
-
197
251
## Context object [_context_object]
198
252
199
253
Sometimes, you might need to make some custom data available in your events, you can do that via the `context` option of a request:
@@ -263,10 +317,9 @@ client.search({
263
317
}).then(console.log, console.log)
264
318
```
265
319
266
-
267
320
## Client name [_client_name]
268
321
269
-
If you are using multiple instances of the client or if you are using multiple child clients *(which is the recommended way to have multiple instances of the client)*, you might need to recognize which client you are using. The `name` options help you in this regard.
322
+
If you are using multiple instances of the client or if you are using multiple child clients _(which is the recommended way to have multiple instances of the client)_, you might need to recognize which client you are using. The `name` options help you in this regard.
To improve observability, the client offers an easy way to configure the `X-Opaque-Id` header. If you set the `X-Opaque-Id` in a specific request, this allows you to discover this identifier in the [deprecation logs](docs-content://deploy-manage/monitor/logging-configuration/update-elasticsearch-logging-levels.md#deprecation-logging), helps you with [identifying search slow log origin](elasticsearch://reference/elasticsearch/index-settings/slow-log.md) as well as [identifying running tasks](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-tasks).
0 commit comments