Package: opentelemetry-instrumentation
Installationpip install opentelemetry-instrumentationThis package provides commands that help automatically instrument a program:NoteYou need to install a distro package to get auto instrumentation working. Theopentelemetry-distropackage contains the default distro and configurator and automatically configures some of the common options for users.
For more info aboutopentelemetry-distrocheckherepip install "opentelemetry-distro[otlp]"When creating a custom distro and/or configurator, be sure to add entry points for each underopentelemetry_distroandopentelemetry_configuratorrespectfully.
If you have entry points for multiple distros or configurators present in your environment, you should specify the entry point name of the distro and configurator you want to be used via theOTEL_PYTHON_DISTROandOTEL_PYTHON_CONFIGURATORenvironment variables.opentelemetry-bootstrapopentelemetry-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=installor-a installflag. All default and detectable
instrumentation packages are definedhere <https://github.com/flands/opentelemetry-python-contrib/blob/main/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py>.opentelemetry-instrumentopentelemetry-instrument python program.pyThe 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_exporterorOTEL_TRACES_EXPORTER--metrics_exporterorOTEL_METRICS_EXPORTER--distroorOTEL_PYTHON_DISTRO--configuratororOTEL_PYTHON_CONFIGURATORThe 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 tootlp.Can be set tononeto disable automatic tracer initialization.Can be set to ‘console` to display JSON results locally.Trace exporter names:jaeger_protojaeger_thriftopencensusotlpotlp_proto_grpc (deprecated)otlp_proto_http (deprecated)zipkin_jsonzipkin_protoMetric exporter names:otlpotlp_proto_grpc (deprecated)prometheusNote: The default transport protocol forotlpis gRPC.--id-generatororOTEL_PYTHON_ID_GENERATORUsed to specify which IDs Generator to use for the global Tracer Provider. By default, it
will use the random IDs generator.The code inprogram.pyneeds to use one of the packages for which there is
an OpenTelemetry integration. For a list of the available integrations please
checkhereOTEL_PYTHON_DISABLED_INSTRUMENTATIONSIf set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations.
e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = “requests,django”Examplesopentelemetry-instrument --traces_exporter console flask run --port=3000The above command will pass--traces_exporterconsoleto the instrument command and--port=3000toflask run.opentelemetry-instrument --traces_exporter zipkin_json,otlp celery -A tasks worker --loglevel=infoThe 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=3000The above command will configure the global trace provider to use the Random IDs Generator, and then
pass--port=3000toflask run.ReferencesOpenTelemetry Project