Skip to content

[A-1511] Add OTel spans for repo-checkout git operations with --trace-git-checkout flag#4098

Open
isaacsu wants to merge 5 commits into
mainfrom
isaacsu/instrument-git-cp
Open

[A-1511] Add OTel spans for repo-checkout git operations with --trace-git-checkout flag#4098
isaacsu wants to merge 5 commits into
mainfrom
isaacsu/instrument-git-cp

Conversation

@isaacsu

@isaacsu isaacsu commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

New experimental feature that emits additional git.* OpenTelemetry spans when the agent is started with --trace-git-checkout.

This will allow customers to see what goes on behind the "Preparing working directory" / repo-checkout span and figure out ways to speed up the checkout phase of their jobs.

Spans added

Span Description
repo-checkout (existing) Added attempt counter; git.* builds off its child context
git.mirror.update main repo getOrUpdateMirrorDir
git.mirror.lock_wait.clone mirror clonelock
git.mirror.clone mirror gitClone
git.mirror.lock_wait.update mirror updatelock
git.mirror.fetch mirror gitFetch
git.mirror.snapshot snapshot gitClone
git.dissociate main repo gitRepack if GitMirrorCheckoutMode is dissociate
git.clone main repo gitClone
git.clean.pre main repo gitCleanSubmodules and gitClean
git.lfs.install git lfs install
git.fetch main repo fetchSource
git.verify_commit main repo verifyCommit
git.sparse_checkout setupSparseCheckout
git.checkout main repo gitCheckout
git.submodules main repo updateGitSubmodules
(for each submodule)
   └ git.mirror.update submodule getOrUpdateMirrorDir (see git.mirror.update above)
   └ git.submodule.update git submodule update
git.lfs.fetch main repo gitLFSFetchCheckout
git.clean.post main repo gitClean and gitCleanSubmodules

Screenshot

Screenshot 2026-07-24 at 9 11 46 am

Changes

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 .)

Disclosures / Credits

While this PR was produced with the help of advanced automation tools, I take full credit and responsibility for it.

@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch from 1ba8dbb to 6578fd5 Compare July 20, 2026 05:09
@isaacsu
isaacsu changed the base branch from main to isaacsu/redact-url-credentials July 20, 2026 05:09
@isaacsu
isaacsu force-pushed the isaacsu/redact-url-credentials branch from aff0469 to c19c2e4 Compare July 21, 2026 01:01
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch from 6578fd5 to 01e4b00 Compare July 21, 2026 01:41
Base automatically changed from isaacsu/redact-url-credentials to main July 21, 2026 06:00
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch 4 times, most recently from fa62ad8 to 2223a68 Compare July 22, 2026 23:11
Add opt-in per-operation git.* child spans (and a handful of attributes)
inside the default checkout so a trace shows a waterfall, making the slow
step obvious. Gated behind --trace-git-checkout / BUILDKITE_TRACE_GIT_CHECKOUT
(default off) so the added span volume is only paid by agents that ask for it.

This is pure instrumentation — no git commands, retry policy, or checkout
behaviour change. Adapted to the multi-file checkout refactor: spans live in
the files owning each operation (checkout.go, checkout_fetch.go,
checkout_mirror.go).
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch 2 times, most recently from 6c0a7d7 to e7fdf5c Compare July 23, 2026 07:07
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch from e7fdf5c to 6a85428 Compare July 23, 2026 07:14
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch from d45acc4 to 6999f72 Compare July 24, 2026 01:55
@isaacsu
isaacsu force-pushed the isaacsu/instrument-git-cp branch from 6999f72 to a7d8017 Compare July 24, 2026 02:09
@isaacsu isaacsu changed the title Isaacsu/instrument git cp [A-1511] Add OTel spans for repo-checkout git operations with --trace-git-checkout flag Jul 24, 2026
@isaacsu isaacsu added the feature New user-facing feature! label Jul 24, 2026
@isaacsu
isaacsu requested a review from buildsworth-bk July 24, 2026 02:20
buildsworth-bk-app[bot]

This comment was marked as resolved.

@buildsworth-bk-app
buildsworth-bk-app Bot removed the request for review from buildsworth-bk July 24, 2026 02:33
@isaacsu
isaacsu marked this pull request as ready for review July 24, 2026 02:47
@isaacsu
isaacsu requested review from a team as code owners July 24, 2026 02:47
buildsworth-bk-app[bot]

This comment was marked as resolved.

@zhming0 zhming0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More Otel span the better 🙌🏿 , but I wonder if we can make them less invasive in our code, perhaps we can start by thinking if the flag is worth it.

Comment thread clicommand/global.go Outdated
Comment on lines +315 to +319
TraceGitCheckoutFlag = cli.BoolFlag{
Name: "trace-git-checkout",
Usage: "Emit per-operation git.* child spans inside the checkout phase so a trace shows a waterfall of the individual git operations. Only takes effect when tracing is enabled (default: false)",
EnvVar: "BUILDKITE_TRACE_GIT_CHECKOUT",
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, what is the rationale behind adding a CLI flag as the toggle? I think it's a matter of 10 spans per job?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Once we add a CLI flag it becomes a product surface that we will to support forever.

Comment thread internal/job/tracing.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These abstractions aren't ideal. Nothing in traceGitOp is about git, they seem mostly do a feature flag check + typical Otel ceremony.

If this is sole place where we check the flag I think it'd be reasonable but I think we have various other places checking the flag, which makes these questionable.

@buildsworth-bk-app buildsworth-bk-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I didn't find a concrete defect in the latest revision. Making the git.* spans automatic for either tracing backend across the default checkout path is cross-cutting enough to warrant a human sanity-check.

Want to dig deeper?

Paste this into your agent to explore the findings from this review's Buildkite build:

Download the buildsworth logs from build 8013, then answer my questions about the findings.

Install the reading-buildsworth-logs skill to run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New user-facing feature!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants