|
| 1 | +OpenTelemetry Distro |
| 2 | +==================== |
| 3 | + |
| 4 | +In order to make using OpenTelemetry and auto-instrumentation as quick as possible without sacrificing flexibility, |
| 5 | +OpenTelemetry distros provide a mechanism to automatically configure some of the more common options for users. By |
| 6 | +harnessing their power, users of OpenTelemetry can configure the components as they need. The ``opentelemetry-distro`` |
| 7 | +package provides some defaults to users looking to get started, it configures: |
| 8 | + |
| 9 | +- the SDK TracerProvider |
| 10 | +- a BatchSpanProcessor |
| 11 | +- the OTLP ``SpanExporter`` to send data to an OpenTelemetry collector |
| 12 | + |
| 13 | +The package also provides a starting point for anyone interested in producing an alternative distro. The |
| 14 | +interfaces implemented by the package are loaded by the auto-instrumentation via the ``opentelemetry_distro`` |
| 15 | +and ``opentelemetry_configurator`` entry points to configure the application before any other code is |
| 16 | +executed. |
| 17 | + |
| 18 | +In order to automatically export data from OpenTelemetry to the OpenTelemetry collector, installing the |
| 19 | +package will setup all the required entry points. |
| 20 | + |
| 21 | +.. code:: sh |
| 22 | +
|
| 23 | + $ pip install opentelemetry-distro[otlp] opentelemetry-instrumentation |
| 24 | +
|
| 25 | +Start the Collector locally to see data being exported. Write the following file: |
| 26 | + |
| 27 | +.. code-block:: yaml |
| 28 | +
|
| 29 | + # /tmp/otel-collector-config.yaml |
| 30 | + receivers: |
| 31 | + otlp: |
| 32 | + protocols: |
| 33 | + grpc: |
| 34 | + http: |
| 35 | + exporters: |
| 36 | + logging: |
| 37 | + loglevel: debug |
| 38 | + processors: |
| 39 | + batch: |
| 40 | + service: |
| 41 | + pipelines: |
| 42 | + traces: |
| 43 | + receivers: [otlp] |
| 44 | + exporters: [logging] |
| 45 | + processors: [batch] |
| 46 | +
|
| 47 | +Then start the Docker container: |
| 48 | + |
| 49 | +.. code-block:: sh |
| 50 | +
|
| 51 | + docker run -p 4317:4317 \ |
| 52 | + -v /tmp/otel-collector-config.yaml:/etc/otel-collector-config.yaml \ |
| 53 | + otel/opentelemetry-collector:latest \ |
| 54 | + --config=/etc/otel-collector-config.yaml |
| 55 | +
|
| 56 | +The following code will create a span with no configuration. |
| 57 | + |
| 58 | +.. code:: python |
| 59 | +
|
| 60 | + # no_configuration.py |
| 61 | + from opentelemetry import trace |
| 62 | +
|
| 63 | + with trace.get_tracer(__name__).start_as_current_span("foo"): |
| 64 | + with trace.get_tracer(__name__).start_as_current_span("bar"): |
| 65 | + print("baz") |
| 66 | +
|
| 67 | +Lastly, run the ``no_configuration.py`` with the auto-instrumentation: |
| 68 | + |
| 69 | +.. code-block:: sh |
| 70 | +
|
| 71 | + $ opentelemetry-instrument python no_configuration.py |
| 72 | +
|
| 73 | +The resulting span will appear in the output from the collector and look similar to this: |
| 74 | + |
| 75 | +.. code-block:: sh |
| 76 | +
|
| 77 | + Resource labels: |
| 78 | + -> telemetry.sdk.language: STRING(python) |
| 79 | + -> telemetry.sdk.name: STRING(opentelemetry) |
| 80 | + -> telemetry.sdk.version: STRING(1.1.0) |
| 81 | + -> service.name: STRING(unknown_service) |
| 82 | + InstrumentationLibrarySpans #0 |
| 83 | + InstrumentationLibrary __main__ |
| 84 | + Span #0 |
| 85 | + Trace ID : db3c99e5bfc50ef8be1773c3765e8845 |
| 86 | + Parent ID : 0677126a4d110cb8 |
| 87 | + ID : 3163b3022808ed1b |
| 88 | + Name : bar |
| 89 | + Kind : SPAN_KIND_INTERNAL |
| 90 | + Start time : 2021-05-06 22:54:51.23063 +0000 UTC |
| 91 | + End time : 2021-05-06 22:54:51.230684 +0000 UTC |
| 92 | + Status code : STATUS_CODE_UNSET |
| 93 | + Status message : |
| 94 | + Span #1 |
| 95 | + Trace ID : db3c99e5bfc50ef8be1773c3765e8845 |
| 96 | + Parent ID : |
| 97 | + ID : 0677126a4d110cb8 |
| 98 | + Name : foo |
| 99 | + Kind : SPAN_KIND_INTERNAL |
| 100 | + Start time : 2021-05-06 22:54:51.230549 +0000 UTC |
| 101 | + End time : 2021-05-06 22:54:51.230706 +0000 UTC |
| 102 | + Status code : STATUS_CODE_UNSET |
| 103 | + Status message : |
| 104 | +
|
0 commit comments