Skip to content

Commit e282879

Browse files
author
Alisson Claudino
committed
test: add scenario for OTEL context forwarding in parallel bulk
1 parent 87133b1 commit e282879

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Diff for: noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test(session):
5252
session.run(*pytest_argv())
5353

5454

55-
@nox.session(python=["3.7", "3.12"])
55+
@nox.session(python=["3.7", "3.8", "3.12"])
5656
def test_otel(session):
5757
session.install(
5858
".[dev]",

Diff for: test_elasticsearch/test_otel.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# under the License.
1717

1818
import os
19-
19+
from unittest import mock
20+
from elasticsearch import Elasticsearch
21+
from elasticsearch import helpers
2022
import pytest
2123

2224
try:
@@ -95,3 +97,22 @@ def test_detailed_span():
9597
"db.elasticsearch.cluster.name": "e9106fc68e3044f0b1475b04bf4ffd5f",
9698
"db.elasticsearch.node.name": "instance-0000000001",
9799
}
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

0 commit comments

Comments
 (0)