Skip to content

fix(telemetry): label auth add/switch events with the newly active site - #28

Closed
cb-muthiahm wants to merge 1 commit into
mainfrom
fix/telemetry-auth-site-name
Closed

cb-muthiahm wants to merge 1 commit into
mainfrom
fix/telemetry-auth-site-name

Conversation

@cb-muthiahm

@cb-muthiahm cb-muthiahm commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Telemetry events for auth add and auth switch carried the site that was active before the command ran: unconfigured for a first auth add, otherwise the previous profile's site. The recorder reads the site in preAction, before the action saves the new active profile. These events now carry the site the command made active.

 preAction
   begin()      pending.siteName = peekActiveSiteName()   # before the action runs
 action (auth add / auth switch)
   writeConfig({ activeProfile })
+  noteActiveSite(site)
 exit
   finalize()
-    site_name: pending.siteName
+    site_name: takeActiveSite() ?? pending.siteName

noteActiveSite lives in a dependency-free module (telemetry/active-site.ts), following error.ts and interactive.ts, so commands don't import the recorder. A failed command never reaches the call and keeps its previous label.

Changes

  • src/lib/telemetry/active-site.ts: new noteActiveSite / takeActiveSite slot.
  • src/lib/telemetry/index.ts: finalize() prefers the noted site; the test reset clears it.
  • src/commands/auth.ts, src/lib/config/switch-profile.ts: note the site once the profile is saved as active.
  • src/lib/test-support/_helpers.ts: runCli accepts an optional configure hook, so integration tests can install the recorder on the real program.
  • Tests: unit tests for the slot and the recorder; integration tests for a first auth add, auth add over an active profile, auth switch, a failed auth add, an ordinary command, and telemetry disabled.
  • TELEMETRY.md: documents site_name for auth add and auth switch.

New integration tests, run against main without the fix:

Scenario Before After
First auth add for acme-test unconfigured acme-test
auth add for globex-test while acme-test is active acme-test globex-test
auth switch dev (acme-test) from globex-test globex-test acme-test
auth add with an invalid site while acme-test is active acme-test acme-test

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / internal
  • Other:

Checklist

  • bun test passes
  • bun run typecheck passes
  • If I changed the code generator or SDK version, I ran bun run generate --refresh and committed the regenerated src/commands/generated/*
  • I updated docs / README / skill content where relevant
  • I did not commit any secrets or credentials

Related issues

auth add and auth switch now record the site they make active. Telemetry uses that site for successful commands and falls back to the previously active site when no new site is recorded. Added unit and integration tests for site tracking and telemetry labels.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Auth profile commands now record the resulting active site for telemetry events. The telemetry recorder consumes that site when finalizing an event, and tests cover command outcomes and slot reset behavior.

Changes

Active site telemetry

Layer / File(s) Summary
Site capture and event recording
src/lib/telemetry/active-site.ts, src/commands/auth.ts, src/lib/config/switch-profile.ts, src/lib/telemetry/index.ts, TELEMETRY.md, src/tests/unit/lib/telemetry/*
auth add and auth switch note the site after updating the active profile. The recorder consumes the noted site for site_name and falls back to the pending site when none is noted. Unit tests cover slot consumption and reset behavior. The telemetry description reflects the resulting-site behavior.
CLI integration coverage
src/lib/test-support/_helpers.ts, src/tests/integration/telemetry-site-label.test.ts
runCli accepts a configuration callback that runs before argument parsing. Integration tests check successful profile changes, failed auth add, a subsequent command, and disabled telemetry.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: cb-logesh

Merge Risk: Minimal · up to af692

The telemetry label change is ready to merge after normal checks.

Pre-merge checks: Passed 1

Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 8 files. (1 skipped: 1 unsupported.)

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 11e92c00-5f85-449f-aa89-3207ede31f4a
Commits

Reviewing files that changed from the base of the PR and between ca5c25a and af6920f.

Files selected for processing: 9

  • TELEMETRY.md
  • src/commands/auth.ts
  • src/lib/config/switch-profile.ts
  • src/lib/telemetry/active-site.ts
  • src/lib/telemetry/index.ts
  • src/lib/test-support/_helpers.ts
  • src/tests/integration/telemetry-site-label.test.ts
  • src/tests/unit/lib/telemetry/active-site.test.ts
  • src/tests/unit/lib/telemetry/index.test.ts
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Test coverage

✅ Gate passed — all 79 files are at or above the 95% floor.

Status Metric Coverage Threshold
✅ Functions 99.90% 95%
✅ Lines 99.45% 95%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant