opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

Handle elasticsearch client native instrumentation

Open xrmx opened this issue 2 years ago • 2 comments

Describe your environment

Elasticsearch client added native opentelemetry instrumentation in 8.13.0 and so currently without manual intervention it is possible to have our instrumentation and the client one create spans concurrently.

Steps to reproduce

Add opentelemetry instrumentation using elasticsearch client 8.13.0

What is the expected behavior?

Only the elasticsearch client creates spans.

What is the actual behavior?

Both client and opentelemetry instrumentation creates their own spans.

Additional context

Java opentelemetry instrumentation disables its instrumentation if a new enough elasticsearch client is found https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/9337/

xrmx avatar Apr 04 '24 17:04 xrmx

Since we are hooking into transport perform_request we can check if one of its kwargs is otel_span (https://github.com/elastic/elasticsearch-py/blob/main/elasticsearch/_sync/client/_base.py#L271) and if its enabled attribute is True (https://github.com/elastic/elasticsearch-py/blob/main/elasticsearch/_otel.py#L46).

xrmx avatar Apr 05 '24 09:04 xrmx

Before fixing this we need to make tests pass with elasticsearch 7 and 8

xrmx avatar Apr 12 '24 12:04 xrmx