dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

Support elasticsearch8

Open lu911 opened this issue 3 years ago • 2 comments

Thanks for taking the time for reporting an issue!

Before reporting an issue on dd-trace-py, please be sure to provide all necessary information.

If you're hitting a bug, make sure that you're using the latest version of this library.

Which version of dd-trace-py are you using?

0.59.1

Which version of pip are you using?

22.0.3

Which version of the libraries are you using?

elastic-transport==8.0.1 elasticsearch==8.1.0 ddtrace==0.59.1 Django==4.0.2 gunicorn==20.1.0

How can we reproduce your problem?

ddtrace-run gunicorn -c gunicorn.py app.wsgi

What is the result that you get?

AttributeError ddtrace.contrib.elasticsearch.patch in _patch

'elasticsearch.transport' module is deprecated on elasticsearch8.

lu911 avatar Mar 23 '22 16:03 lu911

Running into this as well. Would love a fix.

stblain avatar Jun 01 '22 17:06 stblain

Temporarily

from ddtrace import tracer
from ddtrace.pin import Pin
from ddtrace.vendor.wrapt import wrap_function_wrapper as _w

def patch_es8():
    def _es_modules():
        module_names = (
            "elasticsearch",
        )
        for module_name in module_names:
            try:
                yield import_module(module_name)
            except ImportError:
                pass

    # noinspection PyProtectedMember
    def _get_perform_request(elasticsearch):
        from ddtrace.contrib.elasticsearch.patch import _get_perform_request as _dd_gpr

        def _perform_request(func, instance, args, kwargs):
            instance.serializer = instance.serializers
            return _dd_gpr(elasticsearch)(func, instance, args, kwargs)

        return _perform_request

    # noinspection PyProtectedMember
    def _patch(elasticsearch):
        if getattr(elasticsearch, "_datadog_patch", False):
            return
        setattr(elasticsearch, "_datadog_patch", True)

        import elastic_transport

        _w(elastic_transport._transport,
            "Transport.perform_request",
            _get_perform_request(elasticsearch))
        Pin().onto(elastic_transport.Transport)

    for es_mod in _es_modules():
        _patch(es_mod)


# ES8
patch_es8()

lu911 avatar Jul 20 '22 08:07 lu911

Hi, getting this as well when enabling dd-trace with the v8 client. Any news of a patch version?

petroslamb avatar Mar 20 '23 14:03 petroslamb

I tried to disable elasticsearch tracing with the DD_TRACE_ELASTICSEARCH_ENABLED=false flag and it did ~not~ WORK for me.

For now the only other solution I found is to remain in a late 7.x version of the library and enable the compatibility mode with a v8 cluster using ELASTIC_CLIENT_APIVERSIONING=1.

ddtrace                  1.9.3
elastic-transport        8.4.0
elasticsearch            8.6.2
python      3.9.13

EDIT: The env var to disable ES worked.

petroslamb avatar Mar 21 '23 09:03 petroslamb

Elasticsearch 8 support was added in #7113 by @chadawagner

emmettbutler avatar Nov 03 '23 13:11 emmettbutler