Skip to content

fix(logging): add tRPC context to propagate URL params into logs#748

Merged
danadajian merged 2 commits intomainfrom
feat/trpc-context-url-params
Mar 26, 2026
Merged

fix(logging): add tRPC context to propagate URL params into logs#748
danadajian merged 2 commits intomainfrom
feat/trpc-context-url-params

Conversation

@danadajian
Copy link
Copy Markdown
Contributor

Summary

  • Introduces a Context type (parsed from the Referer header once per request) that makes SPA URL params available server-side — commitHash, owner, repo, bucket, etc.
  • The onError handler now uses ctx.urlParams instead of re-parsing the Referer header itself, consolidating that logic in one place
  • acceptVisualChanges now receives ctx so its INFO log automatically includes all URL params without manually enumerating owner, repo, hash, etc.
  • tRPC procedure inputs are unchanged — context is used only as a cross-cutting concern, preserving full type-safe contracts between client and server

Changes

  • app/backend/src/context.ts (new)Context type and createContext function; parses Referer header into urlParams
  • app/server.ts — passes createContext to createBunHttpHandler; onError uses ctx?.urlParams instead of inline Referer parsing
  • app/backend/src/router.tsinitTRPC.context<Context>().create(); passes ctx to acceptVisualChanges mutation
  • app/backend/src/acceptVisualChanges.ts — accepts ctx: Context as second param; spreads ctx.urlParams into the VISUAL_CHANGES_ACCEPTED info log
  • app/backend/test/acceptVisualChanges.test.ts — updated call sites to pass { urlParams: {} } as ctx

Test plan

  • Trigger acceptVisualChanges and verify the server INFO log includes owner, repo, bucket, commitHash from the browser URL
  • Trigger a tRPC error and verify the ERROR log still includes URL params via ctx.urlParams
  • bunx nx test backend passes

Generated with Claude Code

danadajian and others added 2 commits March 26, 2026 16:54
Introduces a Context type parsed from the Referer header once per
request. The onError handler now uses ctx.urlParams instead of
re-parsing the Referer itself. acceptVisualChanges receives ctx so its
INFO log automatically includes all SPA URL params (owner, repo, bucket,
commitHash, etc.) without manually listing each field.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danadajian danadajian changed the title feat(logging): add tRPC context to propagate URL params into logs fix(logging): add tRPC context to propagate URL params into logs Mar 26, 2026
@danadajian danadajian merged commit 5382f6b into main Mar 26, 2026
3 checks passed
@danadajian danadajian deleted the feat/trpc-context-url-params branch March 26, 2026 21:59
@eg-oss-ci
Copy link
Copy Markdown

🎉 This PR is included in version 1.41.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants