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