Skip to content

feat: add queue phase spans to build traces - #1286

Open
rahulsom wants to merge 2 commits into
jenkinsci:mainfrom
rahulsom:feat/queue-phase-spans
Open

feat: add queue phase spans to build traces#1286
rahulsom wants to merge 2 commits into
jenkinsci:mainfrom
rahulsom:feat/queue-phase-spans

Conversation

@rahulsom

@rahulsom rahulsom commented Apr 27, 2026

Copy link
Copy Markdown

Before this change, traces only covered build execution. Builds that spent time waiting in the Jenkins queue showed up with a root span whose start time matched execution start, hiding all queue latency.

This change attaches a QueueItemMonitoringAction to each queue item as it enters the WaitingItem state. The action tracks each state transition (Waiting → Blocked → Buildable) with timestamps and the reason/label for that state. When the build starts, MonitoringRunListener reads the completed phases and emits a child span per phase under the root BUILD span, using historical timestamps. The root span start time is extended back to when the item first entered the queue.

New spans:

  • Phase: Queue - Waiting (ci.pipeline.run.queue.reason, when applicable)
  • Phase: Queue - Blocked (ci.pipeline.run.queue.reason, jenkins.pipeline.step.agent.label)
  • Phase: Queue - Buildable (ci.pipeline.run.queue.reason, jenkins.pipeline.step.agent.label)

Testing done

Added tests.
Manually verified the spans are present.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@rahulsom
rahulsom force-pushed the feat/queue-phase-spans branch 2 times, most recently from 9244f61 to dd552c0 Compare May 2, 2026 23:29
@rahulsom
rahulsom marked this pull request as ready for review May 3, 2026 00:06
@rahulsom
rahulsom requested a review from a team as a code owner May 3, 2026 00:06
@rahulsom
rahulsom force-pushed the feat/queue-phase-spans branch 3 times, most recently from a9dfa89 to 0c91a40 Compare May 28, 2026 16:33
@rahulsom
rahulsom force-pushed the feat/queue-phase-spans branch from 0c91a40 to 1e5f26b Compare June 1, 2026 16:24
@rahulsom
rahulsom force-pushed the feat/queue-phase-spans branch from 1e5f26b to 2063e14 Compare June 9, 2026 19:28
rahulsom added 2 commits June 9, 2026 13:25
The cloudbees-disk-usage-simple plugin refreshes disk usage on a
background thread and persists cloudbees-disk-usage-simple.xml into
JENKINS_HOME when it finishes. When that write lands while
JenkinsRule.after() is deleting the temporary JENKINS_HOME, deletion
fails with DirectoryNotEmptyException ("These files still exist:
cloudbees-disk-usage-simple.xml") and the otherwise-passing test is
reported as a failure. The flake hits random integration tests and also
occurs on the main branch.

BaseIntegrationTest.afterEach() now forces the refresh to completion
before JenkinsRule teardown: it flushes any in-flight write and bumps
the plugin's lastRunEnd so its 15-minute quiet period suppresses any
further refresh during teardown.
Before this change, traces only covered build execution. Builds that
spent time waiting in the Jenkins queue showed up with a root span
whose start time matched execution start, hiding all queue latency.

This change attaches a QueueItemMonitoringAction to each queue item
as it enters the WaitingItem state. The action tracks each state
transition (Waiting → Blocked → Buildable) with timestamps and the
reason/label for that state. When the build starts, MonitoringRunListener
reads the completed phases and emits a child span per phase under the
root BUILD span, using historical timestamps. The root span start time
is extended back to when the item first entered the queue.

New spans:
  Phase: Queue - Waiting   (ci.pipeline.run.queue.reason, when applicable)
  Phase: Queue - Blocked   (ci.pipeline.run.queue.reason, jenkins.pipeline.step.agent.label)
  Phase: Queue - Buildable (ci.pipeline.run.queue.reason, jenkins.pipeline.step.agent.label)
@rahulsom
rahulsom force-pushed the feat/queue-phase-spans branch from 2063e14 to 2a38cef Compare June 9, 2026 20:40
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.

1 participant