RousselTMLEARNING

Observability

Linking traces and profiles: span profiles with Tempo and Pyroscope

Go from a slow trace to the exact CPU profile of that span: span profiles in Go and Java, configuring the Tempo data source (traces to profiles) and metrics → profiles links.

1. How span profiles work #

The profile of a single request.

Why #

Correlation between signals
Each jump takes one click in Grafana if the signals share their identifiers.

A trace shows that a span lasted 2 s, but not why. Span profiles attach the span identifier to the profile samples collected during its execution. From the trace, you open the flame graph of that span only.

Good to know: Only the « root » spans of a service (the first local span) are annotated, to limit overhead. The profile covers the process's CPU work during that span.

2. Instrumenting #

Go and Java.

Go #

go get github.com/grafana/otel-profiling-go
import otelpyroscope "github.com/grafana/otel-profiling-go"

tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
// Enveloppe le TracerProvider : chaque span racine reçoit un label de profil
otel.SetTracerProvider(otelpyroscope.NewTracerProvider(tp))

pyroscope.Start(pyroscope.Config{ApplicationName: "checkout", ServerAddress: "http://pyroscope:4040"})

Java #

With the OpenTelemetry Java agent, add the pyroscope-otel extension in addition to the Pyroscope agent:

java -javaagent:opentelemetry-javaagent.jar \
     -Dotel.javaagent.extensions=pyroscope-otel.jar \
     -Dpyroscope.application.name=orders \
     -Dpyroscope.server.address=http://pyroscope:4040 \
     -jar orders.jar

3. Configuring Grafana #

The link between data sources.

Tempo data source #

# provisioning/datasources/tempo.yaml
apiVersion: 1
datasources:
  - name: Tempo
    type: tempo
    uid: tempo
    url: http://tempo:3200
    jsonData:
      tracesToProfiles:
        datasourceUid: pyroscope
        profileTypeId: process_cpu:cpu:nanoseconds:cpu:nanoseconds
        tags: [{ key: service.name, value: service_name }]
  - name: Pyroscope
    type: grafana-pyroscope-datasource
    uid: pyroscope
    url: http://pyroscope:4040

In a trace view, a Profiles for this span button appears on annotated spans.

Good practice: Use the same service_name in traces, metrics, logs and profiles: it is the key to any correlation in Grafana.

Related articles

Continuous profiling with Grafana Pyroscope: why and how

The fourth signal of observability: what continuous profiling is, profile types (CPU, memory, locks), reading…

Grafana Pyroscope architecture and deployment

Pyroscope components (distributor, ingester, querier, store-gateway, compactor), object storage, monolithic a…

Instrumenting applications for Pyroscope: SDKs, Alloy and eBPF

Send profiles to Pyroscope from Go, Java, Python and Node.js with the SDKs, collect pprof endpoints with Allo…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!