Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
import elasticsearch

from datetime import datetime

# instrument elasticsearch
ElasticsearchInstrumentor().instrument()

# Using elasticsearch as normal now will automatically generate spans
es = elasticsearch.Elasticsearch()
es.index(index='my-index', doc_type='my-type', id=1, body={'my': 'data', 'timestamp': datetime.now()})
es.get(index='my-index', doc_type='my-type', id=1)
es.index(index='my-index', doc_type='_doc', id=1, body={'my': 'data', 'timestamp': datetime.now()})
es.get(index='my-index', doc_type='_doc', id=1)

Elasticsearch instrumentation prefixes operation names with the string "Elasticsearch". This
can be changed to a different string by either setting the OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX
Expand All @@ -49,6 +49,8 @@

.. code-block:: python

from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor

ElasticsearchInstrumentor("my-custom-prefix").instrument()

The instrument() method accepts the following keyword args:
Expand All @@ -67,6 +69,7 @@ def response_hook(span: Span, response: dict)

from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
import elasticsearch
from datetime import datetime

def request_hook(span, method, url, kwargs):
if span and span.is_recording():
Expand All @@ -82,8 +85,8 @@ def response_hook(span, response):
# Using elasticsearch as normal now will automatically generate spans,
# including user custom attributes added from the hooks
es = elasticsearch.Elasticsearch()
es.index(index='my-index', doc_type='my-type', id=1, body={'my': 'data', 'timestamp': datetime.now()})
es.get(index='my-index', doc_type='my-type', id=1)
es.index(index='my-index', doc_type='_doc', id=1, body={'my': 'data', 'timestamp': datetime.now()})
es.get(index='my-index', doc_type='_doc', id=1)

API
---
Expand Down