Job logger trace correlation#3782
Merged
DrJosh9000 merged 3 commits intobuildkite:mainfrom Mar 25, 2026
Merged
Conversation
Moves the inline job logger out of job_runner.go into json_job_logger.go and job_logger.go. JsonJobLogger handles structured JSON output with job metadata fields (org, pipeline, branch, etc.). JobLogger dispatches to JsonJobLogger for JSON format or passes bytes through directly for text. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parses the job's traceparent header and includes trace_id and span_id as structured log fields for trace correlation. Adds tests for the traceparent parsing and all structured job fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b00d8e6 to
e4238fb
Compare
Rename JsonJobLogger to JSONJobLogger, NewJsonJobLogger to NewJSONJobLogger, etc https://google.github.io/styleguide/go/decisions#initialisms Use cmp.Diff for comparing maps https://google.github.io/styleguide/go/decisions#full-structure-comparisons Avoid nil checking and type assertions by unmarshaling JSON to map[string]string instead of map[string]any, and take advantage of zero value for string to avoid missing map value checks
DrJosh9000
reviewed
Mar 25, 2026
Contributor
DrJosh9000
left a comment
There was a problem hiding this comment.
Thanks @aapzu, this is good. I've pushed some readability improvements, LGTM
DrJosh9000
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When both logging to stdout and tracing are on, it's difficult to connect the logs to the traces. That can be done by using build and log ids, but even that won't help with the exact span (e.g. if it was a hook or the step itself). This PR adds
trace_idandspan_idfields to the json formatted logs (if tracing is enabled), which are extracted from the job'straceparentheader.To be able to independently test the new code, the inline job logger code from job_runner.go was extracted into dedicated files to make it independently testable.
Context
relates to #3770
Changes
agent/json_job_logger.go: A new file with the extracted json logging code. Otherwise it's the same as what previously was injob_runner.go, but with the added traceparent field extraction.agent/job_logger.go: ExtractedjobLoggerfromjob_runner.go. Either initializes aJsonJobLoggeror aTextJobLoggerbased on thelog_formatconfiguration. Due to its simplicity, this file also contains theTextJobLoggerimplementation.agent/job_runner.go: ExtractedjobLoggertojob_logger.go.agent/json_job_logger_test.go: tests for traceparent field extraction as well as for the other fields that are added to the logs.agent/job_logger_test.go: tests for format dispatching behaviour.Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)Disclosures / Credits
Claude Code wrote the implementation and tests. I directed the design decisions and reviewed every single piece of the code written by it.