diff --git a/elasticsearch/__init__.py b/elasticsearch/__init__.py index c2277228a..c696bd91b 100644 --- a/elasticsearch/__init__.py +++ b/elasticsearch/__init__.py @@ -28,11 +28,11 @@ # Ensure that a compatible version of elastic-transport is installed. _version_groups = tuple(int(x) for x in re.search(r"^(\d+)\.(\d+)\.(\d+)", _elastic_transport_version).groups()) # type: ignore[union-attr] -if _version_groups < (8, 0, 0) or _version_groups > (9, 0, 0): +if _version_groups < (9, 1, 0) or _version_groups > (10, 0, 0): raise ImportError( "An incompatible version of elastic-transport is installed. Must be between " - "v8.0.0 and v9.0.0. Install the correct version with the following command: " - "$ python -m pip install 'elastic-transport>=8, <9'" + "v9.1.0 and v10.0.0. Install the correct version with the following command: " + "$ python -m pip install 'elastic-transport>=9.1, <10'" ) _version_groups = re.search(r"^(\d+)\.(\d+)\.(\d+)", __versionstr__).groups() # type: ignore[assignment, union-attr] diff --git a/elasticsearch/_otel.py b/elasticsearch/_otel.py index 71a0702e7..c13ed10c2 100644 --- a/elasticsearch/_otel.py +++ b/elasticsearch/_otel.py @@ -75,11 +75,11 @@ def span( span_name = endpoint_id or method with self.tracer.start_as_current_span(span_name) as otel_span: otel_span.set_attribute("http.request.method", method) - otel_span.set_attribute("db.system", "elasticsearch") + otel_span.set_attribute("db.system.name", "elasticsearch") if endpoint_id is not None: - otel_span.set_attribute("db.operation", endpoint_id) + otel_span.set_attribute("db.operation.name", endpoint_id) for key, value in path_parts.items(): - otel_span.set_attribute(f"db.elasticsearch.path_parts.{key}", value) + otel_span.set_attribute(f"db.operation.parameter.{key}", value) yield OpenTelemetrySpan( otel_span, @@ -94,8 +94,8 @@ def helpers_span(self, span_name: str) -> Generator[OpenTelemetrySpan]: return with self.tracer.start_as_current_span(span_name) as otel_span: - otel_span.set_attribute("db.system", "elasticsearch") - otel_span.set_attribute("db.operation", span_name) + otel_span.set_attribute("db.system.name", "elasticsearch") + otel_span.set_attribute("db.operation.name", span_name) # Without a request method, Elastic APM does not display the traces otel_span.set_attribute("http.request.method", "null") yield OpenTelemetrySpan(otel_span) diff --git a/pyproject.toml b/pyproject.toml index 845d52493..6c81fc2b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ keywords = [ ] dynamic = ["version"] dependencies = [ - "elastic-transport>=8.15.1,<9", + "elastic-transport>=9.1.0,<10", "python-dateutil", "typing-extensions", ] diff --git a/test_elasticsearch/test_otel.py b/test_elasticsearch/test_otel.py index 48eb9ea58..39edf5869 100644 --- a/test_elasticsearch/test_otel.py +++ b/test_elasticsearch/test_otel.py @@ -68,7 +68,7 @@ def test_minimal_span(): assert spans[0].name == "GET" assert spans[0].attributes == { "http.request.method": "GET", - "db.system": "elasticsearch", + "db.system.name": "elasticsearch", } @@ -92,11 +92,11 @@ def test_detailed_span(): assert spans[0].name == "ml.open_job" assert spans[0].attributes == { "http.request.method": "GET", - "db.system": "elasticsearch", - "db.operation": "ml.open_job", - "db.elasticsearch.path_parts.job_id": "my-job", - "db.elasticsearch.cluster.name": "e9106fc68e3044f0b1475b04bf4ffd5f", - "db.elasticsearch.node.name": "instance-0000000001", + "db.system.name": "elasticsearch", + "db.operation.name": "ml.open_job", + "db.operation.parameter.job_id": "my-job", + "db.namespace": "e9106fc68e3044f0b1475b04bf4ffd5f", + "elasticsearch.node.name": "instance-0000000001", } diff --git a/test_elasticsearch/test_server/test_otel.py b/test_elasticsearch/test_server/test_otel.py index 3f8033d7b..e0b0cc776 100644 --- a/test_elasticsearch/test_server/test_otel.py +++ b/test_elasticsearch/test_server/test_otel.py @@ -44,9 +44,9 @@ def test_otel_end_to_end(sync_client): assert spans[0].name == "search" expected_attributes = { "http.request.method": "POST", - "db.system": "elasticsearch", - "db.operation": "search", - "db.elasticsearch.path_parts.index": "logs-*", + "db.system.name": "elasticsearch", + "db.operation.name": "search", + "db.operation.parameter.index": "logs-*", } # Assert expected atttributes are here, but allow other attributes too # to make this test robust to elastic-transport changes @@ -89,8 +89,8 @@ def test_otel_bulk(sync_client, elasticsearch_url, bulk_helper_name): parent_span = spans.pop() assert parent_span.name == f"helpers.{bulk_helper_name}" assert parent_span.attributes == { - "db.system": "elasticsearch", - "db.operation": f"helpers.{bulk_helper_name}", + "db.system.name": "elasticsearch", + "db.operation.name": f"helpers.{bulk_helper_name}", "http.request.method": "null", } @@ -99,9 +99,9 @@ def test_otel_bulk(sync_client, elasticsearch_url, bulk_helper_name): assert span.name == "bulk" expected_attributes = { "http.request.method": "PUT", - "db.system": "elasticsearch", - "db.operation": "bulk", - "db.elasticsearch.path_parts.index": "test-index", + "db.system.name": "elasticsearch", + "db.operation.name": "bulk", + "db.operation.parameter.index": "test-index", } # Assert expected atttributes are here, but allow other attributes too # to make this test robust to elastic-transport changes