|
| 1 | +OpenTelemetry Jaeger Exporter |
| 2 | +============================= |
| 3 | + |
| 4 | +Installation |
| 5 | +------------ |
| 6 | + |
| 7 | +:: |
| 8 | + |
| 9 | + pip install opentelemetry-ext-jaeger |
| 10 | + |
| 11 | + |
| 12 | +Usage |
| 13 | +----- |
| 14 | + |
| 15 | +The **OpenTelemetry Jaeger Exporter** allows to export `OpenTelemetry`_ traces to `Jaeger`_. |
| 16 | +This exporter always send traces to the configured agent using Thrift compact protocol over UDP. |
| 17 | +An optional collector can be configured, in this case Thrift binary protocol over HTTP is used. |
| 18 | +gRPC is still not supported by this implementation. |
| 19 | + |
| 20 | + |
| 21 | +.. _Jaeger: https://www.jaegertracing.io/ |
| 22 | +.. _OpenTelemetry: https://github.com/opentelemetry/opentelemetry-python/ |
| 23 | + |
| 24 | +.. code:: python |
| 25 | +
|
| 26 | + from opentelemetry import trace |
| 27 | + from opentelemetry.ext import jaeger |
| 28 | + from opentelemetry.sdk.trace import Tracer |
| 29 | + from opentelemetry.sdk.trace.export import BatchExportSpanProcessor |
| 30 | +
|
| 31 | + trace.set_preferred_tracer_implementation(lambda T: Tracer()) |
| 32 | + tracer = trace.tracer() |
| 33 | +
|
| 34 | + # create a JaegerSpanExporter |
| 35 | + jaeger_exporter = jaeger.JaegerSpanExporter( |
| 36 | + service_name='my-helloworld-service', |
| 37 | + # configure agent |
| 38 | + agent_host_name='localhost', |
| 39 | + agent_port=6831, |
| 40 | + # optional: configure also collector |
| 41 | + # collector_host_name='localhost', |
| 42 | + # collector_port=14268, |
| 43 | + # collector_endpoint='/api/traces?format=jaeger.thrift', |
| 44 | + # username=xxxx, # optional |
| 45 | + # password=xxxx, # optional |
| 46 | + ) |
| 47 | +
|
| 48 | + # Create a BatchExportSpanProcessor and add the exporter to it |
| 49 | + span_processor = BatchExportSpanProcessor(jaeger_exporter) |
| 50 | +
|
| 51 | + # add to the tracer |
| 52 | + tracer.add_span_processor(span_processor) |
| 53 | +
|
| 54 | + with tracer.start_span('foo'): |
| 55 | + print('Hello world!') |
| 56 | +
|
| 57 | + # shutdown the span processor |
| 58 | + # TODO: this has to be improved so user doesn't need to call it manually |
| 59 | + span_processor.shutdown() |
| 60 | +
|
| 61 | +The `examples <./examples>`_ folder contains more elaborated examples. |
| 62 | + |
| 63 | +References |
| 64 | +---------- |
| 65 | + |
| 66 | +* `Jaeger <https://www.jaegertracing.io/>`_ |
| 67 | +* `OpenTelemetry Project <https://opentelemetry.io/>`_ |
0 commit comments