Skip to content

fix: Add automatic tracing to CLI subcommands#3866

Merged
ss1909 merged 2 commits intomainfrom
sneha/A-1168
May 1, 2026
Merged

fix: Add automatic tracing to CLI subcommands#3866
ss1909 merged 2 commits intomainfrom
sneha/A-1168

Conversation

@ss1909
Copy link
Copy Markdown
Contributor

@ss1909 ss1909 commented Apr 29, 2026

Description

When BUILDKITE_TRACING_BACKEND=opentelemetry is configured, the bootstrap process initialises a TracerProvider and creates spans for each job phase (artifact-upload, etc.). However, subcommands like buildkite-agent artifact upload run as separate OS processes and never initialised their own TracerProvider, so even though TRACEPARENT and BUILDKITE_TRACING_BACKEND were present in their environment, no spans were emitted. The executor's phase spans were not visible internally.

Context

https://linear.app/buildkite/issue/A-1168/add-automatic-tracing-to-cli-subcommands-artifact-upload-pipeline

Changes

  • internal/job/tracing.go — extracted InitOTelTracerProvider as a standalone exported function; startTracingOpenTelemetry now delegates to it

  • clicommand/global.go — setupLoggerAndConfig now initialises a TracerProvider and extracts TRACEPARENT/TRACESTATE into context when running as a subprocess of a traced job

Every subcommand (artifact upload, pipeline upload, etc.) gets tracing for free.

  • ctx, span := otel.Tracer("buildkite-agent").Start(ctx, "<sub-command-name>")
    create a new span named after the sub-command-name. Because ctx already has the parent trace context extracted from TRACEPARENT, OTel automatically makes this span a child of the executor's span.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Grafana screenshots:
image
image

Disclosures / Credits

Implementation was carried out in consultation with Claude

@ss1909 ss1909 marked this pull request as ready for review April 29, 2026 02:40
@ss1909 ss1909 requested review from a team as code owners April 29, 2026 02:40
@ss1909 ss1909 force-pushed the sneha/A-1168 branch 3 times, most recently from 1196543 to 4184b9c Compare April 30, 2026 10:02
@zhming0 zhming0 self-requested a review May 1, 2026 00:46
Comment thread internal/job/tracing.go Outdated
Copy link
Copy Markdown
Contributor

@buildkate buildkate left a comment

Choose a reason for hiding this comment

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

small nit in comments, but otherwise approved

Co-authored-by: Kate Sy <kate.sy@buildkite.com>
@ss1909 ss1909 merged commit 7c6fdaa into main May 1, 2026
3 checks passed
@ss1909 ss1909 deleted the sneha/A-1168 branch May 1, 2026 03:21
@buildkate buildkate mentioned this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants