Skip to content

Commit 75be7dd

Browse files
Update opentelemetry conventions (#2999)
* Update opentelemetry conventions * upgrade transport required versions * feedback
1 parent 14bfbf2 commit 75be7dd

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

elasticsearch/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
# Ensure that a compatible version of elastic-transport is installed.
3030
_version_groups = tuple(int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", _elastic_transport_version).groups()) # type: ignore[union-attr]
31-
if _version_groups < (8, 0, 0) or _version_groups > (9, 0, 0):
31+
if _version_groups < (9, 1, 0) or _version_groups > (10, 0, 0):
3232
raise ImportError(
3333
"An incompatible version of elastic-transport is installed. Must be between "
34-
"v8.0.0 and v9.0.0. Install the correct version with the following command: "
35-
"$ python -m pip install 'elastic-transport>=8, <9'"
34+
"v9.1.0 and v10.0.0. Install the correct version with the following command: "
35+
"$ python -m pip install 'elastic-transport>=9.1, <10'"
3636
)
3737

3838
_version_groups = re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups() # type: ignore[assignment, union-attr]

elasticsearch/_otel.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def span(
7575
span_name = endpoint_id or method
7676
with self.tracer.start_as_current_span(span_name) as otel_span:
7777
otel_span.set_attribute("http.request.method", method)
78-
otel_span.set_attribute("db.system", "elasticsearch")
78+
otel_span.set_attribute("db.system.name", "elasticsearch")
7979
if endpoint_id is not None:
80-
otel_span.set_attribute("db.operation", endpoint_id)
80+
otel_span.set_attribute("db.operation.name", endpoint_id)
8181
for key, value in path_parts.items():
82-
otel_span.set_attribute(f"db.elasticsearch.path_parts.{key}", value)
82+
otel_span.set_attribute(f"db.operation.parameter.{key}", value)
8383

8484
yield OpenTelemetrySpan(
8585
otel_span,
@@ -94,8 +94,8 @@ def helpers_span(self, span_name: str) -> Generator[OpenTelemetrySpan]:
9494
return
9595

9696
with self.tracer.start_as_current_span(span_name) as otel_span:
97-
otel_span.set_attribute("db.system", "elasticsearch")
98-
otel_span.set_attribute("db.operation", span_name)
97+
otel_span.set_attribute("db.system.name", "elasticsearch")
98+
otel_span.set_attribute("db.operation.name", span_name)
9999
# Without a request method, Elastic APM does not display the traces
100100
otel_span.set_attribute("http.request.method", "null")
101101
yield OpenTelemetrySpan(otel_span)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ keywords = [
4141
]
4242
dynamic = ["version"]
4343
dependencies = [
44-
"elastic-transport>=8.15.1,<9",
44+
"elastic-transport>=9.1.0,<10",
4545
"python-dateutil",
4646
"typing-extensions",
4747
]

test_elasticsearch/test_otel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_minimal_span():
6868
assert spans[0].name == "GET"
6969
assert spans[0].attributes == {
7070
"http.request.method": "GET",
71-
"db.system": "elasticsearch",
71+
"db.system.name": "elasticsearch",
7272
}
7373

7474

@@ -92,11 +92,11 @@ def test_detailed_span():
9292
assert spans[0].name == "ml.open_job"
9393
assert spans[0].attributes == {
9494
"http.request.method": "GET",
95-
"db.system": "elasticsearch",
96-
"db.operation": "ml.open_job",
97-
"db.elasticsearch.path_parts.job_id": "my-job",
98-
"db.elasticsearch.cluster.name": "e9106fc68e3044f0b1475b04bf4ffd5f",
99-
"db.elasticsearch.node.name": "instance-0000000001",
95+
"db.system.name": "elasticsearch",
96+
"db.operation.name": "ml.open_job",
97+
"db.operation.parameter.job_id": "my-job",
98+
"db.namespace": "e9106fc68e3044f0b1475b04bf4ffd5f",
99+
"elasticsearch.node.name": "instance-0000000001",
100100
}
101101

102102

test_elasticsearch/test_server/test_otel.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def test_otel_end_to_end(sync_client):
4444
assert spans[0].name == "search"
4545
expected_attributes = {
4646
"http.request.method": "POST",
47-
"db.system": "elasticsearch",
48-
"db.operation": "search",
49-
"db.elasticsearch.path_parts.index": "logs-*",
47+
"db.system.name": "elasticsearch",
48+
"db.operation.name": "search",
49+
"db.operation.parameter.index": "logs-*",
5050
}
5151
# Assert expected atttributes are here, but allow other attributes too
5252
# to make this test robust to elastic-transport changes
@@ -89,8 +89,8 @@ def test_otel_bulk(sync_client, elasticsearch_url, bulk_helper_name):
8989
parent_span = spans.pop()
9090
assert parent_span.name == f"helpers.{bulk_helper_name}"
9191
assert parent_span.attributes == {
92-
"db.system": "elasticsearch",
93-
"db.operation": f"helpers.{bulk_helper_name}",
92+
"db.system.name": "elasticsearch",
93+
"db.operation.name": f"helpers.{bulk_helper_name}",
9494
"http.request.method": "null",
9595
}
9696

@@ -99,9 +99,9 @@ def test_otel_bulk(sync_client, elasticsearch_url, bulk_helper_name):
9999
assert span.name == "bulk"
100100
expected_attributes = {
101101
"http.request.method": "PUT",
102-
"db.system": "elasticsearch",
103-
"db.operation": "bulk",
104-
"db.elasticsearch.path_parts.index": "test-index",
102+
"db.system.name": "elasticsearch",
103+
"db.operation.name": "bulk",
104+
"db.operation.parameter.index": "test-index",
105105
}
106106
# Assert expected atttributes are here, but allow other attributes too
107107
# to make this test robust to elastic-transport changes

0 commit comments

Comments
 (0)