A library providing profiling functionalities related to OpenTelemetry
Maintained. Last release 5 months ago, commits in 5 of the last 26 weeks. Weaker on commit activity.
pip install pyroscope-otelSpan Profiles Support for OpenTelemetry in Python
This package links OpenTelemetry tracing data with Pyroscope continuous profiling data, enabling you to correlate traces with performance profiles.
Reference: https://grafana.com/docs/pyroscope/latest/configure-client/trace-span-profiles/
Prerequisites
- Your Python application is instrumented with Pyroscope profiler
- Your Python application is instrumented with OpenTelemetry
Installation
pip install pyroscope-otel
Pyroscope Configuration (Required)
Pyroscope must be configured before creating any spans. This is mandatory for all setups:
from pyroscope import configure as pyroscope_configure
# Local setup (default)
pyroscope_configure(
app_name="my-app",
server_address="http://localhost:4040",
sample_rate=100,
)
# Grafana Cloud setup (uncomment and update with your credentials)
# pyroscope_configure(
# app_name="my-app",
# server_address="https://pyroscope-blocks-prod-us-central-1.grafana-cloud.com/prom/push",
# auth_token="<your-grafana-cloud-token>",
# basic_auth_username="<your-username>", # Optional: username for basic auth (Grafana Cloud)
# basic_auth_password="<your-password>", # Optional: password for basic auth (Grafana Cloud)
# sample_rate=100,
# )
How It Works & Span Attributes
The PyroscopeSpanProcessor automatically attaches the profile identifier (pyroscope.profile.id) as an attribute to the root span of each trace. This creates a direct link between traces and their corresponding performance profiles in Grafana Tempo, allowing you to navigate from any trace to the exact performance profile data for that transaction.
On the profiling side, the processor adds these thread-level Pyroscope tags for the lifetime of the root span (child spans running on the same thread inherit them via the thread-local state):
span_id: the root span's ID (16 hex chars).span_name: the root span's name.trace_id: the trace ID (32 hex chars). Enables filtering profile samples by trace on the Pyroscope server.