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_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_PROFILING_ENABLED
OTEL_PROFILING_EXPORTER (otlp or pprof)
OTEL_PROFILING_SAMPLE_INTERVAL
OTEL_PROFILING_EXPORT_INTERVAL
OTEL_PROFILING_MAX_FRAMES
OTEL_PROFILING_INCLUDE_TRACE_CONTEXT
OTEL_PROFILING_EXCEPTION_ENABLED
OTEL_PROFILING_EXCEPTION_SAMPLING_INTERVAL
OTEL_PROFILING_EXCEPTION_COLLECT_MESSAGE
OTEL_PROFILING_LOCK_ENABLED
OTEL_PROFILING_MEMORY_ENABLED
OTEL_PROFILING_MEMORY_INTERVAL
OTEL_PROFILING_MEMORY_TOP_STATS
OTEL_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_PROFILING_PPROF_PATH
OTEL_PROFILING_PPROF_UPLOAD_URL
OTEL_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_PROFILING_ENABLED=true export OTEL_PROFILING_EXCEPTION_ENABLED=true export OTEL_PROFILING_LOCK_ENABLED=true export OTEL_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_PROFILING_EXPORTER=pprof export OTEL_PROFILING_PPROF_PATH=/tmp/otel-profile
To POST pprof directly to a compatible agent endpoint and keep a local copy:
export OTEL_PROFILING_PPROF_UPLOAD_URL=http://localhost:9529/profiling/v1/input export OTEL_PROFILING_PPROF_HEADERS="X-API-Key:xxx" opentelemetry-instrument python app.py
When OTEL_PROFILING_EXPORTER is unset and OTEL_PROFILING_PPROF_UPLOAD_URL is configured, the runtime defaults to a legacy-compatible pprof upload layout. Set OTEL_PROFILING_EXPORTER=otlp to force OTLP profile export.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opentelemetry_sdk_extension_profiling-0.63b4.tar.gz.
File metadata
- Download URL: opentelemetry_sdk_extension_profiling-0.63b4.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4507907eb3b90d04dfada66c81f07d313cf7c5890b64593678adc33d00d06bfe
|
|
| MD5 |
be0ac48cc03317348979994757a0999d
|
|
| BLAKE2b-256 |
b6b3f36ac1db7c4c2393521ec97bddc2738a2744cbac4afb5053466f9558382a
|
File details
Details for the file opentelemetry_sdk_extension_profiling-0.63b4-py3-none-any.whl.
File metadata
- Download URL: opentelemetry_sdk_extension_profiling-0.63b4-py3-none-any.whl
- Upload date:
- Size: 39.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f3f59b3dd86a5c4a6f39e474845251ca47dc76bd29a01deceee8e818093b29a
|
|
| MD5 |
c7bbe5c5cf16c370af37a5206993a12c
|
|
| BLAKE2b-256 |
19744643d24fc6f41c98dea02f81259fc6027f98f0dd4a6d5b343c8a75e2b45b
|