elastic / elasticsearch-py

Official Python client for Elasticsearch
https://ela.st/es-python
Apache License 2.0
4.24k stars 1.18k forks source link

Add OpenTelemetry support #2435

Closed pquentin closed 5 months ago

pquentin commented 9 months ago

There are currently three ways to instrument an application that uses the Elasticsearch Python client:

The main benefit of the existing approaches is that while they can handle past versions of this client, they're fragile to changes in elasticsearch-py, are difficult to test and may be suboptimal as the code may need refactorings to emit spans with complete information. In the case of the OpenTelemetry instrumentations, they don't have clear owners. For this reason, it makes sense to implement this in elasticsearch-py where the feature will be tested and maintained.


We will follow the existing Semantic conventions for Elasticsearch and emit spans for all requests when the opentelemetry-api optional package will be detected. Correctly configuring OpenTelemetry SDK will be left to the user.

The elasticsearch-ruby OpenTelemetry instrumentation will be used as inspiration:

Configuration

Testing

We will have an "OpenTelemetry" test mode that will run the whole test suite with OpenTelemetry enabled and will test a simple API to make sure the exported spans are correct.

The InMemorySpanExporter allows end-to-end testing.

Endpoint id and path parts

Those will need to be passed to the transport.

Steps

Supported attributes

Required

Recommended

pquentin commented 5 months ago

Closing as sanitization isn't mandatory for actual support. We can always add it later.