Title: initSquadTelemetry() should auto-wire EventBus, CostTracker, and token metrics · Issue #281 · github/squad · GitHub
Open Graph Title: initSquadTelemetry() should auto-wire EventBus, CostTracker, and token metrics · Issue #281 · github/squad
X Title: initSquadTelemetry() should auto-wire EventBus, CostTracker, and token metrics · Issue #281 · github/squad
Description: Problem Currently, getting full telemetry from the Squad SDK requires ~30 lines of manual wiring per app: Import RuntimeEventBus, CostTracker, recordTokenUsage separately Create an EventBus instance and pass it to initSquadTelemetry({ ev...
Open Graph Description: Problem Currently, getting full telemetry from the Squad SDK requires ~30 lines of manual wiring per app: Import RuntimeEventBus, CostTracker, recordTokenUsage separately Create an EventBus instanc...
X Description: Problem Currently, getting full telemetry from the Squad SDK requires ~30 lines of manual wiring per app: Import RuntimeEventBus, CostTracker, recordTokenUsage separately Create an EventBus instanc...
Opengraph URL: https://github.com/github/squad/issues/281
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"initSquadTelemetry() should auto-wire EventBus, CostTracker, and token metrics","articleBody":"## Problem\n\nCurrently, getting full telemetry from the Squad SDK requires ~30 lines of manual wiring per app:\n\n1. Import `RuntimeEventBus`, `CostTracker`, `recordTokenUsage` separately\n2. Create an `EventBus` instance and pass it to `initSquadTelemetry({ eventBus })`\n3. Create a `CostTracker` and call `costTracker.wireToEventBus(eventBus)`\n4. Subscribe to the session's `usage` event and manually forward it to the EventBus as a `session:message` event\n5. Call `recordTokenUsage()` yourself to populate the OTel metric counters (`squad.tokens.input`, `squad.tokens.output`, `squad.tokens.cost`)\n6. Print `costTracker.formatSummary()` at shutdown\n\nWithout all of this, users only see `squad.sessions.active` and `squad.sessions.created` in their Aspire/OTel dashboard — no token counts, no cost data, no per-agent breakdowns.\n\nAdditionally, the SDK's `client.js` puts token data as span **attributes** (`tokens.input`, `tokens.output`) on the `squad.session.stream` span, but never calls `recordTokenUsage()` to fire the **metric counters**. So even with a properly configured OTel endpoint, the `squad.tokens.*` metrics never appear.\n\n## Discovery\n\nFound while wiring telemetry across the [Squad IRL](https://github.com/bradygaster/Squad-IRL) samples. All 19 samples needed identical boilerplate. The pattern works, but it shouldn't require this much ceremony.\n\n### What users have to do today\n\n```typescript\nimport { initSquadTelemetry, RuntimeEventBus as EventBus, CostTracker, recordTokenUsage } from '@bradygaster/squad-sdk';\n\nconst eventBus = new EventBus();\nconst telemetry = initSquadTelemetry({ eventBus });\nconst costTracker = new CostTracker();\ncostTracker.wireToEventBus(eventBus);\n\n// ... after creating session ...\nsession.on('usage', (event) => {\n const inputTokens = event.inputTokens ?? 0;\n const outputTokens = event.outputTokens ?? 0;\n const model = event.model ?? 'unknown';\n const cost = estimateCost(model, inputTokens, outputTokens); // user must provide pricing!\n\n recordTokenUsage({ type: 'usage', sessionId: session.sessionId, model, inputTokens, outputTokens, estimatedCost: cost, timestamp: new Date() });\n eventBus.emit({ type: 'session:message', sessionId: session.sessionId, payload: { inputTokens, outputTokens, model, estimatedCost: cost }, timestamp: new Date() });\n});\n```\n\n## Proposed Solution\n\n`initSquadTelemetry()` should handle all of this internally. Ideal API:\n\n```typescript\nconst telemetry = initSquadTelemetry();\n// That's it. Everything lights up.\n```\n\nSpecifically:\n1. **Auto-create EventBus** internally if none is provided\n2. **Auto-wire CostTracker** to the internal EventBus\n3. **Have `client.js` call `recordTokenUsage()`** in `sendMessage()` and `sendAndWait()` — not just set span attributes\n4. **Auto-forward session `usage` events** to the EventBus when sessions are created via `SquadClient`\n5. **Include model pricing** in the SDK so users don't have to maintain their own pricing table\n6. **Expose the CostTracker** on the returned handle: `telemetry.costTracker.formatSummary()`\n\n### Bonus: SquadClient integration\n\nIf `SquadClient` accepted an optional `eventBus` parameter, it could auto-wire session events internally:\n\n```typescript\nconst client = new SquadClient({ cwd: process.cwd(), eventBus: telemetry.eventBus });\n```\n\n## Impact\n\n- Every SDK consumer currently gets incomplete telemetry unless they know the internal architecture\n- The `squad.tokens.*` OTel metrics are defined but never populated through normal usage paths\n- Cost reporting requires users to maintain their own model pricing table\n\n## Current Workaround\n\nSee commit `63bf0b1` in [Squad IRL](https://github.com/bradygaster/Squad-IRL) for the full pattern applied across 19 samples.","author":{"url":"https://github.com/bradygaster","@type":"Person","name":"bradygaster"},"datePublished":"2026-03-08T17:54:38Z","url":"https://github.com/github/squad/issues/281"}
| 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:30693ea1-ccdc-66f3-f9e2-5855e794f51e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8956:266B67:4D53C8:66206C:6B017982 |
| html-safe-nonce | 61b806db1d7dd5cdd254f6b53bcefd2af801809bb698355c95072b293570311f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTU2OjI2NkI2Nzo0RDUzQzg6NjYyMDZDOjZCMDE3OTgyIiwidmlzaXRvcl9pZCI6IjY1NTgxMzIzNTk0NDk5MDE0NDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 892bc6a0bc2a900424032f1a62f65263dd8939174b04cbb97b64f8b5b63bc9cc |
| hovercard-subject-tag | issue:4041826846 |
| 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/github/squad/281/issue_layout |
| twitter:image | https://opengraph.githubassets.com/30b708d12c745bc4fc69276c82f398fd9b0464dbd1eb08348b9ef76f0ed200ad/github/squad/issues/281 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/30b708d12c745bc4fc69276c82f398fd9b0464dbd1eb08348b9ef76f0ed200ad/github/squad/issues/281 |
| og:image:alt | Problem Currently, getting full telemetry from the Squad SDK requires ~30 lines of manual wiring per app: Import RuntimeEventBus, CostTracker, recordTokenUsage separately Create an EventBus instanc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bradygaster |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/github/squad git https://github.com/github/squad.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 1151205052 |
| octolytics-dimension-repository_nwo | github/squad |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1151205052 |
| octolytics-dimension-repository_network_root_nwo | github/squad |
| 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