Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install pyroscope@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin pyroscope v1.0.0 follows the Agent Plugins spec.
gh skills-hub install pyroscope Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/pyroscope/ Extract the ZIP to .github/skills/ in your repo. The folder name must match pyroscope for Copilot to auto-discover it.
Skill Files (3)
SKILL.md 4.6 KB
---
name: pyroscope
license: Apache-2.0
description: Continuously profile applications with Grafana Pyroscope and read the result as flame graphs. Covers three instrumentation paths — language SDK push (Go / Java / Python / Ruby / Node / .NET / Rust), Alloy eBPF auto-instrumentation (no code change, requires kernel 5.8+ with BTF), and SDK → Alloy receiver — plus ProfileQL queries, profile types (CPU / memory / allocations / goroutines / mutex), Grafana Cloud Profiles endpoint, and Span Profiles trace-to-profile linking. Use when adding profiling to a service, deploying Alloy as a cluster-wide eBPF profiler, hunting CPU / memory hotspots from a flame graph, comparing two profiles to find a regression, or correlating a slow Tempo trace to its profile — even when the user says "find what's burning CPU", "flame graph this app", "continuous profiling", "heap hotspots", or "why is allocation so high" without naming Pyroscope.
---
# Grafana Pyroscope
> **Docs**: https://grafana.com/docs/pyroscope/latest/
Continuous profiling — flame graphs of CPU, memory, allocations, mutex contention, goroutines.
## Prerequisites
- Pyroscope server (OSS) or Grafana Cloud Profiles endpoint
- For Cloud: numeric Pyroscope user (stack id) + API key
- For eBPF via Alloy: root + host PID + Linux ≥ 5.8 with BTF (or RHEL 4.18+)
## Instrumentation paths
1. **Alloy eBPF** (preferred) — auto-instrument, no code change
2. **SDK direct push** — application calls Pyroscope API
3. **SDK → Alloy** — SDK posts to `pyroscope.receive_http`, Alloy forwards
## Common Workflows
### 1. Instrument an app with the SDK (representative: Python)
```bash
pip install pyroscope-io==1.0.11
```
```python
import pyroscope, os
pyroscope.configure(
application_name="my.python.app",
server_address="http://pyroscope:4040",
sample_rate=100, oncpu=True,
tags={"region": os.getenv("REGION"), "env": "prod"},
)
# Dynamic tag for a hot path
with pyroscope.tag_wrapper({"controller": "slow_controller"}):
slow_code()
```
```bash
# Verify the app is pushing — Pyroscope ingests samples in a few seconds
curl -s http://pyroscope:4040/ready # → "ready"
curl -s http://pyroscope:4040/api/v1/labels | jq '.data | index("service_name")' # → not null
# Verify the service shows up in Grafana → Explore → Profiles → service dropdown.
```
Other SDKs (Java agent, Node, Ruby, .NET, Rust) + Cloud auth + tunable env vars: [`references/sdks.md`](references/sdks.md).
### 2. Cluster-wide eBPF profiling with Alloy
```alloy
# config.alloy — full block in references/ebpf-and-query.md
pyroscope.ebpf "local_pods" {
forward_to = [pyroscope.write.cloud.receiver]
targets = discovery.relabel.local_pods.output
sample_rate = 97
collect_interval = "15s"
}
pyroscope.write "cloud" {
endpoint {
url = "https://profiles-prod-xxx.grafana.net"
basic_auth { username = sys.env("PYROSCOPE_USER")
password = sys.env("GRAFANA_API_KEY") }
}
}
```
```bash
# 1. Reload Alloy
curl -X POST http://localhost:12345/-/reload
# 2. Verify the eBPF component is healthy
curl -s http://localhost:12345/api/v0/web/components \
| jq '.[] | select(.id|contains("pyroscope.ebpf")) | {id,health:.health.state}'
# Expect: health.state == "healthy"
# 3. Verify profiles arriving in Pyroscope
# Grafana → Explore → Profiles datasource → query:
# {namespace="default", __profile_type__="process_cpu:cpu:nanoseconds:cpu:nanoseconds"}
# Expect flame graph to render with frames from the target pods.
```
### 3. Query with ProfileQL
```
{service_name="myapp", env="prod",
__profile_type__="process_cpu:cpu:nanoseconds:cpu:nanoseconds"}
```
Profile-type list + full ProfileQL grammar: [`references/ebpf-and-query.md`](references/ebpf-and-query.md).
## Troubleshooting
- SDK starts but no flame graph → check the app actually called `start()` / `configure()` (some SDKs are lazy); check `server_address` reachable from inside the container
- Alloy eBPF component `unhealthy` with BPF errors → kernel < 5.8 or BTF missing; `ls /sys/kernel/btf/vmlinux`
- Cloud push 401 → wrong `basic_auth_username` (must be the numeric stack id, not the slug)
- Profile shows up but with no frames → for Java, set `PYROSCOPE_FORMAT=jfr`; for Python on Alpine, ensure `procfs` and `glibc` compatibility
## Resources
- [Pyroscope docs](https://grafana.com/docs/pyroscope/latest/)
- [Grafana Cloud Profiles](https://grafana.com/docs/grafana-cloud/monitor-applications/profiles/)
- [`references/sdks.md`](references/sdks.md) — Java/Node/Ruby/.NET/Rust install + config + env-var table + profile-type matrix
- [`references/ebpf-and-query.md`](references/ebpf-and-query.md) — full Alloy eBPF pipeline + ProfileQL
ebpf-and-query.md 1.7 KB
# Alloy eBPF pipeline + ProfileQL
## Alloy eBPF auto-instrumentation
No code changes. Supports: C/C++, Go, Rust, Java (Hotspot), Python, Ruby, Node.js, PHP, .NET, V8.
Requirements: Alloy as root, host PID namespace, Linux 5.8+ with BTF (or RHEL 4.18+).
```alloy
discovery.kubernetes "all_pods" {
role = "pod"
selectors { field = "spec.nodeName=" + sys.env("HOSTNAME") }
}
discovery.relabel "local_pods" {
targets = discovery.kubernetes.all_pods.targets
rule {
source_labels = ["__meta_kubernetes_namespace"]
target_label = "namespace"
}
}
pyroscope.ebpf "local_pods" {
forward_to = [pyroscope.write.cloud.receiver]
targets = discovery.relabel.local_pods.output
sample_rate = 97 // samples per second
collect_interval = "15s"
}
pyroscope.write "cloud" {
endpoint {
url = "https://profiles-prod-xxx.grafana.net"
basic_auth {
username = sys.env("PYROSCOPE_USER")
password = sys.env("GRAFANA_API_KEY")
}
}
}
```
## ProfileQL
```
# All CPU profiles for a service
{service_name="myapp", __profile_type__="process_cpu:cpu:nanoseconds:cpu:nanoseconds"}
# Filter by label
{service_name="myapp", env="prod"}
```
Profile type format: `<type>:<value_type>:<value_unit>:<span_name>:<span_unit>`.
Common types:
- `process_cpu:cpu:nanoseconds:cpu:nanoseconds` — CPU time
- `memory:inuse_space:bytes:space:bytes` — Heap in-use
- `memory:alloc_space:bytes:space:bytes` — Heap allocations
- `goroutine:goroutine:count::` — Goroutine count (Go)
- `mutex:contentions:count::` — Mutex contentions
## Server `/ready` endpoint
The Pyroscope server exposes `/ready` (HTTP 200) and a `/api/v1/labels` endpoint for verification.
sdks.md 4.1 KB
# Pyroscope SDKs by language
Each SDK pushes profiles to `server_address`. For Grafana Cloud Profiles, use the basic-auth form with the Pyroscope user (numeric stack id) + a Grafana Cloud API key.
## Python
```bash
pip install pyroscope-io==1.0.11
```
```python
import pyroscope, os
pyroscope.configure(
application_name="my.python.app",
server_address="http://pyroscope:4040",
sample_rate=100, oncpu=True,
tags={"region": os.getenv("REGION"), "env": "prod"},
)
with pyroscope.tag_wrapper({"controller": "slow_controller"}):
slow_code()
```
Grafana Cloud:
```python
pyroscope.configure(
application_name="my.python.app",
server_address="https://profiles-prod-xxx.grafana.net",
basic_auth_username="123456",
basic_auth_password=os.getenv("GRAFANA_API_KEY"),
)
```
## Java
```xml
<!-- Maven -->
<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>agent</artifactId>
<version>2.1.2</version>
</dependency>
```
```java
PyroscopeAgent.start(
new Config.Builder()
.setApplicationName("my-java-app")
.setProfilingEvent(EventType.ITIMER)
.setFormat(Format.JFR)
.setServerAddress("http://pyroscope:4040")
.build()
);
Pyroscope.LabelsWrapper.run(new LabelsSet("controller", "slow_controller"), () -> {
slowCode();
});
```
Or Java agent (no code change):
```bash
export PYROSCOPE_APPLICATION_NAME=my.java.app
export PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
java -javaagent:pyroscope.jar -jar app.jar
```
| Env var | Description | Default |
|---------|-------------|---------|
| `PYROSCOPE_FORMAT` | `jfr` for multiple events | `collapsed` |
| `PYROSCOPE_PROFILER_EVENT` | `itimer`, `cpu`, `wall` | `itimer` |
| `PYROSCOPE_PROFILER_ALLOC` | Allocation bytes threshold; `0` = all | disabled |
| `PYROSCOPE_PROFILER_LOCK` | Lock contention threshold (ns) | disabled |
| `PYROSCOPE_UPLOAD_INTERVAL` | Upload frequency | `10s` |
## Node.js
```bash
npm install @pyroscope/nodejs
```
```javascript
const Pyroscope = require('@pyroscope/nodejs');
Pyroscope.init({
serverAddress: 'http://pyroscope:4040',
appName: 'my-node-service',
tags: { region: process.env.REGION },
basicAuthUser: process.env.PYROSCOPE_USER,
basicAuthPassword: process.env.PYROSCOPE_PASSWORD,
flushIntervalMs: 60000,
});
Pyroscope.start();
Pyroscope.wrapWithLabels({ vehicle: 'bike' }, () => slowCode());
```
## Ruby
```bash
bundle add pyroscope
```
```ruby
require 'pyroscope'
Pyroscope.configure do |config|
config.application_name = "my.ruby.app"
config.server_address = "http://pyroscope:4040"
config.tags = { hostname: ENV["HOSTNAME"] }
end
Pyroscope.tag_wrapper({ controller: "slow_controller" }) { slow_code }
```
## .NET (Linux amd64, .NET 6+)
```bash
export PYROSCOPE_APPLICATION_NAME=my.dotnet.app
export PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
export PYROSCOPE_PROFILING_ENABLED=1
export CORECLR_ENABLE_PROFILING=1
export CORECLR_PROFILER={BD1A650D-AC5D-4896-B64F-D6FA25D6B26A}
export CORECLR_PROFILER_PATH=/dotnet/Pyroscope.Profiler.Native.so
export LD_PRELOAD=/dotnet/Pyroscope.Linux.ApiWrapper.x64.so
```
```csharp
var labels = Pyroscope.LabelSet.Empty.BuildUpon().Add("controller", "slow").Build();
Pyroscope.LabelsWrapper.Do(labels, () => SlowCode());
```
## Rust
```bash
cargo add pyroscope pyroscope_pprofrs
```
```rust
let pprof_config = PprofConfig::new().sample_rate(100);
let agent = PyroscopeAgent::builder("http://pyroscope:4040", "my-rust-app")
.backend(pprof_backend(pprof_config))
.tags([("env", "prod"), ("region", "us-east")].to_vec())
.basic_auth(user, password)
.build()?;
let running = agent.start().unwrap();
// ...
let ready = running.stop().unwrap();
ready.shutdown();
```
## Profile types by language
| Language | CPU | Memory | Goroutines | Allocations |
|----------|-----|--------|------------|-------------|
| Go | ✓ | ✓ | ✓ | ✓ |
| Java | ✓ | ✓ | ✓ | ✓ |
| Python | ✓ | - | - | - |
| Node.js | ✓ | ✓ | - | ✓ |
| Ruby | ✓ | ✓ | - | - |
| .NET | ✓ | ✓ | - | ✓ |
| Rust | ✓ | - | - | - |
| eBPF | ✓ | - | - | - |
Valid tag chars: `[a-zA-Z_][a-zA-Z0-9_]*` — periods NOT allowed.
License (Apache-2.0)
View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/grafana/skills/blob/main/LICENSE