Skip to content

Commit b26ff3d

Browse files
committed
Instrument ping with OTel
1 parent 06f25a0 commit b26ff3d

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ async def ping(
504504
"""
505505
__path = "/"
506506
__query: t.Dict[str, t.Any] = {}
507+
__path_parts: t.Dict[str, str] = {}
507508
if error_trace is not None:
508509
__query["error_trace"] = error_trace
509510
if filter_path is not None:
@@ -515,7 +516,12 @@ async def ping(
515516
__headers = {"accept": "application/json"}
516517
try:
517518
await self.perform_request(
518-
"HEAD", __path, params=__query, headers=__headers
519+
"HEAD",
520+
__path,
521+
params=__query,
522+
headers=__headers,
523+
endpoint_id="ping",
524+
path_parts=__path_parts,
519525
)
520526
return True
521527
except (ApiError, TransportError):

elasticsearch/_sync/client/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ def ping(
504504
"""
505505
__path = "/"
506506
__query: t.Dict[str, t.Any] = {}
507+
__path_parts: t.Dict[str, str] = {}
507508
if error_trace is not None:
508509
__query["error_trace"] = error_trace
509510
if filter_path is not None:
@@ -514,7 +515,14 @@ def ping(
514515
__query["pretty"] = pretty
515516
__headers = {"accept": "application/json"}
516517
try:
517-
self.perform_request("HEAD", __path, params=__query, headers=__headers)
518+
self.perform_request(
519+
"HEAD",
520+
__path,
521+
params=__query,
522+
headers=__headers,
523+
endpoint_id="ping",
524+
path_parts=__path_parts,
525+
)
518526
return True
519527
except (ApiError, TransportError):
520528
return False

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_otel(session):
6060
silent=False,
6161
)
6262

63-
argv = pytest_argv() + ["-m", "otel"]
63+
argv = pytest_argv() + ["-m", "otel"] + session.posargs
6464
session.run(*argv, env={"TEST_WITH_OTEL": "1"})
6565

6666

test_elasticsearch/test_server/test_otel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ def test_otel_end_to_end(sync_client):
5353
assert expected_attributes.items() <= spans[0].attributes.items()
5454

5555

56+
# Since ping is manually implemented, we have a dedicated test for it
57+
def test_otel_ping(sync_client):
58+
tracer, memory_exporter = setup_tracing()
59+
sync_client._otel.tracer = tracer
60+
61+
sync_client.ping()
62+
spans = memory_exporter.get_finished_spans()
63+
assert len(spans) == 1
64+
assert spans[0].name == "ping"
65+
66+
5667
@pytest.mark.parametrize(
5768
"bulk_helper_name", ["bulk", "streaming_bulk", "parallel_bulk"]
5869
)

test_elasticsearch/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,4 @@ def wait_for_cluster_state_updates_to_finish(client, timeout=30):
191191
while time.time() < end_time:
192192
if not client.cluster.pending_tasks().get("tasks", ()):
193193
break
194+
time.sleep(0.1)

0 commit comments

Comments
 (0)