feat(tracing): correlate Kubernetes events with distributed traces
#9,784 opened on Apr 16, 2026
Repository metrics
- Stars
- (9,013 stars)
- PR merge metrics
- (PR metrics pending)
Description
Feature request
Inject trace context (traceparent/tracestate) into Kubernetes events emitted by the TaskRun and PipelineRun reconcilers, enabling correlation between K8s events and distributed traces.
Use case
When debugging a failed PipelineRun, operators see K8s events (Started, Succeeded, Failed) and distributed traces separately. Correlating them requires manual timestamp matching. Adding traceparent to event annotations enables one-click navigation from event to trace in observability backends.
Implementation hints
Primary change — pkg/reconciler/events/k8sevent/event.go:
EmitK8sEvents()— switch fromrecorder.Event()torecorder.AnnotatedEventf()with traceparent/tracestate extracted fromctx- Add
span.AddEvent("K8sEvent:<type>")at each emission point
Call sites (context already carries span):
pkg/reconciler/pipelinerun/pipelinerun.go:230,348pkg/reconciler/taskrun/taskrun.go:152,429
Extract trace context:
sc := trace.SpanFromContext(ctx).SpanContext()
annotations := map[string]string{
"traceparent": fmt.Sprintf("00-%s-%s-01", sc.TraceID(), sc.SpanID()),
}
recorder.AnnotatedEventf(object, annotations, corev1.EventTypeNormal, reason, msgFmt, args...)
Part of umbrella: #9701
good first issue — surgical change, single file, clear pattern.