Skip to main content

Instrumentation Tools & Auto Instrumentation for OpenTelemetry Python

Project description

pypi

Installation

pip install opentelemetry-instrumentation

This package provides commands that help automatically instrument a program:

opentelemetry-bootstrap

opentelemetry-bootstrap [-a |--action=][install|requirements]

This command install default instrumentation packages and detects active Python site-packages to figure out which instrumentation packages the user might want to install. By default, it prints out a list of the default and detected instrumentation packages that can be added to a requirements.txt file. It also supports installing the packages when run with --action=install or -a install flag. All default and detectable instrumentation packages are defined here <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py>.

opentelemetry-instrument

opentelemetry-instrument python program.py

The instrument command will try to automatically detect packages used by your python program and when possible, apply automatic tracing instrumentation on them. This means your program will get automatic distributed tracing without having to make any code changes. This will also configure a global tracer and tracing exporter as well as a meter and meter exporter. By default, the instrument command will use the OTLP exporter but this can be overridden.

The command supports the following configuration options as CLI arguments and environment variables:

  • --traces_exporter or OTEL_TRACES_EXPORTER

  • --metrics_exporter or OTEL_METRICS_EXPORTER

  • --distro or OTEL_PYTHON_DISTRO

  • --configurator or OTEL_PYTHON_CONFIGURATOR

The exporter options define what exporter destination to use and can be set to one or more exporter names (see below). You can pass multiple values to configure multiple exporters (e.g., zipkin_json,otlp).

  • Defaults to otlp.

  • Can be set to none to disable automatic tracer initialization.

  • Can be set to ‘console` to display JSON results locally.

Trace exporter names:

  • jaeger_proto

  • jaeger_thrift

  • opencensus

  • otlp

  • otlp_proto_grpc (deprecated)

  • otlp_proto_http (deprecated)

  • zipkin_json

  • zipkin_proto

Metric exporter names:

  • otlp

  • otlp_proto_grpc (deprecated)

  • prometheus

Note: The default transport protocol for otlp is gRPC.

  • --id-generator or OTEL_PYTHON_ID_GENERATOR

Used to specify which IDs Generator to use for the global Tracer Provider. By default, it will use the random IDs generator.

The code in program.py needs to use one of the packages for which there is an OpenTelemetry integration. For a list of the available integrations please check here

  • OTEL_PYTHON_DISABLED_INSTRUMENTATIONS

If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations. e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=”requests,django”

  • OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH

If set by the user to patch_all , opentelemetry instrument will call the gevent monkeypatching method patch_all. This is considered experimental but can be useful to instrument gevent applications. e.g OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH=patch_all

Examples

opentelemetry-instrument --traces_exporter console flask run --port=3000

The above command will pass --traces_exporter console to the instrument command and --port=3000 to flask run.

opentelemetry-instrument --traces_exporter zipkin_json,otlp celery -A tasks worker --loglevel=info

The above command will configure global trace provider, attach zipkin and otlp exporters to it and then start celery with the rest of the arguments.

opentelemetry-instrument --id_generator random flask run --port=3000

The above command will configure the global trace provider to use the Random IDs Generator, and then pass --port=3000 to flask run.

Programmatic Auto-instrumentation

from opentelemetry.instrumentation import auto_instrumentation
auto_instrumentation.initialize()

If you are in an environment where you cannot use opentelemetry-instrument to inject auto-instrumentation you can do so programmatically with the code above. Please note that some instrumentations may require the initialize() method to be called before the library they instrument is imported.

References

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry_instrumentation-0.58b0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opentelemetry_instrumentation-0.58b0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file opentelemetry_instrumentation-0.58b0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation-0.58b0.tar.gz
Algorithm Hash digest
SHA256 df640f3ac715a3e05af145c18f527f4422c6ab6c467e40bd24d2ad75a00cb705
MD5 eeda256f6daf12aa910ff85ad5b7a4ab
BLAKE2b-256 f6367c307d9be8ce4ee7beb86d7f1d31027f2a6a89228240405a858d6e4d64f9

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation-0.58b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation-0.58b0-py3-none-any.whl
Algorithm Hash digest
SHA256 50f97ac03100676c9f7fc28197f8240c7290ca1baa12da8bfbb9a1de4f34cc45
MD5 3c21cca50df47bc9db73b5c58854ed7e
BLAKE2b-256 d4db5ff1cd6c5ca1d12ecf1b73be16fbb2a8af2114ee46d4b0e6d4b23f4f4db7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page