otel-profiling
Continuous in-process CPU and wall-clock profiler for Python that exports OpenTelemetry profiles over OTLP.
It samples the stacks of every running thread with CPython's built-in remote debugging API (the same one behind
python -m profiling.sampling), so it needs no extra privileges (no SYS_PTRACE, no eBPF) and no native
dependencies. It runs inside your process, which makes it a fit for environments where you can't deploy a
profiling agent or a privileged sidecar.
Status: experimental. The OTLP profiles signal is still
v1development, and the CPython API used for sampling is private (_remote_debugging). Expect breaking changes between Python minor versions.
Requirements
- Python 3.15+
- A backend that accepts OTLP profiles over HTTP/protobuf (e.g. the OpenTelemetry Collector with the profiles feature gate, OpenObserve, Grafana Pyroscope)
Installation
pip install otel-profiling
Usage
The package registers an opentelemetry_instrumentor entry point, so with zero-code instrumentation it is picked up
automatically:
export OTEL_PROFILES_EXPORTER=otlp
opentelemetry-instrument python app.py
Or enable it manually, after configuring your tracer provider:
from otel_profiling import ProfilingInstrumentor
ProfilingInstrumentor().instrument()
The profiler only starts when OTEL_PROFILES_EXPORTER=otlp, so it is safe to call instrument() unconditionally.
Profiles carry the resource of the tracer provider (service.name, service.instance.id, ...), so they line up
with your traces in the backend.
Keyword arguments
Arguments passed to instrument() take precedence over environment variables.
| Argument | Default |
|---|---|
tracer_provider |
The global tracer provider (its resource is attached to the profiles) |
endpoint |
OTEL_EXPORTER_OTLP_PROFILES_ENDPOINT, or OTEL_EXPORTER_OTLP_ENDPOINT + /v1/profiles |
headers |
OTEL_EXPORTER_OTLP_PROFILES_HEADERS, or OTEL_EXPORTER_OTLP_HEADERS |
sample_interval_millis |
OTEL_PYTHON_PROFILING_SAMPLE_INTERVAL, or 10 |
export_interval_millis |
OTEL_PYTHON_PROFILING_EXPORT_INTERVAL, or 10000 |
profile_types |
OTEL_PYTHON_PROFILING_TYPES, or ("cpu", "wall") |
Environment variables
| Variable | Default | Description |
|---|---|---|
OTEL_PROFILES_EXPORTER |
— | Set to otlp to enable the profiler |
OTEL_EXPORTER_OTLP_PROFILES_ENDPOINT |
OTEL_EXPORTER_OTLP_ENDPOINT + /v1/profiles |
Full URL profiles are sent to |
OTEL_EXPORTER_OTLP_PROFILES_HEADERS |
OTEL_EXPORTER_OTLP_HEADERS |
Export headers, as key=value pairs separated by commas |
OTEL_PYTHON_PROFILING_SAMPLE_INTERVAL |
10 |
Milliseconds between stack samples |
OTEL_PYTHON_PROFILING_EXPORT_INTERVAL |
10000 |
Milliseconds between exports |
OTEL_PYTHON_PROFILING_TYPES |
cpu,wall |
Comma-separated profile types to collect (see below) |
Profile types
| Type | Samples | Use it to find |
|---|---|---|
cpu |
Threads running Python code or native code on CPU | Hot code paths burning CPU |
wall |
Every thread with a Python stack, including those blocked on I/O, locks or sleep |
Where requests spend time waiting (HTTP calls, database, LLM APIs) |
Both come from the same stack sample, so enabling both costs no extra sampling. Each export carries one profile per enabled type, sharing the same dictionary.
How it works
- A daemon thread reads the stacks of all threads every sample interval. Every thread counts towards
wall; only threads running on CPU, holding the GIL or waiting for it count towardscpu. The sampler itself holds the GIL while sampling, so a busy Python thread shows up as waiting for the GIL and is still counted as CPU. - Samples are aggregated per stack and sent every export interval as an
ExportProfilesServiceRequest(cpu/wallinnanoseconds, each sample weighted by the sampling period). - After
fork()(e.g. Gunicorn workers,multiprocessing) the profiler restarts in the child, and the last window is flushed at interpreter exit.
Limitations
- Samples are not linked to spans yet (
trace_id/span_id). - asyncio tasks are not unwound individually: the stacks are per thread, so suspended tasks don't show up in either profile; only the task running at sample time does.
- A thread genuinely contending for the GIL also counts as
cpu. - Only HTTP/protobuf export is supported (no gRPC).
Metadata
Release files for otel-profiling 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| otel_profiling-0.1.0.tar.gz | 8.2 kB | With provenance | Details for otel_profiling-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| otel_profiling-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for otel_profiling-0.1.0-py3-none-any.whl |
Total release size: 17.6 kB
Release files / otel_profiling-0.1.0.tar.gz
| Download URL | otel_profiling-0.1.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b969cb6bc85a110357093915a1638731a7fbb3f8f3eb7151e6c06136c822b09
|
|
BLAKE2b-256 checksum How to use checksums |
b82e974cded71e54d5e0e711448a6fbd9f6f63b8c7fc499f8504bbc4cf2172f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / otel_profiling-0.1.0-py3-none-any.whl
| Download URL | otel_profiling-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d85ab740e1b0057266e78b9f954df3570d402172893241e27f3a7de61fc52002
|
|
BLAKE2b-256 checksum How to use checksums |
1f87b99cc9dd1e18d4a372044fbc9cb7dfd53635eb322bb86a605d876931d292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for otel-profiling 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for otel_profiling-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.