File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ def test(session):
52
52
session .run (* pytest_argv ())
53
53
54
54
55
- @nox .session (python = ["3.7" , "3.12" ])
55
+ @nox .session (python = ["3.7" , "3.8" , "3. 12" ])
56
56
def test_otel (session ):
57
57
session .install (
58
58
".[dev]" ,
Original file line number Diff line number Diff line change 16
16
# under the License.
17
17
18
18
import os
19
-
19
+ from unittest import mock
20
+ from elasticsearch import Elasticsearch
21
+ from elasticsearch import helpers
20
22
import pytest
21
23
22
24
try :
@@ -95,3 +97,22 @@ def test_detailed_span():
95
97
"db.elasticsearch.cluster.name" : "e9106fc68e3044f0b1475b04bf4ffd5f" ,
96
98
"db.elasticsearch.node.name" : "instance-0000000001" ,
97
99
}
100
+
101
+
102
+ @mock .patch ("elasticsearch._otel.OpenTelemetry.recover_parent_context" )
103
+ @mock .patch ("elasticsearch.helpers.actions._process_bulk_chunk_success" )
104
+ @mock .patch ("elasticsearch.Elasticsearch.bulk" )
105
+ def test_forward_otel_context_to_subthreads (
106
+ _call_bulk_mock , _process_bulk_success_mock , _mock_otel_recv_context
107
+ ):
108
+ tracer , memory_exporter = setup_tracing ()
109
+ es_client = Elasticsearch ("http://localhost:9200" )
110
+ es_client ._otel = OpenTelemetry (enabled = True , tracer = tracer )
111
+
112
+ _call_bulk_mock .return_value = mock .Mock ()
113
+ actions = ({"x" : i } for i in range (100 ))
114
+ list (
115
+ helpers .parallel_bulk (es_client , actions , chunk_size = 4 )
116
+ )
117
+ # Ensures that the OTEL context has been forwarded to all chunks
118
+ assert es_client ._otel .recover_parent_context .call_count == 25
You can’t perform that action at this time.
0 commit comments