Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2151](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2298))
- Avoid losing repeated HTTP headers
([#2266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2266))
- `opentelemetry-instrumentation-elasticsearch` Don't send bulk request body as db statement
([#2355](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2355))

## Version 1.23.0/0.44b0 (2024-02-23)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ def wrapper(wrapped, _, args, kwargs):
if method:
attributes["elasticsearch.method"] = method
if body:
attributes[SpanAttributes.DB_STATEMENT] = sanitize_body(
body
)
# Don't set db.statement for bulk requests, as it can be very large
if isinstance(body, dict):
attributes[
SpanAttributes.DB_STATEMENT
] = sanitize_body(body)
if params:
attributes["elasticsearch.params"] = str(params)
if doc_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

Article = helpers.Article

# pylint: disable=too-many-public-methods


@mock.patch(
"elasticsearch.connection.http_urllib3.Urllib3HttpConnection.perform_request"
Expand Down Expand Up @@ -486,3 +488,35 @@ def test_body_sanitization(self, _):
sanitize_body(json.dumps(sanitization_queries.interval_query)),
str(sanitization_queries.interval_query_sanitized),
)

def test_bulk(self, request_mock):
request_mock.return_value = (1, {}, "")

es = Elasticsearch()
es.bulk(
[
{
"_op_type": "index",
"_index": "sw",
"_doc_type": "_doc",
"_id": 1,
"doc": {"name": "adam"},
},
{
"_op_type": "index",
"_index": "sw",
"_doc_type": "_doc",
"_id": 1,
"doc": {"name": "adam"},
},
]
)

spans_list = self.get_finished_spans()
self.assertEqual(len(spans_list), 1)
span = spans_list[0]

# Check version and name in span's instrumentation info
self.assertEqualSpanInstrumentationInfo(
span, opentelemetry.instrumentation.elasticsearch
)