Skip to content

Conversation

greeshma1196
Copy link
Collaborator

@greeshma1196 greeshma1196 commented Sep 10, 2025

  • added trace_id to groutine context
  • passed the goroutine context to internal context sturct for propagration

Updates: #3596

@greeshma1196 greeshma1196 added tracing tracing or opentracing related issue minor no risk changes, for example new filters labels Sep 10, 2025
proxy/proxy.go Outdated
Comment on lines 1646 to 1658
traceID := tracing.GetTraceID(span)

gCtx := stdlibcontext.Background()

defer pprof.SetGoroutineLabels(gCtx)
labels := pprof.Labels("trace_id", traceID)
gCtx = pprof.WithLabels(gCtx, labels)
pprof.SetGoroutineLabels(gCtx)

ctx.goCtx = &gCtx

traceIDCtx, _ := pprof.Label(gCtx, "trace_id")
ctx.Logger().Debugf("trace id in goroutine context: %s", traceIDCtx)
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to store ctx.goCtx, i.e. just do:

labels := pprof.Labels("trace_id", tracing.GetTraceID(span))
pprof.SetGoroutineLabels(pprof.WithLabels(stdlibcontext.Background(), labels))
defer pprof.SetGoroutineLabels(stdlibcontext.Background())

From https://pkg.go.dev/runtime/pprof#SetGoroutineLabels we read

SetGoroutineLabels sets the current goroutine's labels to match ctx. A new goroutine inherits the labels of the goroutine that created it.

So to test this we can create a testproxy with a mock tracer and a test filter that spawns a goroutine and verifies it can obtain trace_id via https://pkg.go.dev/runtime/pprof#Label. See TestFilterPanic for how to create and register a test filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor no risk changes, for example new filters tracing tracing or opentracing related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants