Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions github/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,22 @@ type CopilotMetricsCLI struct {
LastKnownCLIVersion *CopilotMetricsCLIVersion `json:"last_known_cli_version,omitempty"`
}

// CopilotMetricsThirdPartyAgent represents per-agent app totals in a Copilot usage metrics report.
//
// AgentID is the stable grouping key. AgentName is for display and can change.
// UserInitiatedInteractionCount is agent-app job starts; it is not the same as
// the top-level user_initiated_interaction_count on the parent metrics object.
// SessionCount is included on aggregated enterprise and organization reports
// and omitted from per-user reports.
//
// GitHub API docs: https://docs.github.com/en/copilot/reference/copilot-usage-metrics/copilot-usage-metrics#agent-apps-metrics-fields
type CopilotMetricsThirdPartyAgent struct {
AgentName string `json:"agent_name"`
AgentID string `json:"agent_id"`
UserInitiatedInteractionCount *int `json:"user_initiated_interaction_count,omitempty"`
SessionCount *int `json:"session_count,omitempty"`
Comment on lines +1023 to +1024

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.

I thought these were unmarshal only types so I'm unsure why they need omitempty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question — omitempty only affects marshaling, so it's not required for Unmarshal itself.

I kept it to match the existing Copilot metrics types and the CONTRIBUTING guidance for response bodies (optional pointer fields use omitempty), and so nil fields round-trip cleanly via testJSONMarshal / user re-marshaling without emitting null.

Happy to drop it if you'd prefer these tags to be unmarshal-only.

@gmlewis gmlewis Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought these were unmarshal only types so I'm unsure why they need omitempty?

Right - it is common practice in this repo to use pointers and omitempty for unmarshal-only types, especially when structs are used for many different endpoints. Then, when the GitHub v3 API servers do not provide fields, it is easy to see when they are not included.

I think it is fine to run with this without modification.

@stevehipwell stevehipwell Aug 21, 2026

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.

@gmlewis I'm not sure I follow? The official docs for JSON struct tags say omitempty & omitzero are ignored during unmarshalling, and this type is unmarshal only. I also don't think the struct tag should be conflated with the use of a pointer.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@gmlewis I'm not sure I follow? The official docs for JSON struct tags say omitempty & omitzero are ignored during unmarshalling, and this type is unmarshal only. I also don't think the struct tag should be conflated with the use of a pointer.

Ah, I see exactly what you are saying, and you are right, @stevehipwell.

I think the biggest challenge in this repo is to determine which fields are unmarshal-only, so I wrote #4478 to analyze the situation.

I still like the point made by @Tens1des regarding:

and so nil fields round-trip cleanly via testJSONMarshal / user re-marshaling without emitting null.

So I think we should go ahead with this PR and merge as-is.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@alexandear or @Not-Dhananjay-Mishra - do you have any opinions in this matter?

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.

We can remove the omitempty in another PR.

}

// CopilotDailyMetrics represents the payload downloaded from a 1-day Copilot usage metrics report.
type CopilotDailyMetrics struct {
Day string `json:"day"`
Expand All @@ -1032,6 +1048,7 @@ type CopilotDailyMetrics struct {
TotalsByLanguageModel []*CopilotMetricsLanguageModel `json:"totals_by_language_model,omitempty"`
TotalsByModelFeature []*CopilotMetricsModelFeature `json:"totals_by_model_feature,omitempty"`
TotalsByCLI *CopilotMetricsCLI `json:"totals_by_cli,omitempty"`
TotalsBy3rdPartyAgent []*CopilotMetricsThirdPartyAgent `json:"totals_by_3rd_party_agent,omitempty"`
LOCSuggestedToAddSum *int `json:"loc_suggested_to_add_sum,omitempty"`
LOCSuggestedToDeleteSum *int `json:"loc_suggested_to_delete_sum,omitempty"`
LOCAddedSum *int `json:"loc_added_sum,omitempty"`
Expand Down Expand Up @@ -1092,6 +1109,7 @@ type CopilotUserDailyMetrics struct {
TotalsByLanguageModel []*CopilotMetricsLanguageModel `json:"totals_by_language_model,omitempty"`
TotalsByModelFeature []*CopilotMetricsModelFeature `json:"totals_by_model_feature,omitempty"`
TotalsByCLI *CopilotMetricsCLI `json:"totals_by_cli,omitempty"`
TotalsBy3rdPartyAgent []*CopilotMetricsThirdPartyAgent `json:"totals_by_3rd_party_agent,omitempty"`
UsedAgent *bool `json:"used_agent,omitempty"`
UsedChat *bool `json:"used_chat,omitempty"`
UsedCLI *bool `json:"used_cli,omitempty"`
Expand Down Expand Up @@ -1125,6 +1143,7 @@ type CopilotUserPeriodicMetrics struct {
TotalsByLanguageModel []*CopilotMetricsLanguageModel `json:"totals_by_language_model,omitempty"`
TotalsByModelFeature []*CopilotMetricsModelFeature `json:"totals_by_model_feature,omitempty"`
TotalsByCLI *CopilotMetricsCLI `json:"totals_by_cli,omitempty"`
TotalsBy3rdPartyAgent []*CopilotMetricsThirdPartyAgent `json:"totals_by_3rd_party_agent,omitempty"`
UsedAgent *bool `json:"used_agent,omitempty"`
UsedChat *bool `json:"used_chat,omitempty"`
UsedCLI *bool `json:"used_cli,omitempty"`
Expand Down
25 changes: 24 additions & 1 deletion github/copilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,14 @@ func TestCopilotService_DownloadDailyMetrics(t *testing.T) {
"prompt_tokens_sum": 9494
}
},
"totals_by_3rd_party_agent": [
{
"agent_name": "Claude",
"agent_id": "claude",
"user_initiated_interaction_count": 8,
"session_count": 3
}
],
"loc_added_sum": 100,
"pull_requests": {
"total_reviewed": 1,
Expand Down Expand Up @@ -3121,6 +3129,14 @@ func TestCopilotService_DownloadDailyMetrics(t *testing.T) {
PromptTokensSum: Ptr(9494),
},
},
TotalsBy3rdPartyAgent: []*CopilotMetricsThirdPartyAgent{
{
AgentName: "Claude",
AgentID: "claude",
UserInitiatedInteractionCount: Ptr(8),
SessionCount: Ptr(3),
},
},
LOCAddedSum: Ptr(100),
PullRequests: &CopilotMetricsPullRequests{
TotalReviewed: Ptr(1),
Expand Down Expand Up @@ -3268,7 +3284,7 @@ func TestCopilotService_DownloadUserDailyMetrics(t *testing.T) {

mux.HandleFunc("/path/to/users-daily", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"user_id":1,"user_login":"alice","day":"2026-04-01","user_initiated_interaction_count":5,"chat_panel_edit_mode":2,"used_chat":true,"used_cli":true,"used_copilot_code_review_active":true,"totals_by_cli":{"session_count":2,"request_count":2,"prompt_count":1,"last_known_cli_version":{"sampled_at":`+refTimeStr(1136178000)+`,"cli_version":"1.0.8"}},"totals_by_ide":[{"ide":"vscode","user_initiated_interaction_count":5,"last_known_plugin_version":{"sampled_at":`+refTimeStr(1136178001)+`,"plugin":"copilot","plugin_version":"1.0.0"},"last_known_ide_version":{"sampled_at":`+refTimeStr(1136178002)+`,"ide_version":"1.90"}}]}
fmt.Fprint(w, `{"user_id":1,"user_login":"alice","day":"2026-04-01","user_initiated_interaction_count":5,"chat_panel_edit_mode":2,"used_chat":true,"used_cli":true,"used_copilot_code_review_active":true,"totals_by_cli":{"session_count":2,"request_count":2,"prompt_count":1,"last_known_cli_version":{"sampled_at":`+refTimeStr(1136178000)+`,"cli_version":"1.0.8"}},"totals_by_ide":[{"ide":"vscode","user_initiated_interaction_count":5,"last_known_plugin_version":{"sampled_at":`+refTimeStr(1136178001)+`,"plugin":"copilot","plugin_version":"1.0.0"},"last_known_ide_version":{"sampled_at":`+refTimeStr(1136178002)+`,"ide_version":"1.90"}}],"totals_by_3rd_party_agent":[{"agent_name":"Claude","agent_id":"claude","user_initiated_interaction_count":2}]}
{"user_id":2,"user_login":"bob","day":"2026-04-01","used_agent":true,"used_copilot_code_review_passive":true}
`)
})
Expand Down Expand Up @@ -3319,6 +3335,13 @@ func TestCopilotService_DownloadUserDailyMetrics(t *testing.T) {
},
},
},
TotalsBy3rdPartyAgent: []*CopilotMetricsThirdPartyAgent{
{
AgentName: "Claude",
AgentID: "claude",
UserInitiatedInteractionCount: Ptr(2),
},
},
},
{
UserID: 2,
Expand Down
56 changes: 56 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading