tektoncd/pipeline

feat(tracing): correlate Kubernetes events with distributed traces

Open

#9,784 opened on Apr 16, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Go (1,943 forks)auto 404
good first issuekind/feature

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 from recorder.Event() to recorder.AnnotatedEventf() with traceparent/tracestate extracted from ctx
  • Add span.AddEvent("K8sEvent:<type>") at each emission point

Call sites (context already carries span):

  • pkg/reconciler/pipelinerun/pipelinerun.go:230,348
  • pkg/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.

Contributor guide