Skip to content
otel

otel

Pypi •[email protected] • November 24, 2026

Continuous CPU and wall-clock profiler for Python that exports OpenTelemetry (OTLP) profiles linked to traces

pip install otel-profiling==0.2.0

Continuous CPU and wall-clock profiler for Python that exports OpenTelemetry profiles over OTLP, with each sample linked to the active trace and span.

It samples the stacks of every 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 is started by your application itself, 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.

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.

Linux for the default process mode (other platforms fall back to thread mode, see Modes )

A backend that accepts OTLP profiles over HTTP/protobuf (e.g. the OpenTelemetry Collector with the profiles feature gate, OpenObserve, Grafana Pyroscope)

The package registers an opentelemetry_instrumentor entry point, so with zero-code instrumentation it is picked up automatically:

Or enable it manually, after configuring your tracer provider:

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 , ...), and every sample taken while a span is active carries its trace_id / span_id , so profiles line up with your traces in the backend.

Arguments passed to instrument() take precedence over environment variables.

Environment variables

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.

process (default, Linux)

The instrumentor starts a small sampler process: a fresh interpreter in isolated mode ( python -I ), not a fork of your application , so it doesn't copy its memory or run its auto-instrumentation. Your process allows that child to read its memory with prctl(PR_SET_PTRACER) , which needs no capability. The child samples your process, reads per-thread CPU time from /proc/ /task/ /schedstat , and exports the profiles itself. It exits when your process stops the profiler or dies.

Because it doesn't compete for your process' GIL, it sees short CPU bursts between I/O waits and asyncio task steps that an in-process sampler misses. It costs one extra process per instrumented process ( 35 MB RSS) and its own CPU for sampling.

If the child can't be started or can't read your process' memory (e.g. a seccomp profile blocking process_vm_readv ), the profiler logs a warning and falls back to thread mode.

Samples from a background thread inside your process. It works anywhere the remote debugging API does, but the sampler needs the GIL to run, so it can only sample when your threads release it (I/O or the 5 ms switch interval): CPU bursts shorter than that between I/O waits are under-represented or invisible, and a busy asyncio loop can starve the sampler entirely. Use it where process mode isn't available. On platforms without per-thread CPU clocks (e.g. macOS) only the wall profile is produced.

With an SDK tracer provider, the instrumentor registers a span processor that tracks the active span of each thread:

Threads: the innermost open span of each thread.

asyncio: the first span started in an event loop installs a task factory on that loop (chaining any existing one) that wraps new tasks, so each task step publishes the span of its own context while it runs.

Thread pools: concurrent.futures.ThreadPoolExecutor.submit is patched so submitted work runs linked to the span active where it was submitted. This covers loop.run_in_executor and asgiref's sync_to_async (Django).

In process mode the active spans are shared with the sampler through a table in shared memory. Only sampled spans are linked. Set OTEL_PYTHON_PROFILING_SPAN_LINKS=false to disable the span processor and the patches.

Every sample interval the sampler reads the stacks of all threads. Each thread adds the sampling period to wall and the CPU time it consumed since the sample to cpu , both under its current stack and span.

Samples are aggregated per stack and span and sent every export interval as an ExportProfilesServiceRequest ( cpu / wall in nanoseconds ).

After fork() (e.g. Gunicorn workers, multiprocessing ) the profiler restarts in the child, and the last window is flushed at interpreter exit.

process mode reads the target without pausing it, so some samples are torn (the stack changes while it is read) and dropped; code whose stack changes very fast may be slightly under-represented.

asyncio tasks created before the first span in a loop (e.g. the connection task of the very first request) are not wrapped, so their steps are only linked through spans started inside them.

Suspended asyncio tasks don't show up in either profile: stacks are per thread, so only the running task is seen.

Only HTTP/protobuf export is supported (no gRPC).

Release files for otel-profiling 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation .

Source distribution (sdist)

Built distribution (wheel)

Total release size: 35.7 kB

Release files / otel_profiling-0.2.0.tar.gz

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.

Release files / otel_profiling-0.2.0-py3-none-any.whl

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.

Security for otel-profiling 0.2.0

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.

Both files in this release have been uploaded with provenance metadata.

Attestation for otel_profiling-0.2.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.

Attestation for otel_profiling-0.2.0-py3-none-any.whl

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.

A 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.

Release history Release notifications | RSS feed

Nov 24, 2026 2 release files Full provenance

Nov 24, 2026 2 release files Full provenance