René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:30693ea1-ccdc-66f3-f9e2-5855e794f51e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8956:266B67:4D53C8:66206C:6B017982
html-safe-nonce61b806db1d7dd5cdd254f6b53bcefd2af801809bb698355c95072b293570311f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTU2OjI2NkI2Nzo0RDUzQzg6NjYyMDZDOjZCMDE3OTgyIiwidmlzaXRvcl9pZCI6IjY1NTgxMzIzNTk0NDk5MDE0NDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac892bc6a0bc2a900424032f1a62f65263dd8939174b04cbb97b64f8b5b63bc9cc
hovercard-subject-tagissue:4041826846
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/squad/281/issue_layout
twitter:imagehttps://opengraph.githubassets.com/30b708d12c745bc4fc69276c82f398fd9b0464dbd1eb08348b9ef76f0ed200ad/github/squad/issues/281
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/30b708d12c745bc4fc69276c82f398fd9b0464dbd1eb08348b9ef76f0ed200ad/github/squad/issues/281
og:image:altProblem 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebradygaster
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/github/squad git https://github.com/github/squad.git
octolytics-dimension-user_id9919
octolytics-dimension-user_logingithub
octolytics-dimension-repository_id1151205052
octolytics-dimension-repository_nwogithub/squad
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1151205052
octolytics-dimension-repository_network_root_nwogithub/squad
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/github/squad/issues/281#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fsquad%2Fissues%2F281
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fsquad%2Fissues%2F281
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=github%2Fsquad
Reloadhttps://github.com/github/squad/issues/281
Reloadhttps://github.com/github/squad/issues/281
Reloadhttps://github.com/github/squad/issues/281
githubhttps://github.com/github
squadhttps://github.com/github/squad
Codehttps://github.com/github/squad
Issues108 (108)https://github.com/github/squad/issues
Pull requests26 (26)https://github.com/github/squad/pulls
Discussionshttps://github.com/github/squad/discussions
Actionshttps://github.com/github/squad/actions
Projectshttps://github.com/github/squad/projects
Security and qualityhttps://github.com/github/squad/security
Insightshttps://github.com/github/squad/insights
https://github.com/github/squad
New issuehttps://github.com/login?return_to=https://github.com/github/squad/issues/281
New issuehttps://github.com/login?return_to=https://github.com/github/squad/issues/281
#501https://github.com/github/squad/pull/501
initSquadTelemetry() should auto-wire EventBus, CostTracker, and token metricshttps://github.com/github/squad/issues/281#top
#501https://github.com/github/squad/pull/501
enhancementNew feature or improvementhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22enhancement%22
next-upPriority queue — next issues to workhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22next-up%22
priority:p2Next sprinthttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22priority%3Ap2%22
squadSquad triage inbox — Lead will assign to a memberhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%22
status:doneWork completed and shippedhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22status%3Adone%22
type:featureNew capabilityhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22type%3Afeature%22
https://github.com/bradygaster
bradygasterhttps://github.com/bradygaster
on Mar 8, 2026https://github.com/github/squad/issues/281#issue-4041826846
Squad IRLhttps://github.com/bradygaster/Squad-IRL
Squad IRLhttps://github.com/bradygaster/Squad-IRL
bradygasterhttps://github.com/bradygaster
enhancementNew feature or improvementhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22enhancement%22
type:featureNew capabilityhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22type%3Afeature%22
priority:p2Next sprinthttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22priority%3Ap2%22
squad:telemetryhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Atelemetry%22
status:backlogBacklog itemhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22status%3Abacklog%22
on Mar 8, 2026https://github.com/github/squad/issues/281#event-23375349727
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Mar 9, 2026https://github.com/github/squad/issues/281#issuecomment-4022939279
GitHub Actionshttps://help.github.com/en/actions
#281https://github.com/github/squad/issues/281
bradygasterhttps://github.com/bradygaster
squad:saulhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Asaul%22
squad:telemetryhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Atelemetry%22
squad:telemetryhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Atelemetry%22
squad:saulhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Asaul%22
on Mar 13, 2026https://github.com/github/squad/issues/281#event-23559305087
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Mar 13, 2026https://github.com/github/squad/issues/281#issuecomment-4058726613
GitHub Actionshttps://help.github.com/en/actions
#281https://github.com/github/squad/issues/281
githubhttps://github.com/github
github-actionshttps://github.com/github-actions
on Mar 18, 2026https://github.com/github/squad/issues/281#event-23694388397
github-actionshttps://github.com/apps/github-actions
squadSquad triage inbox — Lead will assign to a memberhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%22
on Mar 20, 2026https://github.com/github/squad/issues/281#event-23746163594
bradygasterhttps://github.com/bradygaster
next-upPriority queue — next issues to workhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22next-up%22
on Mar 22, 2026https://github.com/github/squad/issues/281#event-23789050852
bradygasterhttps://github.com/bradygaster
on Mar 22, 2026https://github.com/github/squad/issues/281#event-23789162202
feat: auto-wire telemetry in initSquadTelemetry() (#281)https://github.com/github/squad/commit/832cb401871d290ecba0daceaed73464667eddca
#281https://github.com/github/squad/issues/281
832cb40https://github.com/github/squad/commit/832cb401871d290ecba0daceaed73464667eddca
bradygasterhttps://github.com/bradygaster
completedhttps://github.com/github/squad/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
d507dc3https://github.com/github/squad/commit/d507dc36fdcf29746e22175220681ee504ee3869
on Mar 22, 2026https://github.com/github/squad/issues/281#event-23789213001
bradygasterhttps://github.com/bradygaster
status:doneWork completed and shippedhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22status%3Adone%22
status:backlogBacklog itemhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22status%3Abacklog%22
on Mar 22, 2026https://github.com/github/squad/issues/281#event-23789214845
diberryhttps://github.com/diberry
on Mar 22, 2026https://github.com/github/squad/issues/281#event-23791078249
feat: auto-wire telemetry in initSquadTelemetry() (github#281) (githu…https://github.com/diberry/squad/commit/d507dc36fdcf29746e22175220681ee504ee3869
github#281https://github.com/github/squad/issues/281
githu…https://github.com/github/squad/pull/501
d507dc3https://github.com/diberry/squad/commit/d507dc36fdcf29746e22175220681ee504ee3869
bradygasterhttps://github.com/bradygaster
squad:telemetryhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%3Atelemetry%22
on Sep 11, 2026https://github.com/github/squad/issues/281#event-31000849713
Sign up for freehttps://github.com/signup?return_to=https://github.com/github/squad/issues/281
Sign in to commenthttps://github.com/login?return_to=https://github.com/github/squad/issues/281
enhancementNew feature or improvementhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22enhancement%22
next-upPriority queue — next issues to workhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22next-up%22
priority:p2Next sprinthttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22priority%3Ap2%22
squadSquad triage inbox — Lead will assign to a memberhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22squad%22
status:doneWork completed and shippedhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22status%3Adone%22
type:featureNew capabilityhttps://github.com/github/squad/issues?q=state%3Aopen%20label%3A%22type%3Afeature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.