Standard library / runtime/pprof

pprof.SetGoroutineLabels()

Set the calling goroutine’s labels from a context. Prefer Do for scoped restoration. This example checks the context value, not profile label extraction. Expected stdout: 'parse\n'.

Formal Syntax & Structure

go syntaxgo
func SetGoroutineLabels(ctx context.Context)

Parameters & Attributes

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.

Working Example

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