|
| 1 | +OpenTelemetry Instrumentation |
| 2 | +============================= |
| 3 | + |
| 4 | +|pypi| |
| 5 | + |
| 6 | +.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation.svg |
| 7 | + :target: https://pypi.org/project/opentelemetry-instrumentation/ |
| 8 | + |
| 9 | +Installation |
| 10 | +------------ |
| 11 | + |
| 12 | +:: |
| 13 | + |
| 14 | + pip install opentelemetry-instrumentation |
| 15 | + |
| 16 | + |
| 17 | +This package provides a couple of commands that help automatically instruments a program: |
| 18 | + |
| 19 | +.. note:: |
| 20 | + You need to install a distro package to get auto instrumentation working. The ``opentelemetry-distro`` |
| 21 | + package contains the default distro and automatically configures some of the common options for users. |
| 22 | + For more info about ``opentelemetry-distro`` check `here <https://opentelemetry-python.readthedocs.io/en/latest/examples/distro/README.html>`__ |
| 23 | + :: |
| 24 | + |
| 25 | + pip install opentelemetry-distro[otlp] |
| 26 | + |
| 27 | + |
| 28 | +opentelemetry-bootstrap |
| 29 | +----------------------- |
| 30 | + |
| 31 | +:: |
| 32 | + |
| 33 | + opentelemetry-bootstrap --action=install|requirements |
| 34 | + |
| 35 | +This commands inspects the active Python site-packages and figures out which |
| 36 | +instrumentation packages the user might want to install. By default it prints out |
| 37 | +a list of the suggested instrumentation packages which can be added to a requirements.txt |
| 38 | +file. It also supports installing the suggested packages when run with :code:`--action=install` |
| 39 | +flag. |
| 40 | + |
| 41 | + |
| 42 | +opentelemetry-instrument |
| 43 | +------------------------ |
| 44 | + |
| 45 | +:: |
| 46 | + |
| 47 | + opentelemetry-instrument python program.py |
| 48 | + |
| 49 | +The instrument command will try to automatically detect packages used by your python program |
| 50 | +and when possible, apply automatic tracing instrumentation on them. This means your program |
| 51 | +will get automatic distributed tracing for free without having to make any code changes |
| 52 | +at all. This will also configure a global tracer and tracing exporter without you having to |
| 53 | +make any code changes. By default, the instrument command will use the OTLP exporter but |
| 54 | +this can be overriden when needed. |
| 55 | + |
| 56 | +The command supports the following configuration options as CLI arguments and environment vars: |
| 57 | + |
| 58 | + |
| 59 | +* ``--trace-exporter`` or ``OTEL_TRACE_EXPORTER`` |
| 60 | + |
| 61 | +Used to specify which trace exporter to use. Can be set to one or more of the well-known exporter |
| 62 | +names (see below). |
| 63 | + |
| 64 | + - Defaults to `otlp`. |
| 65 | + - Can be set to `none` to disable automatic tracer initialization. |
| 66 | + |
| 67 | +You can pass multiple values to configure multiple exporters e.g, ``zipkin,prometheus`` |
| 68 | + |
| 69 | +Well known trace exporter names: |
| 70 | + |
| 71 | + - jaeger |
| 72 | + - opencensus |
| 73 | + - otlp |
| 74 | + - otlp_proto_grpc_span |
| 75 | + - zipkin |
| 76 | + |
| 77 | +``otlp`` is an alias for ``otlp_proto_grpc_span``. |
| 78 | + |
| 79 | +* ``--id-generator`` or ``OTEL_PYTHON_ID_GENERATOR`` |
| 80 | + |
| 81 | +Used to specify which IDs Generator to use for the global Tracer Provider. By default, it |
| 82 | +will use the random IDs generator. |
| 83 | + |
| 84 | +The code in ``program.py`` needs to use one of the packages for which there is |
| 85 | +an OpenTelemetry integration. For a list of the available integrations please |
| 86 | +check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#integrations>`_ |
| 87 | + |
| 88 | +* ``OTEL_PYTHON_DISABLED_INSTRUMENTATIONS`` |
| 89 | + |
| 90 | +If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations. |
| 91 | +e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "requests,django" |
| 92 | + |
| 93 | + |
| 94 | +Examples |
| 95 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 96 | + |
| 97 | +:: |
| 98 | + |
| 99 | + opentelemetry-instrument --trace-exporter otlp flask run --port=3000 |
| 100 | + |
| 101 | +The above command will pass ``--trace-exporter otlp`` to the instrument command and ``--port=3000`` to ``flask run``. |
| 102 | + |
| 103 | +:: |
| 104 | + |
| 105 | + opentelemetry-instrument --trace-exporter zipkin,otlp celery -A tasks worker --loglevel=info |
| 106 | + |
| 107 | +The above command will configure global trace provider, attach zipkin and otlp exporters to it and then |
| 108 | +start celery with the rest of the arguments. |
| 109 | + |
| 110 | +:: |
| 111 | + |
| 112 | + opentelemetry-instrument --ids-generator random flask run --port=3000 |
| 113 | + |
| 114 | +The above command will configure the global trace provider to use the Random IDs Generator, and then |
| 115 | +pass ``--port=3000`` to ``flask run``. |
| 116 | + |
| 117 | +References |
| 118 | +---------- |
| 119 | + |
| 120 | +* `OpenTelemetry Project <https://opentelemetry.io/>`_ |
0 commit comments