feat: persist created_via on shortened urls - #268
Conversation
Store the validated X-Spoo-Client slug on UrlV2Doc at creation so link provenance survives log retention. Parser moved to shared/client_tag.py for reuse by the middleware and the shorten route. Legacy routes are untouched since legacy clients never send the header.
|
Warning Review limit reached
Next review available in: 30 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Zingzy
left a comment
There was a problem hiding this comment.
Mergeable. One decision to make consciously before this lands, inline below. Everything else verified clean.
Verified:
shorten_v1is the only v2 creation path (the emoji router only serves the emoji set, bulk has no create), so the single plumbing point covers all tagged creations; legacy stays untouched as stated.created_viaappears in no response DTO and no route serialization.- Old documents and anything cached before deploy decode fine: nullable field, None default, nothing reads it yet.
shared/client_tag.pyfits the shared/ convention exactly (pure function, no I/O, no framework import), and moving the parser out of the middleware instead of importing middleware code from a route was the right direction.
Chain note: merge bottom-up and let CI re-run after each retarget; the stacked PRs only ran check_formatting because the test workflows filter on the base branch. Full unit suite passes at this tip locally (2001).
Unknown but well-formed slugs still appear in logs, where they surface new clients without a deploy; the document field is restricted to the known first-party set so junk header values never become permanent history. Review follow-up on the created_via PR.
Stacked on #267 (chain: #265 -> #266 -> #267 -> this).
What
UrlV2Docgains acreated_viafield storing the validatedX-Spoo-Clientslug (dashboard,landing,snap,raycast,cli,bot) at creation time. Null for untagged creations.shared/client_tag.pyso the middleware and the shorten route share one implementation.POST /api/v1/shortenparses the header and passes the slug intoUrlService.createas an explicit parameter.Why
Log-based attribution expires with log retention. Persisting provenance on the document makes "where did this link come from" queryable forever, supports per-client counts straight from Mongo, and leaves room for a created-via hint in the dashboard later.
Security and performance
The stored value is never the raw header: it must match
^[a-z0-9_-]{1,32}$or it is dropped to null, so arbitrary header content cannot reach the database. No extra queries; one nullable field on insert. The field is not exposed on any public response DTO.Notes