Skip to content

Commit 94bf5b2

Browse files
Documentation for OpenTelemetry support (#2289)
* Documentation for OpenTelemetry support * Update docs/observability.asciidoc Co-authored-by: Miguel Grinberg <[email protected]> * Fix docs typo * Fix bad link references in asciidoc changelog * Drop link to 8.15 changelog For now. Link just doesn't work yet. --------- Co-authored-by: Miguel Grinberg <[email protected]>
1 parent f34bb6a commit 94bf5b2

File tree

2 files changed

+81
-45
lines changed

2 files changed

+81
-45
lines changed

docs/changelog.asciidoc

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
[[changelog-client]]
22
== Release notes
33

4+
[discrete]
5+
=== 8.15.0
6+
7+
[discrete]
8+
==== Features
9+
10+
[discrete]
11+
===== OpenTelemetry zero-code instrumentation support
12+
13+
For those that use an observability service that supports OpenTelemetry spans, the client will now automatically generate traces for each Elasticsearch request it makes.
14+
See {jsclient}/observability.html#_opentelemetry[the docs]
15+
for more information.
16+
417
[discrete]
518
=== 8.14.0
619

@@ -198,7 +211,7 @@ https://www.elastic.co/guide/en/elasticsearch/reference/8.9/release-notes-8.9.0.
198211
[discrete]
199212
===== Allow document to be overwritten in `onDocument` iteratee of bulk helper https://github.com/elastic/elasticsearch-js/pull/1732[#1732]
200213

201-
In the https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html#bulk-helper[bulk helper], documents could not be modified before being sent to Elasticsearch. It is now possible to https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html#_modifying_a_document_before_operation[modify a document] before sending it.
214+
In the {jsclient}/client-helpers.html#bulk-helper[bulk helper], documents could not be modified before being sent to Elasticsearch. It is now possible to {jsclient}/client-helpers.html#_modifying_a_document_before_operation[modify a document] before sending it.
202215

203216
[discrete]
204217
==== Fixes

docs/observability.asciidoc

+67-44
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,61 @@
11
[[observability]]
22
=== Observability
33

4-
The client does not provide a default logger, but instead it offers an event
5-
emitter interface to hook into internal events, such as `request` and
6-
`response`.
4+
To observe and measure Elasticsearch client usage, several client features are provided.
75

8-
Correlating those events can be hard, especially if your applications have a
9-
large codebase with many events happening at the same time.
6+
First, as of 8.15.0, the client provides native support for OpenTelemetry, which allows you to send client usage data to any endpoint that supports OpenTelemetry without having to make any changes to your JavaScript codebase.
107

11-
To help you with this, the client offers you a correlation id system and other
12-
features. Let's see them in action.
8+
Also, rather than providing a default logger, the client offers an event
9+
emitter interface to hook into internal events, such as `request` and
10+
`response`, allowing you to log the events you care about, or otherwise react
11+
to client usage however you might need.
1312

13+
Correlating events can be hard, especially if your applications have a large codebase with many events happening at the same time. To help you with this, the client provides a correlation ID system, and other
14+
features.
15+
16+
All of these observability features are documented below.
17+
18+
[discrete]
19+
==== OpenTelemetry
20+
21+
The client supports OpenTelemetry's https://opentelemetry.io/docs/zero-code/js/[zero-code
22+
instrumentation] to enable tracking each client request as an
23+
https://opentelemetry.io/docs/concepts/signals/traces/#spans[OpenTelemetry span]. These spans
24+
follow all of the https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/[semantic
25+
OpenTelemetry conventions for Elasticsearch] except for `db.query.text`.
26+
27+
To start sending Elasticsearch trace data to your OpenTelemetry endpoint, follow
28+
https://opentelemetry.io/docs/zero-code/js/[OpenTelemetry's zero-code instrumentation guide],
29+
or the following steps:
30+
31+
1. Install `@opentelemetry/api` and `@opentelemetry/auto-instrumentations-node` as Node.js dependencies
32+
2. Export the following environment variables with the appropriate values:
33+
- `OTEL_EXPORTER_OTLP_ENDPOINT`
34+
- `OTEL_EXPORTER_OTLP_HEADERS`
35+
- `OTEL_RESOURCE_ATTRIBUTES`
36+
- `OTEL_SERVICE_NAME`
37+
3. `require` the Node.js auto-instrumentation library at startup:
38+
[source,bash]
39+
----
40+
node --require '@opentelemetry/auto-instrumentations-node/register' index.js
41+
----
1442

1543
[discrete]
1644
==== Events
1745

18-
The client is an event emitter, this means that you can listen for its event and
19-
add additional logic to your code, without need to change the client internals
20-
or your normal usage. You can find the events names by access the `events` key
21-
of the client.
46+
The client is an event emitter. This means that you can listen for its events to
47+
add additional logic to your code, without needing to change the client's internals
48+
or how you use the client. You can find the events' names by accessing the `events` key
49+
of the client:
2250

2351
[source,js]
2452
----
2553
const { events } = require('@elastic/elasticsearch')
2654
console.log(events)
2755
----
2856

29-
30-
The event emitter functionality can be useful if you want to log every request,
31-
response and error that is happening during the use of the client.
57+
The event emitter functionality can be useful if you want to log every request,
58+
response or error that is created by the client:
3259

3360
[source,js]
3461
----
@@ -48,7 +75,6 @@ client.diagnostic.on('response', (err, result) => {
4875
})
4976
----
5077

51-
5278
The client emits the following events:
5379
[cols=2*]
5480
|===
@@ -108,7 +134,7 @@ client.diagnostic.on('resurrect', (err, result) => {
108134

109135
|===
110136

111-
The values of `result` in `serialization`, `request`, `deserialization`,
137+
The values of `result` in `serialization`, `request`, `deserialization`,
112138
`response` and `sniff` are:
113139

114140
[source,ts]
@@ -135,7 +161,6 @@ meta: {
135161
};
136162
----
137163

138-
139164
While the `result` value in `resurrect` is:
140165

141166
[source,ts]
@@ -152,10 +177,10 @@ request: {
152177
[discrete]
153178
===== Events order
154179

155-
The event order is described in the following graph, in some edge cases, the
180+
The event order is described in the following graph, in some edge cases, the
156181
order is not guaranteed.
157-
You can find in
158-
https://github.com/elastic/elasticsearch-js/blob/main/test/acceptance/events-order.test.js[`test/acceptance/events-order.test.js`]
182+
You can find in
183+
https://github.com/elastic/elasticsearch-js/blob/main/test/acceptance/events-order.test.js[`test/acceptance/events-order.test.js`]
159184
how the order changes based on the situation.
160185

161186
[source]
@@ -175,12 +200,11 @@ serialization
175200
└─▶ response
176201
----
177202

178-
179203
[discrete]
180-
==== Correlation id
204+
==== Correlation ID
181205

182-
Correlating events can be hard, especially if there are many events at the same
183-
time. The client offers you an automatic (and configurable) system to help you
206+
Correlating events can be hard, especially if there are many events at the same
207+
time. The client offers you an automatic (and configurable) system to help you
184208
handle this problem.
185209

186210
[source,js]
@@ -211,8 +235,7 @@ client.search({
211235
}).then(console.log, console.log)
212236
----
213237

214-
215-
By default the id is an incremental integer, but you can configure it with the
238+
By default the ID is an incremental integer, but you can configure it with the
216239
`generateRequestId` option:
217240

218241
[source,js]
@@ -231,7 +254,7 @@ const client = new Client({
231254
----
232255

233256

234-
You can also specify a custom id per request:
257+
You can also specify a custom ID per request:
235258

236259
[source,js]
237260
----
@@ -247,8 +270,8 @@ client.search({
247270
[discrete]
248271
==== Context object
249272

250-
Sometimes, you might need to make some custom data available in your events, you
251-
can do that via the `context` option of a request:
273+
Sometimes, you might need to make some custom data available in your events, you
274+
can do that via the `context` option of a request:
252275

253276
[source,js]
254277
----
@@ -283,7 +306,7 @@ client.search({
283306
----
284307

285308
The context object can also be configured as a global option in the client
286-
configuration. If you provide both, the two context objects will be shallow
309+
configuration. If you provide both, the two context objects will be shallow
287310
merged, and the API level object will take precedence.
288311

289312
[source,js]
@@ -323,9 +346,9 @@ client.search({
323346
[discrete]
324347
==== Client name
325348

326-
If you are using multiple instances of the client or if you are using multiple
327-
child clients _(which is the recommended way to have multiple instances of the
328-
client)_, you might need to recognize which client you are using. The `name`
349+
If you are using multiple instances of the client or if you are using multiple
350+
child clients _(which is the recommended way to have multiple instances of the
351+
client)_, you might need to recognize which client you are using. The `name`
329352
options help you in this regard.
330353

331354
[source,js]
@@ -374,15 +397,15 @@ child.search({
374397
[discrete]
375398
==== X-Opaque-Id support
376399

377-
To improve observability, the client offers an easy way to configure the
378-
`X-Opaque-Id` header. If you set the `X-Opaque-Id` in a specific request, this
379-
allows you to discover this identifier in the
380-
https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html#deprecation-logging[deprecation logs],
381-
helps you with https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html#_identifying_search_slow_log_origin[identifying search slow log origin]
400+
To improve observability, the client offers an easy way to configure the
401+
`X-Opaque-Id` header. If you set the `X-Opaque-Id` in a specific request, this
402+
allows you to discover this identifier in the
403+
https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html#deprecation-logging[deprecation logs],
404+
helps you with https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html#_identifying_search_slow_log_origin[identifying search slow log origin]
382405
as well as https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html#_identifying_running_tasks[identifying running tasks].
383406

384-
The `X-Opaque-Id` should be configured in each request, for doing that you can
385-
use the `opaqueId` option, as you can see in the following example. The
407+
The `X-Opaque-Id` should be configured in each request, for doing that you can
408+
use the `opaqueId` option, as you can see in the following example. The
386409
resulting header will be `{ 'X-Opaque-Id': 'my-search' }`.
387410

388411
[source,js]
@@ -401,10 +424,10 @@ client.search({
401424
}).then(console.log, console.log)
402425
----
403426

404-
Sometimes it may be useful to prefix all the `X-Opaque-Id` headers with a
405-
specific string, in case you need to identify a specific client or server. For
406-
doing this, the client offers a top-level configuration option:
407-
`opaqueIdPrefix`. In the following example, the resulting header will be
427+
Sometimes it may be useful to prefix all the `X-Opaque-Id` headers with a
428+
specific string, in case you need to identify a specific client or server. For
429+
doing this, the client offers a top-level configuration option:
430+
`opaqueIdPrefix`. In the following example, the resulting header will be
408431
`{ 'X-Opaque-Id': 'proxy-client::my-search' }`.
409432

410433
[source,js]

0 commit comments

Comments
 (0)