Skip to main content

OpenTelementry Python extensions written at Red Hat

Project description

redhat-opentelemetry-python-contrib

OpenTelemetry Python extensions written at Red Hat

This repository includes:

  • File exporters to export OpenTelemetry data to files when using auto-instrumentation
  • Script instrumentor - Auto instrumentation plugin for wrapping an entire python script run in a tracing span

Installation

pip install redhat-opentelemetry-python-contrib

Using the file exporters

The file exporters can be used by setting the OTEL_*_EXPORTER environment variables to file, or using the equivalent arguments to opentelemetry-instrument.

For example to export span data to a file for a particular Python script:

opentelemetry-instrument --traces_exporter file python myscript.py

The file to which the data will be written to can be customized using the environment variables listed below. Otherwise, the listed default value would be used:

Variable Used for Default value
OTEL_FILE_SPAN_EXPORTER_NAME Trace data otel_traces.log
OTEL_FILE_METRIC_EXPORTER_NAME Metrics otel_metrics.log
OTEL_FILE_LOG_EXPORTER_NAME Logs otel_logs.log

Using the script instrumentor

Once installed, the script instrumentor will automatically wrap any Python script invoked with auto instrumentation enabled in a span that would include the script name, command-line arguments and exit status.

The script instrumentor attempts to propagate the tracing context from the environment it was invoked in, by trying to read environment variables that are capitalized versions of the HTTP headers defined by the W3C Trace Context specification. This typically means that if the TRACEPARENT environment variable is defined in the environment the script runs in, the script span will become a child span of that trace. This is generally compatible with how other tools and systems handle things such as the Ansible OpenTelemetry callback plugin and the Jenkins OpenTelemetry plugin.

The script instrumentor can cause traces to look a bit strange for things that are not meant to be stand-alone Python scripts such as Django and Flask server processes. It can be disabled by setting the OTEL_PYTHON_DISABLED_INSTRUMENTATIONS environment variable:

export OTEL_PYTHON_DISABLED_INSTRUMENTATIONS="__main__"

Project details


Download files

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

Source Distribution

Built Distribution

File details

Details for the file redhat_opentelemetry_contrib-0.0.0.post6.dev0.tar.gz.

File metadata

File hashes

Hashes for redhat_opentelemetry_contrib-0.0.0.post6.dev0.tar.gz
Algorithm Hash digest
SHA256 cb2a59540d8a8c9e37ef64ec8e596b22512a0f445e49c10f54dec721415d7c11
MD5 620c1b62417f9ab4c5d8723e21d3e4ec
BLAKE2b-256 d0661741a4141624b372bba16a28ce7e7f2c0e37fc3da9c68a3b55294cfde0b5

See more details on using hashes here.

File details

Details for the file redhat_opentelemetry_contrib-0.0.0.post6.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for redhat_opentelemetry_contrib-0.0.0.post6.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac4169a721390e2cb3c881cdd3270093d7b8f3bc189525620f5c62adbb4c923b
MD5 7a0bba5e84a65da32d46b7e24f2cba43
BLAKE2b-256 e513bb60d5ad6cb4c26141f05cd217efd4df7fda6c7c4cedfad58222ec64b8df

See more details on using hashes here.

Supported by

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