-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(telemetry): improve Sentry instrumentation #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Switch from @sentry/node to @sentry/bun with esbuild alias for npm bundle - Add descriptive command names to spans (e.g., 'auth.login' instead of 'cli-execution') - Add HTTP instrumentation for API client and OAuth calls - Add DB instrumentation for auth/config operations - Add serialize instrumentation for expensive formatters - Track user identity (ID only, no PII) and instance ID for telemetry - Add org/project context tags in issue commands - Add schema migration v1→v2 for user_info and instance_info tables - Fix race condition in instance ID generation with INSERT OR IGNORE
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
…nstrumentation # Conflicts: # src/lib/telemetry.ts
Codecov Results 📊❌ Patch coverage is 68.98%. Project has 1760 uncovered lines. Files with missing lines (24)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 66.66% 67.66% +1%
==========================================
Files 45 47 +2
Lines 5297 5442 +145
Branches 0 0 —
==========================================
+ Hits 3531 3682 +151
- Misses 1766 1760 -6
- Partials 0 0 —Generated by Codecov Action |
ky already handles retries via apiRequest/createApiClient with exponential backoff. Manual retry loop was redundant.
|
Addressed in e2da7c4 - removed the manual retry loop since |
- Report errors to Sentry in catch block (login.ts) - Use getCurrentUser() for token validation, combining validation + user fetch - Fold clearUserInfo() into clearAuth() for single logout operation - Change setOrgProjectContext to accept arrays for org/project tags - Use uuidv7 npm package in node-polyfills.ts (Bun has native support) - Abstract schema table definitions to single source of truth
3c3262f to
637f1fe
Compare
637f1fe to
deae9db
Compare
…or v10.38.0 - Add user.json fixture and /api/0/users/me/ mock route for auth E2E tests - Create patch for @sentry/[email protected] (used by @sentry/[email protected]) - Keep existing patch for @sentry/[email protected] (used by @sentry/[email protected])
- Upgrade @sentry/node from 10.36.0 to 10.38.0 - Remove @sentry/[email protected] patch (no longer needed) - Keep single @sentry/[email protected] patch for both @sentry/bun and @sentry/node
Display 'Logged in as username <email>' after successful authentication for both token-based and OAuth flows.
- Add Sentry.captureException in telemetry.ts initTelemetryContext catch block - Abstract connection error handling into fetchWithConnectionError() in oauth.ts - Remove redundant divider comments in schema.ts and oauth.ts
Addressing PR Review CommentsI've made the following code changes in commit 912781f:
Responses to Questions:Q: Will No, they complement each other:
Q: Why not using OAuth uses native fetch because:
Q: Does SQLite have a built-in No, SQLite doesn't have built-in UUIDv7 support. Standard SQLite only provides:
UUIDv7 requires specific timestamp encoding in the first 48 bits that SQLite doesn't provide natively. Using Already Addressed in Previous Commits:
|
- Add tests for setCommandSpanName, setOrgProjectContext - Add tests for withHttpSpan, withDbSpan, withSerializeSpan - Add comprehensive tests for user.ts (getUserInfo, setUserInfo, clearUserInfo)
- CI: Ensure retry loop fails when all attempts exhausted (exit 1) - telemetry: Use dynamic import() instead of require() for ES module compatibility - user.ts: Remove unused clearUserInfo export (now handled by clearAuth)
Add formatUserIdentity() helper to gracefully handle cases where
username and/or email are undefined in the Sentry API response.
Fallback order:
1. username <email> (both present)
2. username (only username)
3. email (only email)
4. user {id} (neither present)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Database errors in setUserInfo() were incorrectly being treated as invalid token errors. Now the flows are: 1. getCurrentUser() validates token - failure clears auth 2. setUserInfo() stores telemetry data - failure is reported to Sentry This matches the OAuth flow pattern and prevents valid tokens from being cleared due to unrelated database errors.
Summary
Improves Sentry telemetry for better observability and debugging of CLI usage.
Changes
@sentry/coreto prevent 3s flush timeout from blocking CLI exitTechnical Notes
@sentry/bunfor native builds, aliased to@sentry/nodefor npm bundleuser_infoandinstance_infotables (schema v2 migration)Bun.randomUUIDv7()(polyfilled for Node.js)