Skip to content

fix(opensearch): pass positional args to transport.perform_request for ddtrace compatibility#3132

Merged
ArzelaAscoIi merged 5 commits into
mainfrom
copilot/fix-ddtrace-error-open-search
Apr 13, 2026
Merged

fix(opensearch): pass positional args to transport.perform_request for ddtrace compatibility#3132
ArzelaAscoIi merged 5 commits into
mainfrom
copilot/fix-ddtrace-error-open-search

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

  • Add inline comment above both transport.perform_request(...) calls in _query_sql and _query_sql_async explaining why positional args are used (ddtrace compatibility)
Original prompt

Issue Title: ddtrace issue when using sqlmetadataretriever
Issue Description: ### Problem

When OpenSearchSQLRetriever executes a SQL query, ddtrace's Elasticsearch patch intercepts _client.transport.perform_request() and attempts to unpack (method, target) = args. The call arrives with 0 positional arguments, raising a ValueError that propagates as DocumentStoreError: Failed to execute SQL query in OpenSearch: not enough values to unpack (expected 2, got 0).

Customer / Business Impact

Customers (flagged via Sols) using OpenSearchSQLRetriever in environments with Datadog APM (ddtrace) active are completely blocked from executing SQL queries against OpenSearch. All such requests return HTTP 400.

Expected Behaviour

SQL queries via OpenSearchSQLRetriever should execute successfully regardless of whether Datadog APM (ddtrace) instrumentation is active in the environment.

How to Reproduce

  1. Enable Datadog APM (ddtrace) instrumentation in the Haystack service.
  2. Use the OpenSearchSQLRetriever component (or call OpenSearchDocumentStore._query_sql() directly).
  3. Run a SQL query, e.g. SELECT COUNT(*) AS file_count FROM file WHERE file_name IS NOT NULL;
  4. Observe the 400 error with ValueError: not enough values to unpack (expected 2, got 0) inside the ddtrace Elasticsearch patch.

Code / Configuration

Component configuration used at time of repro:

{
  "component_type": "haystack_integrations.components.retrievers.opensearch.sql_retriever.OpenSearchSQLRetriever",
  "init_params": {
    "raise_on_failure": true,
    "fetch_size": 1000,
    "document_store": {
      "type": "haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore",
      "init_parameters": {
        "index": "Standard-Index-English",
        "max_chunk_bytes": 104857600,
        "embedding_dim": 768,
        "return_embedding": false,
        "settings": {"index.knn": true},
        "create_index": true
      }
    }
  },
  "input": {
    "query": "SELECT COUNT(*) AS file_count FROM file WHERE file_name IS NOT NULL;"
  }
}

Full stack trace from API response:

Error running component haystack_integrations.components.retrievers.opensearch.sql_retriever.OpenSearchSQLRetriever:
haystack.document_stores.errors.errors.DocumentStoreError: Failed to execute SQL query in OpenSearch: not enough values to unpack (expected 2, got 0)

Traceback (most recent call last):
  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack_integrations/document_stores/opensearch/document_store.py", line 2006, in _query_sql
    response_data = self._client.transport.perform_request(
  File "/home/haystackd/.local/lib/python3.12/site-packages/ddtrace/contrib/internal/elasticsearch/patch.py", line 249, in _perform_request
    result = next(coro)
  File "/home/haystackd/.local/lib/python3.12/site-packages/ddtrace/contrib/internal/elasticsearch/patch.py", line 154, in _perform_request
    method, target = args
ValueError: not enough values to unpack (expected 2, got 0)

The above exception was the direct cause of the following exception:

  File "/home/haystackd/.local/lib/python3.12/site-packages/dc_haystack_utilities/api/haystack/haystack_service.py", line 468, in run_component
    output: Mapping[str, Any] = component.run(**component_input)
  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack_integrations/components/retrievers/opensearch/sql_retriever.py", line 125, in run
    raise e
  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack_integrations/components/retrievers/opensearch/sql_retriever.py", line 122, in run
    result = doc_store._query_sql(query=query, fetch_size=fetch_size)
  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack_integrations/document_stores/opensearch/document_store.py", line 2015, in _query_sql
    raise DocumentStoreError(msg) from e
haystack.document_stores.errors.errors.DocumentStoreError: Failed to execute SQL query in OpenSearch: not enough values to unpack (expected 2, got 0)

Acceptance Criteria

  • SQL queries via OpenSearchSQLRetriever succeed without errors when ddtrace is active.
  • Users no longer see "Failed to execute SQL query in OpenSearch" errors caused by the Datadog instrumentation's argument-unpacking incompatibility with the OpenSearch client's perform_request signature.

Additional Context

The root cause is in ddtrace/contrib/internal/elasticsearch/patch.py line 154: method, target = args assumes positional args but the OpenSearch client passes them differently. This is a ddtrace version compatibility issue with the OpenSearch Python client.

🎥 Jam: https://jam.dev/c/887748f3-cfd8-45eb-b173-fd4a30e3d94b


Consolidated by Marvin
Fixes https://linear.app/deepset/issue/PIP-226/ddtrace-issue-when-using-sqlmetadataretriever
Branch Name should include the identifier "PIP-226"

Issue ...

…r ddtrace compatibility (PIP-226)

Agent-Logs-Url: https://github.com/deepset-ai/haystack-core-integrations/sessions/7394727c-b32f-412d-9811-4e720db0b0d4

Co-authored-by: ArzelaAscoIi <37148029+ArzelaAscoIi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ddtrace error in OpenSearchSQLRetriever fix(opensearch): pass positional args to transport.perform_request for ddtrace compatibility Apr 10, 2026
Copilot AI requested a review from ArzelaAscoIi April 10, 2026 17:59
@ArzelaAscoIi ArzelaAscoIi marked this pull request as ready for review April 10, 2026 18:08
@ArzelaAscoIi ArzelaAscoIi requested a review from a team as a code owner April 10, 2026 18:08
@ArzelaAscoIi ArzelaAscoIi requested review from anakin87 and removed request for a team April 10, 2026 18:08
@github-actions github-actions Bot added integration:opensearch type:documentation Improvements or additions to documentation labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Coverage report (opensearch)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/opensearch/src/haystack_integrations/document_stores/opensearch
  document_store.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few minor comments

Comment thread integrations/opensearch/CHANGELOG.md Outdated
method="POST",
url="/_plugins/_sql",
"POST",
"/_plugins/_sql",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment explaining why we use positional args here, so we don't forget in the future

method="POST",
url="/_plugins/_sql",
"POST",
"/_plugins/_sql",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment explaining why we use positional args here, so we don't forget in the future

…dtrace compatibility

Agent-Logs-Url: https://github.com/deepset-ai/haystack-core-integrations/sessions/8aaa7986-fefa-42c4-bd78-8e70e746aa26

Co-authored-by: ArzelaAscoIi <37148029+ArzelaAscoIi@users.noreply.github.com>
@ArzelaAscoIi ArzelaAscoIi requested a review from anakin87 April 13, 2026 09:34
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ArzelaAscoIi ArzelaAscoIi merged commit a5ad293 into main Apr 13, 2026
9 checks passed
@ArzelaAscoIi ArzelaAscoIi deleted the copilot/fix-ddtrace-error-open-search branch April 13, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:opensearch type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants