feat(elasticsearch): Add Elasticsearch integration#5559
feat(elasticsearch): Add Elasticsearch integration#5559dmkoch wants to merge 1 commit intogetsentry:masterfrom
Conversation
Add a new integration for the `elasticsearch` Python client that instruments search, index, delete, and update operations with spans and breadcrumbs. Supports both elasticsearch 7.x and 8.x/9.x APIs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| operation, index = _parse_url(path) | ||
| description = "{} {}".format(method, path) | ||
|
|
||
| span = sentry_sdk.start_span( |
There was a problem hiding this comment.
Bug: The new Elasticsearch integration creates a span but doesn't use it as a context manager or manually call span.__enter__(), so the span is not attached to the current scope.
Severity: MEDIUM
Suggested Fix
The span should be managed using a with statement to ensure its lifecycle is handled correctly. Wrap the operation that the span is measuring in a with start_span(...) as span: block. This will automatically handle entering and exiting the span's context, ensuring it is properly attached to the transaction.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/integrations/elasticsearch.py#L131
Potential issue: The `elasticsearch` integration creates a new span using
`sentry_sdk.start_span(...)` but fails to properly manage its lifecycle. It does not use
a `with` statement or manually call `span.__enter__()`. This prevents the span from
being pushed onto the current scope's span stack. As a result, the span is not correctly
associated with the active transaction and may not be recorded or sent to Sentry,
leading to incomplete tracing data for Elasticsearch operations. Other integrations like
`boto3` and `pymongo` correctly handle this by explicitly calling `span.__enter__()` and
`span.__exit__()`.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| except Exception: | ||
| pass | ||
|
|
||
| return None, None |
There was a problem hiding this comment.
Unused major_version parameter in _get_connection_info
Low Severity
The major_version parameter in _get_connection_info is accepted but never referenced in the function body. The function tries both the v7 approach (obj.hosts[0]) and the v8/v9 approach (obj.transport.node_pool.all()) sequentially via try/except regardless of the version. This unused parameter is misleading — it suggests version-specific logic that doesn't exist, and could confuse future maintainers into thinking version-dependent handling was intended but accidentally omitted.


Summary
ElasticsearchIntegrationfor theelasticsearchPython client libraryTest plan
elasticsearchtest suite intest-integrations-dbs.ymlelasticsearchpackage is installed🤖 Generated with Claude Code