fix: propagate user id to Hevy API spans - #592
Conversation
There was a problem hiding this comment.
✨ PR Review
The PR is small and focused: it plumbs getCurrentUserId() into the Axios request interceptor and adds tests for both the present and absent cases. The production code change is correct, but one test has a stale-mock indexing bug, and the changeset type may not match project conventions.
2 issues detected:
🐞 Bug - `mock.calls[0]` is the first call ever recorded; without clearing history between tests it does not reliably refer to the call made in the current test. 🛠️
Details: The "omits the user ID attribute" test reads telemetryTestDoubles.tracerStartSpan.mock.calls[0]?.[1] to obtain the span options. Because beforeEach only calls mockReturnValue (which preserves call history), calls[0] refers to the first invocation ever recorded across all prior tests, not the one made during this test. If any earlier test also triggered tracerStartSpan, the assertion silently checks stale data and the test can pass for the wrong reason.
File: src/utils/hevyClientKubb.test.ts (930-930)
🛠️ A suggested code correction is included in the review comments.
🧹 Maintainability - A versioned patch changeset is used for an internal-only telemetry enhancement, which the project convention reserves for `--empty` changesets.
Details: The changeset uses a versioned patch entry. Per project conventions, versioned changesets are reserved for user-facing, runtime-visible changes. Adding a user.id attribute to internal Honeycomb telemetry spans is an internal observability improvement that should use npx changeset --empty instead.
File: .changeset/tidy-traces-connect.md (1-5)
Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how
| baseURL: "https://api.hevyapp.com", | ||
| }); | ||
|
|
||
| const spanOptions = telemetryTestDoubles.tracerStartSpan.mock.calls[0]?.[1]; |
There was a problem hiding this comment.
🐞 Bug - Stale Mock Index: Clear the mock in beforeEach by adding telemetryTestDoubles.tracerStartSpan.mockClear(), or reference the last call instead: replace mock.calls[0]?.[1] with mock.calls.at(-1)?.[1].
| const spanOptions = telemetryTestDoubles.tracerStartSpan.mock.calls[0]?.[1]; | |
| const spanOptions = telemetryTestDoubles.tracerStartSpan.mock.calls.at(-1)?.[1]; |
Is this review accurate? Use 👍 or 👎 to rate it
If you want to tell us more, use /gs feedback e.g. /gs feedback this review doesn't make sense, I disagree, and it keeps repeating over and over
Unit Test Results 1 files 32 suites 3s ⏱️ Results for commit 508ea11. ♻️ This comment has been updated with latest results. |
|
Queued — the merge queue status continues in this comment ↓. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #592 +/- ##
=======================================
Coverage 93.00% 93.01%
=======================================
Files 35 35
Lines 1572 1574 +2
Branches 395 396 +1
=======================================
+ Hits 1462 1464 +2
Misses 48 48
Partials 62 62 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merge Queue Status
This pull request spent 7 minutes 3 seconds in the queue, including 1 minute 19 seconds running CI. Required conditions to merge
|
Summary
user.idto manually-createdhevy.api.*spans when available.Testing
npm run buildnpx vitest run src/utils/hevyClientKubb.test.tsnpx vitest run --exclude tests/integration/**npm run checknpm run check:typesnpm run check:changesetgit diff --checkAll passed.
Deployment
Honeycomb verification remains after deployment.
Resolves #588
✨ PR Description
Purpose: Propagate user ID to Hevy API trace spans to correlate API requests with specific users in observability data.
Main changes:
getCurrentUserIdfrom telemetry module and conditionally adduser.idattribute to trace spansgetCurrentUserIdtest double for request interceptor testingGenerated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how