Standard library / runtime/pprof

pprof.WithLabels()

Derive a context with labels merged into existing labels; later values replace matching keys. This alone does not set the goroutine labels. Expected stdout: 'b\n'.

Formal Syntax & Structure

go syntaxgo
func WithLabels(ctx context.Context, labels LabelSet) context.Context

Parameters & Attributes

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.
labelsLabelSetLabel set to associate with the context or operation.

Return Value

context.Context

Derived context carrying the merged labels.

Working Example

Example Snippetgo
package main
import (  "context"  "fmt"  "runtime/pprof")
func main() {  c := pprof.WithLabels(context.Background(), pprof.Labels("phase", "a"))  d := pprof.WithLabels(c, pprof.Labels("phase", "b"))  v, _ := pprof.Label(d, "phase")  fmt.Println(v)}
Go Reference