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/guide/integrations.asciidoc
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,13 @@
4
4
You can find integration options and information on this page.
5
5
6
6
7
+
[discrete]
8
+
[[opentelemetry]]
9
+
=== OpenTelemetry instrumentation
10
+
11
+
The Python Elasticsearch client supports native OpenTelemetry instrumentation following the https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/[OpenTelemetry Semantic Conventions for Elasticsearch].
12
+
Refer to the <<opentelemetry>> page for details.
13
+
7
14
[discrete]
8
15
[[transport]]
9
16
=== Transport
@@ -53,3 +60,6 @@ es.options(
53
60
------------------------------------
54
61
55
62
Type hints also allow tools like your IDE to check types and provide better auto-complete functionality.
You can use https://opentelemetry.io/[OpenTelemetry] to monitor the performance and behavior of your {es} requests through the Elasticsearch Python Client.
5
+
The Python Client comes with built-in OpenTelemetry instrumentation that emits https://www.elastic.co/guide/en/apm/guide/current/apm-distributed-tracing.html[distributed tracing spans] by default.
6
+
With that, applications https://opentelemetry.io/docs/languages/python/instrumentation/[manually instrumented with OpenTelemetry] or using the https://opentelemetry.io/docs/languages/python/automatic/[OpenTelemetry Python agent] are enriched with additional spans that contain insightful information about the execution of the {es} requests.
7
+
8
+
The native instrumentation in the Python Client follows the https://opentelemetry.io/docs/specs/semconv/database/elasticsearch/[OpenTelemetry Semantic Conventions for {es}]. In particular, the instrumentation in the client covers the logical layer of {es} requests. A single span per request is created that is processed by the service through the Python Client. The following image shows a trace that records the handling of two different {es} requests: an `info` request and a `search` request.
9
+
10
+
[role="screenshot"]
11
+
image::images/otel-waterfall-without-http.png[alt="Distributed trace with Elasticsearch spans",align="center"]
12
+
13
+
Usually, OpenTelemetry auto-instrumentation modules come with instrumentation support for HTTP-level communication. In this case, in addition to the logical {es} client requests, spans will be captured for the physical HTTP requests emitted by the client. The following image shows a trace with both, {es} spans (in blue) and the corresponding HTTP-level spans (in red):
14
+
15
+
[role="screenshot"]
16
+
image::images/otel-waterfall-with-http.png[alt="Distributed trace with Elasticsearch spans",align="center"]
17
+
18
+
Advanced Python Client behavior such as nodes round-robin and request retries are revealed through the combination of logical {es} spans and the physical HTTP spans. The following example shows a `search` request in a scenario with two nodes:
19
+
20
+
[role="screenshot"]
21
+
image::images/otel-waterfall-retry.png[alt="Distributed trace with Elasticsearch spans",align="center"]
22
+
23
+
The first node is unavailable and results in an HTTP error, while the retry to the second node succeeds. Both HTTP requests are subsumed by the logical {es} request span (in blue).
24
+
25
+
[discrete]
26
+
==== Setup the OpenTelemetry instrumentation
27
+
28
+
When using the https://opentelemetry.io/docs/languages/python/instrumentation/[manual Python OpenTelemetry instrumentation] or using the https://opentelemetry.io/docs/languages/python/automatic/[OpenTelemetry Python agent], the Python Client's OpenTelemetry instrumentation is enabled by default and uses the global OpenTelemetry SDK with the global tracer provider.
29
+
30
+
[discrete]
31
+
==== Configuring the OpenTelemetry instrumentation
32
+
33
+
You can configure the OpenTelemetry instrumentation through environment variables.
34
+
The following configuration options are available.
35
+
36
+
[discrete]
37
+
[[opentelemetry-config-enable]]
38
+
===== Enable / Disable the OpenTelemetry instrumentation
39
+
40
+
With this configuration option you can enable (default) or disable the built-in OpenTelemetry instrumentation.
Per default, the built-in OpenTelemetry instrumentation does not capture request bodies due to data privacy considerations. You can use this option to enable capturing of search queries from the request bodies of {es} search requests in case you wish to gather this information regardless. The options are to capture the raw search query or not capture it at all.
The OpenTelemetry instrumentation (as any other monitoring approach) may come with a slight overhead on CPU, memory, and/or latency. The overhead may only occur when the instrumentation is enabled (default) and an OpenTelemetry SDK is active in the target application. When the instrumentation is disabled or no OpenTelemetry SDK is active within the target application, monitoring overhead is not expected when using the client.
65
+
66
+
Even in cases where the instrumentation is enabled and is actively used (by an OpenTelemetry SDK), the overhead is minimal and negligible in the vast majority of cases. In edge cases where there is a noticeable overhead, the <<opentelemetry-config-enable,instrumentation can be explicitly disabled>> to eliminate any potential impact on performance.
0 commit comments