Improve elasticsearch instrumentation examples (#3367)
* Improve elasticsearch instrumentation examples * Fix doc_type for elasticsearch instrumentation examples
This commit is contained in:
parent
db617eb3fd
commit
164259e149
|
|
@ -32,15 +32,15 @@ Usage
|
||||||
|
|
||||||
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
|
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
# instrument elasticsearch
|
# instrument elasticsearch
|
||||||
ElasticsearchInstrumentor().instrument()
|
ElasticsearchInstrumentor().instrument()
|
||||||
|
|
||||||
# Using elasticsearch as normal now will automatically generate spans
|
# Using elasticsearch as normal now will automatically generate spans
|
||||||
es = elasticsearch.Elasticsearch()
|
es = elasticsearch.Elasticsearch()
|
||||||
es.index(index='my-index', doc_type='my-type', id=1, body={'my': 'data', 'timestamp': datetime.now()})
|
es.index(index='my-index', doc_type='_doc', id=1, body={'my': 'data', 'timestamp': datetime.now()})
|
||||||
es.get(index='my-index', doc_type='my-type', id=1)
|
es.get(index='my-index', doc_type='_doc', id=1)
|
||||||
|
|
||||||
Elasticsearch instrumentation prefixes operation names with the string "Elasticsearch". This
|
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
|
can be changed to a different string by either setting the OTEL_PYTHON_ELASTICSEARCH_NAME_PREFIX
|
||||||
|
|
@ -49,6 +49,8 @@ environment variable or by passing the prefix as an argument to the instrumentor
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
|
||||||
|
|
||||||
ElasticsearchInstrumentor("my-custom-prefix").instrument()
|
ElasticsearchInstrumentor("my-custom-prefix").instrument()
|
||||||
|
|
||||||
The instrument() method accepts the following keyword args:
|
The instrument() method accepts the following keyword args:
|
||||||
|
|
@ -67,6 +69,7 @@ for example:
|
||||||
|
|
||||||
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
|
from opentelemetry.instrumentation.elasticsearch import ElasticsearchInstrumentor
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
def request_hook(span, method, url, kwargs):
|
def request_hook(span, method, url, kwargs):
|
||||||
if span and span.is_recording():
|
if span and span.is_recording():
|
||||||
|
|
@ -82,8 +85,8 @@ for example:
|
||||||
# Using elasticsearch as normal now will automatically generate spans,
|
# Using elasticsearch as normal now will automatically generate spans,
|
||||||
# including user custom attributes added from the hooks
|
# including user custom attributes added from the hooks
|
||||||
es = elasticsearch.Elasticsearch()
|
es = elasticsearch.Elasticsearch()
|
||||||
es.index(index='my-index', doc_type='my-type', id=1, body={'my': 'data', 'timestamp': datetime.now()})
|
es.index(index='my-index', doc_type='_doc', id=1, body={'my': 'data', 'timestamp': datetime.now()})
|
||||||
es.get(index='my-index', doc_type='my-type', id=1)
|
es.get(index='my-index', doc_type='_doc', id=1)
|
||||||
|
|
||||||
API
|
API
|
||||||
---
|
---
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue