Skip to content

[BUG]: OpenSearchPy client 3.x compatibility issue with ddtrace elastic module #14957

@ashi-monaco

Description

@ashi-monaco

Tracer Version(s)

3.5.0

Python Version(s)

3.11

Pip Version(s)

poetry 1.8.3

Bug Report

Description:

Bug Report

I'm encountering a compatibility issue between ddtrace's elasticsearch integration and the opensearch-py library version 2.x+. The error occurs when ddtrace auto-instrumentation patches the perform_request method used by both libraries. The compatibility issue results in
ValueError: not enough values to unpack (expected 2, got 1) when using opensearch-py 2.x+ with elasticsearch integration

Environment:

  • ddtrace version: 3.5.0
  • opensearch-py version: 3.0.0
  • Python version: 3.11
  • Environment: Production Kubernetes deployment with auto-instrumentation via ddtrace-run

Error Details:

Traceback:

Traceback (most recent call last):
  File "/app/api/src/rest/v1/search/_search.py", line 54, in search_foo
    index = FooOpenSearchIndex(create_if_not_exists=True)
  File "/app/search/index/_foo_opensearch_index_v2.py", line 122, in __init__
    return super().__init__(
  File "/app/search/index/opensearch_index.py", line 115, in __init__
    self._ensure_foo_pipeline(
  File "/app/search/index/opensearch_index.py", line 232, in _ensure_foo_pipeline
    client.http.get(f"/_search/pipeline/{FOO_PIPELINE_NAME}")
  File "/usr/local/lib/python3.11/site-packages/opensearchpy/client/http.py", line 38, in get
    return self.transport.perform_request(
  File "/usr/local/lib/python3.11/site-packages/ddtrace/contrib/internal/elasticsearch/patch.py", line 251, in _perform_request
    result = next(coro)
  File "/usr/local/lib/python3.11/site-packages/ddtrace/contrib/internal/elasticsearch/patch.py", line 156, in _perform_request
    method, target = args
ValueError: not enough values to unpack (expected 2, got 1)

Error Location: ddtrace/contrib/internal/elasticsearch/patch.py:156

Root Cause Analysis:

The issue stems from a function signature mismatch between elasticsearch v7.x and opensearch-py 2.x+:

  1. ddtrace's elasticsearch integration automatically patches the perform_request method used by both elasticsearch and opensearch-py libraries
  2. The patch expects the function signature from elasticsearch v7.x: method, target = args
  3. opensearch-py 2.x+ passes arguments differently, causing the unpacking error

Reproduction Steps:

  1. Install ddtrace >= 2.9.0 and opensearch-py >= 2.0.0
  2. Run application with ddtrace-run (auto-instrumentation enabled)
  3. Create an OpenSearch client and make any HTTP request (e.g., client.http.get())
  4. The error occurs when ddtrace's patched perform_request method tries to unpack arguments

Expected Behavior:

OpenSearch operations should work without errors when ddtrace auto-instrumentation is enabled.

Actual Behavior:

ValueError: not enough values to unpack (expected 2, got 1) is raised, preventing OpenSearch operations.

Workaround:

Currently using DD_PATCH_MODULES: "elasticsearch:false" to disable the elasticsearch integration, which resolves the issue but disables tracing for OpenSearch operations.

Impact:

  • Severity: High - Breaks OpenSearch functionality when auto-instrumentation is enabled
  • Affected Users: Anyone using opensearch-py 2.x+ with ddtrace auto-instrumentation
  • Workaround Available: Yes, but with reduced observability

Additional Context:

This appears to be a known compatibility issue that affects users migrating from elasticsearch to opensearch-py while maintaining ddtrace observability. The opensearch-py library is a popular fork of elasticsearch-py and is widely used in production environments.

Request:

Could the elasticsearch integration be updated to handle both elasticsearch v7.x and opensearch-py 2.x+ function signatures, or could a separate opensearch integration be created to properly support the opensearch-py library? I can take a stab at fixing it in a PR.

Reproduction Code

No response

Error Logs

No response

Libraries in Use

No response

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions