Record attachment operation counts in telemetry - #14360
Merged
Merged
Conversation
Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The deferred lifecycle, operation accounting, command integrations, and failure paths are consistently implemented and covered by focused tests.
Review tier: Balanced
Findings: None
What changed in this PR
Adds attachment Markdown operation counts to issue and pull request telemetry while preserving failed-invocation reporting.
Changes:
- Tracks upload, append, and replacement outcomes.
- Adds flush-time deferred telemetry resolution.
- Integrates and tests telemetry across six attachment-enabled commands.
| File | Description |
|---|---|
internal/attachments/attach.go |
Returns detailed upload results. |
internal/attachments/attach_test.go |
Tests operation counting. |
internal/attachments/doc.go |
Updates uploader documentation. |
internal/attachments/flags.go |
Removes immediate telemetry recording. |
internal/attachments/flags_test.go |
Tests deferred invocation telemetry. |
internal/attachments/references.go |
Counts rewritten attachments. |
internal/attachments/telemetry.go |
Implements invocation telemetry lifecycle. |
internal/attachments/test.go |
Adds telemetry test helpers. |
internal/gh/ghtelemetry/telemetry.go |
Extends the recorder interface. |
internal/telemetry/fake.go |
Supports deferred events in the spy. |
internal/telemetry/telemetry.go |
Resolves deferred events during flush. |
internal/telemetry/telemetry_test.go |
Verifies flush-time resolution. |
pkg/cmd/issue/comment/comment.go |
Registers deferred attachment telemetry. |
pkg/cmd/issue/comment/comment_test.go |
Tests validation-failure telemetry. |
pkg/cmd/issue/create/create.go |
Records creation attachment operations. |
pkg/cmd/issue/create/create_test.go |
Tests creation operation counts. |
pkg/cmd/issue/edit/edit.go |
Records edit attachment operations. |
pkg/cmd/issue/edit/edit_test.go |
Tests edit operation counts. |
pkg/cmd/pr/comment/comment.go |
Registers deferred attachment telemetry. |
pkg/cmd/pr/comment/comment_test.go |
Tests validation-failure telemetry. |
pkg/cmd/pr/create/create.go |
Records creation attachment operations. |
pkg/cmd/pr/create/create_test.go |
Tests creation operation counts. |
pkg/cmd/pr/edit/edit.go |
Records edit attachment operations. |
pkg/cmd/pr/edit/edit_test.go |
Tests edit operation counts. |
pkg/cmd/pr/shared/commentable.go |
Records shared comment upload operations. |
pkg/cmd/pr/shared/commentable_test.go |
Tests comment operation telemetry. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
williammartin
approved these changes
Sep 9, 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.
Follow-up to #14327, which added attachment invocation counts.
Description
Attachment telemetry records how many
--attachflags a command received, but not how successful uploads changed the command's Markdown.This adds
append_ops_countandreplace_ops_countmeasures to the existingattachment_invocationevent. An attachment that replaces several textual references counts as one replacement.The event is registered before argument validation and resolved when telemetry flushes. It still reports
attach_countfor failed invocations, including authentication and validation failures, while successful uploads can add their operation counts to the same event.How did you test this change?
I built the local
ghbinary and exercised a disposable test issue. I attached two PNGs, referenced the first twice in the comment body, and left the second unreferenced.The posted comment rewrote both references to the first uploaded URL and appended the second attachment. With
GH_TELEMETRY=log, I saw oneattachment_invocationevent withattach_countset to2andreplace_ops_countandappend_ops_counteach set to1, plus the pairedcommand_invocationevent.I also ran the command with a missing attachment. It failed validation and logged
attach_countas1, with both operation counts set to0.The recordings project the raw log through
jqso they show only event type, command, flags, and measures.Mixed append and replace
Validation failure
Key points
attachment_invocationuses dimensions{command}and measures{attach_count, append_ops_count, replace_ops_count}. It is sampled at 100%.--attachis parsed, authentication, positional argument, and command validation failures retainattach_countand report zero operations.Notes for reviewers
Start with the telemetry recorder interface and service implementation. The important new pattern is
RecordDeferred: a caller registers an event early, with its original recorded timestamp, but supplies a callback that resolves the final event duringFlush. Sampling and disabled-telemetry checks still happen before the callback is evaluated. The existing immediateRecordpath is unchanged.Then review
InvocationTelemetry, which references the parsed attachment flag but owns the recorder and mutable event. Each command options struct stores it besideAttachFlag. It registers the deferred event from Cobra's argument validator, after flags are parsed but before positional argument validation. Successful uploads update this telemetry object before the process-level flush, producing exactly oneattachment_invocationacross subsequent validation and execution paths.The telemetry service test covers flush-time resolution. The rooted attachment command test covers failure in a parent persistent pre-run hook, the lifecycle edge case that motivated the deferred recorder.
Authorship and follow-up
Who wrote this:
Who answers review comments: