Title: Record the connection method for session app usage · Issue #31012 · coder/coder · GitHub
Open Graph Title: Record the connection method for session app usage · Issue #31012 · coder/coder
X Title: Record the connection method for session app usage · Issue #31012 · coder/coder
Description: Follow-up to #29796 (review thread). Problem Template insights reports each session app with a method (connection_log_method values). #29796 derives it at read time because session usage is stored per app name only: Stats.session_counts ...
Open Graph Description: Follow-up to #29796 (review thread). Problem Template insights reports each session app with a method (connection_log_method values). #29796 derives it at read time because session usage is stored ...
X Description: Follow-up to #29796 (review thread). Problem Template insights reports each session app with a method (connection_log_method values). #29796 derives it at read time because session usage is stored ...
Opengraph URL: https://github.com/coder/coder/issues/31012
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Record the connection method for session app usage","articleBody":"Follow-up to coder/coder#29796 ([review thread](\u003chttps://github.com/coder/coder/pull/29796#discussion_r4309702858>)).\n\n## Problem\n\nTemplate insights reports each session app with a `method` (`connection_log_method` values). coder/coder#29796 derives it at read time because session usage is stored per app name only: `Stats.session_counts` (agent proto) -> `workspace_agent_stats.session_counts` -> `template_usage_stats_session_apps(start_time, user_id, template_id, app_name, usage_mins)`.\n\nDerivation rule: app name `reconnecting_pty` -> `reconnecting_pty`, `port_forwarding` -> `port_forwarding`, any other session app -> `ssh`, template apps -> `workspace_app`. It is wrong whenever a client picks a name that does not match how it connected.\n\nSession counts have two sources:\n\n* The agent's `Stats.session_counts`, from its SSH and web terminal servers.\n* `POST /workspaces/{id}/usage` (`coderd/workspaces.go`), which turns the client-chosen `app_name` into `session_counts` directly. `coder port-forward` reports `port_forwarding`, `coder ssh --usage-app` any name (default `ssh`), `coder vscodessh` `vscode`, and `coder exp rpty` `reconnecting_pty`.\n\n## Scope (database only)\n\nStore the connection method of each session app. The agent protocol, the `/usage` endpoint, the CLI and the HTTP API do not change. Each current reporter uses an app name that matches its method, so coderd derives the method once, at ingest: `reconnecting_pty` → `reconnecting_pty`, `port_forwarding` → `port_forwarding`, everything else → `ssh`.\n\n* Migration: add `method connection_log_method NOT NULL` to `template_usage_stats_session_apps`, fill in existing rows with the rule above, add `method` to the primary key, and allow only `ssh`, `reconnecting_pty` and `port_forwarding`. The down migration adds each app's minutes across methods, capped at 30 per bucket.\n* Store `workspace_agent_stats.session_counts` as `{method: {app: count}}`.\n* The rollup and template insights group by (method, app). Apps past the limit fold into one `overflow` row per method.\n* Prometheus uses the stored method through coder/coder#29906, which is stacked on this PR. Telemetry and metricscache add up all methods, so their output does not change.\n\n## Out of scope\n\nA method field in the agent protocol and in `PostWorkspaceUsageRequest`. The first reporter whose app name does not match its method adds it (see the port-forward counting follow-up, [CLIENT-1053](https://linear.app/codercom/issue/CLIENT-1053/count-port-forwards-as-session-apps-per-method)).\n\n## Done when\n\n- [ ] coder/coder#31028 is merged.\n\nPart of coder/coder#27413.\n\n*Generated with Coder Agents on behalf of @EhabY.*\n\nScope narrowed to database-only storage by Coder Agents on behalf of @EhabY.","author":{"url":"https://github.com/EhabY","@type":"Person","name":"EhabY"},"datePublished":"2026-10-19T09:26:21Z","url":"https://github.com/coder/coder/issues/31012"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4eace5d3-c3d2-3036-1b1a-03d7f079b245 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC22:2E124E:1C80BF1:245C7C3:6B0160CD |
| html-safe-nonce | 4fe1c1b9b112c66260ed16a79bd4fece43ae9a1276140e1d8998c1911d5554c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzIyOjJFMTI0RToxQzgwQkYxOjI0NUM3QzM6NkIwMTYwQ0QiLCJ2aXNpdG9yX2lkIjoiMzU0OTUxNTkxMDgzNzI5MTAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0a24f88f2bea87262f16c4ae624603cf332bd2db31b063d2096c12800021bc8c |
| hovercard-subject-tag | issue:5921287386 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/31012/issue_layout |
| twitter:image | https://opengraph.githubassets.com/85e10661bb5ccb6e3948d7b9d870c3b124fa4636a4d762454f4ff5f513d11e18/coder/coder/issues/31012 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/85e10661bb5ccb6e3948d7b9d870c3b124fa4636a4d762454f4ff5f513d11e18/coder/coder/issues/31012 |
| og:image:alt | Follow-up to #29796 (review thread). Problem Template insights reports each session app with a method (connection_log_method values). #29796 derives it at read time because session usage is stored ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EhabY |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width