Repository navigation
Make the analytics shim's tripwire name the API that will replace it - #552
Conversation
The contract test asserted the server SDK still offers no way for a caller to supply the event's page URL, by matching an `options.url` override. The request actually went upstream as vercel/analytics#208, which adds a `beforeSend` hook mirroring the browser SDK's -- source reading `options?.beforeSend` and `event.url`, matching neither that regex nor anything else the test looked for. So the tripwire would have stayed green through exactly the API it was watching for, and the shim would have outlived its own replacement without anyone being told. Assert on `beforeSend` by name as well, so bumping the dependency past the release that carries it is a red test rather than something to remember. Records the upstream PR on the follow-up entry, which until now only said to open one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reviewer's GuideThe PR tightens the analytics shim tripwire by explicitly checking for the new Flow diagram for analytics shim tripwire reacting to beforeSend introductionflowchart TD
vercel_analytics_release["Vercel analytics releases server beforeSend hook"]
dependency_bump["Project bumps @vercel/analytics dependency"]
run_tests["Run analytics-request-context.test"]
check_bundle["Check sdk bundle for options.url and beforeSend"]
has_beforeSend{sdk contains beforeSend}
test_fail["Test fails (tripwire triggered)"]
migrate_shim["Migrate trackEvent to beforeSend and delete shim"]
vercel_analytics_release --> dependency_bump --> run_tests --> check_bundle --> has_beforeSend
has_beforeSend -->|yes| test_fail --> migrate_shim
has_beforeSend -->|no| run_tests
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
expect(sdk).not.toContain("beforeSend")assertion is quite broad and could fail on incidental occurrences (e.g., comments, metadata); consider tightening it to a regex that specifically targetsoptions?.beforeSendin the server track implementation. - Given that this test is acting as a tripwire on the bundled SDK, it might be more robust to key off a structural signal (e.g., the presence of a beforeSend option in the exported API shape) rather than plain text matching, to reduce fragility against bundling/minification changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `expect(sdk).not.toContain("beforeSend")` assertion is quite broad and could fail on incidental occurrences (e.g., comments, metadata); consider tightening it to a regex that specifically targets `options?.beforeSend` in the server track implementation.
- Given that this test is acting as a tripwire on the bundled SDK, it might be more robust to key off a structural signal (e.g., the presence of a beforeSend option in the exported API shape) rather than plain text matching, to reduce fragility against bundling/minification changes.
## Individual Comments
### Comment 1
<location path="docs/product/follow-ups/FU-20260814-vercel-analytics-url-override.md" line_range="65-67" />
<code_context>
+ https://github.com/vercel/analytics/pull/208** — `feat(server): add \`beforeSend\` to server-side
+ \`track\``, opened by a human under their own account, as this entry required. It adds the
+ browser SDK's `beforeSend` contract to the server `track` as an option: the hook receives
+ `{ type: "event", url }` and returns the event or `null` to drop it, runs before the request body
+ is built, and is fail-closed (a throwing hook is caught rather than falling through to the
+ un-edited URL). That is the shape to adopt, and it is a strictly better fit than the
+ `options.url` override this entry originally proposed — it can withhold an event entirely, which
</code_context>
<issue_to_address>
**suggestion (typo):** Consider spelling "un-edited" as "unedited".
Here, "unedited" is normally written as one word. Updating "un-edited URL" to "unedited URL" would follow standard spelling.
```suggestion
`{ type: "event", url }` and returns the event or `null` to drop it, runs before the request body
is built, and is fail-closed (a throwing hook is caught rather than falling through to the
unedited URL). That is the shape to adopt, and it is a strictly better fit than the
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| `{ type: "event", url }` and returns the event or `null` to drop it, runs before the request body | ||
| is built, and is fail-closed (a throwing hook is caught rather than falling through to the | ||
| un-edited URL). That is the shape to adopt, and it is a strictly better fit than the |
There was a problem hiding this comment.
suggestion (typo): Consider spelling "un-edited" as "unedited".
Here, "unedited" is normally written as one word. Updating "un-edited URL" to "unedited URL" would follow standard spelling.
| `{ type: "event", url }` and returns the event or `null` to drop it, runs before the request body | |
| is built, and is fail-closed (a throwing hook is caught rather than falling through to the | |
| un-edited URL). That is the shape to adopt, and it is a strictly better fit than the | |
| `{ type: "event", url }` and returns the event or `null` to drop it, runs before the request body | |
| is built, and is fail-closed (a throwing hook is caught rather than falling through to the | |
| unedited URL). That is the shape to adopt, and it is a strictly better fit than the |
The neighbouring assertion pinned the page URL to the `o:` property it was
written inline against:
/o:\s*\(?\s*requestContext[\s\S]{0,60}?\.url/
vercel/analytics#208 hoists that same expression into a `pageUrl` local so a
`beforeSend` hook can edit it before the body is built, leaving `o: pageUrl`.
The SDK reads `requestContext.url` exactly as before and the shim keeps
working -- but pinned to the old shape this test goes red on that release
claiming the redaction contract broke. False, and the opposite of the actual
news.
Match the derivation instead. The arrival of a supported API is the
`beforeSend` assertion's job to report, and only its job, so the two
conditions now fail independently and say what they mean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
✨✨ That's perfect, there is no visual difference! ✨✨ Check out the report here. |
Visual regression — no differences across 459 compared surface(s)reg-suit compared 459 surface(s) against the baseline for this
Look at the pixels
This comment is informational and never fails the build. Accounting for every changed pixel Commit |
Follow-on to #550, prompted by the upstream PR actually being opened: vercel/analytics#208
The gap
analytics-request-context.test.tscarries a tripwire asserting the server SDK still gives a caller no way to supply the event's page URL — the condition that justifies the global shim existing at all:That matches an
options.urloverride. But the request went upstream as vercel/analytics#208, which adds abeforeSendhook mirroring the browser SDK's — source readingoptions?.beforeSendandevent.url, matching neither that regex nor anything else the test looked for.So the tripwire would have stayed green through exactly the API it was watching for. We'd have bumped the dependency past the release carrying
beforeSendand kept the shim — an undocumented hook into a Vercel internal — outliving its own supported replacement, with nothing to say so. The test's own comment said "(or abeforeSend)"; the assertion never covered it.The change
Assert on
beforeSendby name as well, so the bump becomes a red test rather than something to remember. The current release has zero occurrences in that bundle, so it passes today and fires on the release that lands #208.Also records the upstream PR on the follow-up entry, which until now only said to open one — and notes that
beforeSendis a strictly better fit than theoptions.urloverride the entry originally proposed, since it can withhold an event entirely, which is what ourtrackEventalready does when it cannot redact.Owned paths
src/lib/analytics-request-context.test.tsdocs/product/follow-ups/FU-20260814-vercel-analytics-url-override.mdNo production code changes. Lint, typecheck,
check:repo,check:follow-ups, and both analytics specs green (26/26).🤖 Generated with Claude Code
Summary by Sourcery
Tighten the analytics server SDK tripwire so dependency bumps fail as soon as the upstream
beforeSendhook that can replace our shim is introduced, and update the associated follow-up documentation to reference the landed upstream PR and its preferred API shape.Documentation:
beforeSendhook and clarify that this hook is the preferred replacement for the current shim.Tests:
beforeSendhook, ensuring the test fails once the upstream replacement API ships.