1. How span profiles work #
The profile of a single request.
Why #
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-goimport 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.jar3. 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:4040In 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.