Skip to content

Commit a5ecfdb

Browse files
committed
fix: propagate trace context to Snapshot in new-model snapshot creation
Konflux-CI ADR 0061 requires the build PipelineRun's trace context be persisted onto the Snapshot so the delivery trace continues forward through integration and release. The old-model adapter does this explicitly. The new-model PrepareSnapshotForPipelineRun (ComponentGroup-based) never did, leaving Snapshots created via the new path without a pipelinerunSpanContext annotation and breaking the trace chain for every delivery that exercises ComponentGroup workflow. Mirror the existing old-model behavior with a verbatim copy of tekton.dev/pipelinerunSpanContext from the build PipelineRun to the Snapshot, and assert the propagation with a targeted unit test on PrepareSnapshotForPipelineRun. Assisted-by: Claude Code Signed-off-by: Josiah England <jengland@redhat.com>
1 parent 3db0d33 commit a5ecfdb

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

snapshot/create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/konflux-ci/integration-service/gitops"
3131
"github.com/konflux-ci/integration-service/helpers"
3232
"github.com/konflux-ci/integration-service/tekton"
33+
"github.com/konflux-ci/integration-service/tekton/consts"
3334
"github.com/konflux-ci/operator-toolkit/metadata"
3435
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
3536
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
@@ -62,6 +63,10 @@ func PrepareSnapshotForPipelineRun(ctx context.Context, adapterClient client.Cli
6263
prefixes := []string{gitops.BuildPipelineRunPrefix, gitops.TestLabelPrefix, gitops.CustomLabelPrefix, gitops.ReleaseLabelPrefix}
6364
gitops.CopySnapshotLabelsAndAnnotations(&componentGroup.ObjectMeta, snapshot, componentName, &pipelineRun.ObjectMeta, prefixes, false)
6465

66+
if tp, found := pipelineRun.Annotations[consts.SpanContextAnnotation]; found && tp != "" {
67+
snapshot.Annotations[consts.SpanContextAnnotation] = tp
68+
}
69+
6570
snapshot.Labels[gitops.BuildPipelineRunNameLabel] = pipelineRun.Name
6671
if pipelineRun.Status.CompletionTime != nil {
6772
snapshot.Labels[gitops.BuildPipelineRunFinishTimeLabel] = strconv.FormatInt(pipelineRun.Status.CompletionTime.Unix(), 10)

snapshot/create_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ var _ = Describe("Snapshot creation functions", Ordered, func() {
454454
Expect(label).To(Equal("pull_request"))
455455
})
456456

457+
It("propagates pipelinerunSpanContext annotation from the build PipelineRun to the Snapshot", func() {
458+
const carrier = `{"traceparent":"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"}`
459+
buildPipelineRun.Annotations[tektonconsts.SpanContextAnnotation] = carrier
460+
defer delete(buildPipelineRun.Annotations, tektonconsts.SpanContextAnnotation)
461+
462+
snapshot, err := PrepareSnapshotForPipelineRun(ctx, k8sClient, buildPipelineRun, componentName, hasCompGroup)
463+
Expect(err).ToNot(HaveOccurred())
464+
Expect(snapshot).ToNot(BeNil())
465+
Expect(snapshot.GetAnnotations()[tektonconsts.SpanContextAnnotation]).To(Equal(carrier))
466+
})
467+
457468
It("ensures non-pipelines as code labels and annotations are NOT propagated to the snapshot", func() {
458469
snapshot, err := PrepareSnapshotForPipelineRun(ctx, k8sClient, buildPipelineRun, componentName, hasCompGroup)
459470
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)