Skip to main content

Profiling SDK extension for OpenTelemetry Python

Project description

This package provides a Python profiling runtime for OpenTelemetry auto-instrumentation. The current implementation exports profiles via OTLP and supports multiple collector types:

  • stack sampling

  • handled exceptions

  • threading and asyncio lock contention

  • threading and asyncio condition wait time

  • heap snapshots via tracemalloc

  • child-process restart after fork()

Installation

pip install opentelemetry-sdk-extension-profiling

or install it through the distro extra:

pip install opentelemetry-distro[profiling]

Usage

Enable profiling for applications launched via opentelemetry-instrument:

export OTEL_PYTHON_PROFILING_ENABLED=true
opentelemetry-instrument python app.py

Programmatic usage:

from opentelemetry.sdk.extension.profiling import Profiler

profiler = Profiler()
profiler.start()

Configuration

The following environment variables are supported:

  • OTEL_PYTHON_PROFILING_ENABLED

  • OTEL_PYTHON_PROFILING_EXPORTER (otlp or pprof)

  • OTEL_PYTHON_PROFILING_SAMPLE_INTERVAL

  • OTEL_PYTHON_PROFILING_EXPORT_INTERVAL

  • OTEL_PYTHON_PROFILING_MAX_FRAMES

  • OTEL_PYTHON_PROFILING_INCLUDE_TRACE_CONTEXT

  • OTEL_PYTHON_PROFILING_EXCEPTION_ENABLED

  • OTEL_PYTHON_PROFILING_EXCEPTION_SAMPLING_INTERVAL

  • OTEL_PYTHON_PROFILING_EXCEPTION_COLLECT_MESSAGE

  • OTEL_PYTHON_PROFILING_LOCK_ENABLED

  • OTEL_PYTHON_PROFILING_MEMORY_ENABLED

  • OTEL_PYTHON_PROFILING_MEMORY_INTERVAL

  • OTEL_PYTHON_PROFILING_MEMORY_TOP_STATS

  • OTEL_PYTHON_PROFILING_MEMORY_IGNORE_PROFILER

  • OTEL_EXPORTER_OTLP_PROFILES_PROTOCOL

  • OTEL_EXPORTER_OTLP_PROFILES_ENDPOINT

  • OTEL_EXPORTER_OTLP_PROFILES_HEADERS

  • OTEL_EXPORTER_OTLP_PROFILES_TIMEOUT

  • OTEL_EXPORTER_OTLP_PROFILES_COMPRESSION

  • OTEL_EXPORTER_OTLP_PROFILES_CERTIFICATE

  • OTEL_EXPORTER_OTLP_PROFILES_CLIENT_KEY

  • OTEL_EXPORTER_OTLP_PROFILES_CLIENT_CERTIFICATE

  • OTEL_PYTHON_PROFILING_PPROF_PATH

  • OTEL_PYTHON_PROFILING_PPROF_UPLOAD_URL

  • OTEL_PYTHON_PROFILING_PPROF_HEADERS

Service metadata should be configured with standard OpenTelemetry resource settings such as OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES.

Examples

Collect stack, exception, lock, and heap profiles and export them with OTLP/HTTP:

export OTEL_PYTHON_PROFILING_ENABLED=true
export OTEL_PYTHON_PROFILING_EXCEPTION_ENABLED=true
export OTEL_PYTHON_PROFILING_LOCK_ENABLED=true
export OTEL_PYTHON_PROFILING_MEMORY_ENABLED=true
export OTEL_EXPORTER_OTLP_PROFILES_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_PROFILES_ENDPOINT=http://localhost:4318/v1development/profiles
opentelemetry-instrument python app.py

To dump pprof files instead of OTLP, set:

export OTEL_PYTHON_PROFILING_EXPORTER=pprof
export OTEL_PYTHON_PROFILING_PPROF_PATH=/tmp/otel-profile

To POST pprof directly to a compatible agent endpoint and keep a local copy:

export OTEL_PYTHON_PROFILING_PPROF_UPLOAD_URL=http://localhost:9529/profiling/v1/input
export OTEL_PYTHON_PROFILING_PPROF_HEADERS="X-API-Key:xxx"
opentelemetry-instrument python app.py

When OTEL_PYTHON_PROFILING_EXPORTER is unset and OTEL_PYTHON_PROFILING_PPROF_UPLOAD_URL is configured, the runtime defaults to a legacy-compatible pprof upload layout. Set OTEL_PYTHON_PROFILING_EXPORTER=otlp to force OTLP profile export.

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

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

File details

Details for the file opentelemetry_sdk_extension_profiling-0.63b3.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_sdk_extension_profiling-0.63b3.tar.gz
Algorithm Hash digest
SHA256 132718a27783767aeff71ca352e831b60af62bdef000dde1fdd8d6139ce6171a
MD5 79f331cd8988b7a7610f18b0b1d283eb
BLAKE2b-256 325aacc938118db4b020c3caf153eeecfe783d6e53d8ab849e7ac64ca0db84e8

See more details on using hashes here.

File details

Details for the file opentelemetry_sdk_extension_profiling-0.63b3-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_sdk_extension_profiling-0.63b3-py3-none-any.whl
Algorithm Hash digest
SHA256 a631329922791e196174835e089a8fc67744f4518208fd67adb55fa4de4893cf
MD5 8f6e642dd1c26415b89d210ef73f5f69
BLAKE2b-256 c3b497c7c47dfaf5f58ce7765505b9cfde24d57d72de4bef9a67b40453ef5798

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