Skip to content

feat: support agent friendly logs - #3440

Open
Debashich wants to merge 1 commit into
tektoncd:mainfrom
Debashich:feat/agent-friendly-logs
Open

Debashich wants to merge 1 commit into
tektoncd:mainfrom
Debashich:feat/agent-friendly-logs

Conversation

@Debashich

@Debashich Debashich commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Add JSON output support to tkn pipelinerun logs and tkn taskrun logs, making log output easier for agents, scripts, and automated tools to consume.

  • Add the -o/--output flag to both commands.
  • Support newline-delimited JSON (NDJSON), emitting one JSON object per log entry.
  • Include task, step, timestamp, and message fields in each log record.
  • Preserve timestamps provided by Kubernetes.
  • Support streaming JSON output with --follow.
  • Keep the existing human-readable output as the default.
  • Ensure JSON output remains machine-readable, including when runtime errors occur.
  • Update command documentation and man pages.

Sample Output

Run either command with -o json to receive newline-delimited JSON records:

tkn pipelinerun logs <pipeline-run-name> -o json
tkn taskrun logs <task-run-name> -o json

Each line represents an individual log entry, making it straightforward to process records incrementally without parsing human-readable terminal output.

Example format (illustrative; replace with actual CLI output):

{"task":"build","step":"build","timestamp":"2026-11-24T10:30:00Z","message":"Building application..."}
{"task":"build","step":"build","timestamp":"2026-11-24T10:30:01Z","message":"Build completed."}

Closes #2854

Submitter Checklist

See the [contribution guide](https://github.com/tektoncd/cli/blob/master/CONTRIBUTING.md) for more details.

Release Notes

Add JSON output support to PipelineRun and TaskRun logs commands.

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Nov 17, 2026
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign pratap0007 after the PR has been reviewed.
You can assign the PR to them by writing /assign @pratap0007 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 17, 2026
@Debashich Debashich changed the title Feat/agent friendly logs feat: support agent friendly logs Nov 17, 2026
@Debashich

Copy link
Copy Markdown
Contributor Author

Hey @divyansh42! Got this ready for review. Whenever you get some time PTAL

Copilot AI 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.

🟡 Changes recommended

Unresolved issues drop requested timestamps from text logs, contaminate JSON output with plain-text diagnostics, and can cause a panic on null termination-message entries.

3 open issues
What changed in this PR

Adds structured log output to tkn pipelinerun logs and tkn taskrun logs for agents and automated tools, using the shared log-reading and formatting infrastructure.

Changes:

  • Adds -o/--output json for newline-delimited JSON, including follow mode.
  • Carries Kubernetes timestamps into structured records with task, step, and message fields.
  • Updates command references and man pages; human-readable output remains the default.
File Description
pkg/​pods/​container.go Extracts timestamps from Kubernetes log lines.
pkg/​options/​logs.go Adds the output-format option.
pkg/​log/​writer.go Encodes structured log records as NDJSON.
pkg/​log/​task_reader.go Forwards timestamps and changes termination-result decoding.
pkg/​log/​pipeline_reader.go Forwards timestamps through pipeline logs.
pkg/​log/​log.go Adds timestamps to shared log records.
pkg/​cmd/​taskrun/​logs.go Exposes and configures JSON output for TaskRun logs.
pkg/​cmd/​pipelinerun/​logs.go Exposes and configures JSON output for PipelineRun logs.
docs/​man/​man1/​tkn-taskrun-logs.1 Documents the TaskRun output flag.
docs/​man/​man1/​tkn-pipelinerun-logs.1 Documents the PipelineRun output flag.
docs/​cmd/​tkn_taskrun_logs.md Updates the TaskRun command reference.
docs/​cmd/​tkn_pipelinerun_logs.md Updates the PipelineRun command reference.

Review effort: Balanced

Comment thread pkg/cmd/pipelinerun/logs.go Resolved
Comment thread pkg/log/task_reader.go Resolved
Comment thread pkg/log/writer.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from ac436dc to d0584b3 Compare November 18, 2026 21:05
@Debashich

Copy link
Copy Markdown
Contributor Author

@divyansh42 I have addressed the review suggestions PTAL whenever you are free. Thanks!

@Debashich

Copy link
Copy Markdown
Contributor Author

Also the k8s-plus-one E2E check failed on TestPipelineInteractiveStartE2E (-f + --last). Couldn't find anything conclusive in the logs. Could you rerun it once?

@divyansh42
divyansh42 requested a balanced review from Copilot November 19, 2026 05:49
@divyansh42

Copy link
Copy Markdown
Member

/retest

Copilot AI 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.

🟡 Changes recommended

Unresolved issues split long log lines with incorrect timestamps, drop genuine EOFLOG messages, mix selection output into JSON stdout, and silently accept unsupported output formats.

5 open issues
2 resolved since last review

Review effort: Balanced

Comment thread pkg/cmd/pipelinerun/logs.go Resolved
Comment thread pkg/cmd/taskrun/logs.go Resolved
Comment thread pkg/log/writer.go Resolved
Comment thread pkg/pods/container.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from cfcb1a3 to a722779 Compare November 19, 2026 18:39
@Debashich

Copy link
Copy Markdown
Contributor Author

Addressed the review suggestions.

Copilot AI 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.

Comment thread pkg/cmd/pipelinerun/logs.go Resolved
Comment thread pkg/log/writer.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from a722779 to b78e17a Compare November 20, 2026 14:45
@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 20, 2026
@Debashich

Copy link
Copy Markdown
Contributor Author

I've addressed the review comments as well. Could you please rerun the failed test? It seems to be an intermittent CI issue. Thanks!

@divyansh42
divyansh42 requested a balanced review from Copilot November 20, 2026 16:20
@divyansh42

Copy link
Copy Markdown
Member

/retest

Copilot AI 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.

🟡 Changes recommended

Cancellation can close shared logging channels before task goroutines finish sending, causing a panic, and the cancellation test can hang when its unbuffered notification is dropped.

4 open issues

Review effort: Balanced

Comment thread pkg/log/pipeline_reader.go Resolved
Comment thread pkg/pipelinerun/tracker_test.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from 7193858 to aad95fa Compare November 20, 2026 18:27
@Debashich

Copy link
Copy Markdown
Contributor Author

Addressed the reviews

Copilot AI 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.

Comment thread pkg/cmd/pipelinerun/logs.go Resolved
Comment thread pkg/log/writer.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from aad95fa to e8c507a Compare November 20, 2026 20:25
@Debashich

Copy link
Copy Markdown
Contributor Author

Addressed the review, PTAL when you get a chance

@divyansh42

Copy link
Copy Markdown
Member

@Debashich could you please attach a sample output in the description for better understanding?

Copilot AI 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.

🟡 Changes recommended

The logging changes can produce invalid JSON diagnostics, reject valid output-format case and whitespace variants, and lose TaskRun failure details when no pod exists.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread pkg/cmd/pipelinerun/logs.go Resolved
Comment thread pkg/log/task_reader.go Resolved
Comment thread pkg/options/logs.go Resolved
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from 77d9193 to f2bf635 Compare November 23, 2026 19:52
Signed-off-by: Debashich <debashishsinha555@gmail.com>

Add wait for goroutine in pipeline_reader

Ensure goroutine waits for completion before returning.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

test: buffer inHandler channel to prevent test hang

Return error when no PipelineRuns are found

Change error handling to return an error when no PipelineRuns are found.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

fix: make agent-friendly logs JSON output consistent

Signed-off-by: Debashich <debashishsinha555@gmail.com>

test: verify JSON runtime errors and exit codes

Signed-off-by: Debashich <debashishsinha555@gmail.com>
@Debashich
Debashich force-pushed the feat/agent-friendly-logs branch from 584f506 to d7a847b Compare November 23, 2026 22:30
@Debashich

Copy link
Copy Markdown
Contributor Author

I have addressed the reviews, PTAL when you get a chance.

Copilot AI 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.

🟡 Changes recommended

Cancellation cannot interrupt stream-opening requests, and log commands return the wrong exit code when neither a run name nor --last is supplied.

2 open issues
4 resolved since last review

Review effort: Balanced

}

if opts.Output == "json" && opts.PipelineRunName == "" && !opts.Last {
return fmt.Errorf("JSON output requires a PipelineRun name or --last")
Comment thread pkg/pods/container.go
}

// ReadContext reads container logs until the context is cancelled.
func (lr *LogReader) ReadContext(ctx context.Context) (<-chan Log, <-chan error, error) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make pipelinerun/taskrun logs agent-friendly

4 participants