feat(tanstackstart-react): Auto-instrument global middleware#18844
feat(tanstackstart-react): Auto-instrument global middleware#18844nicohrubec merged 53 commits intodevelopfrom
Conversation
This reverts commit 286f624.
size-limit report 📦
|
| return `${key}: wrapMiddlewaresWithSentry(${objContents})`; | ||
| } | ||
| // Track middlewares that couldn't be auto-wrapped | ||
| if (contents.trim()) { |
There was a problem hiding this comment.
Q: why do we trim the contents here? To make sure it's not an empty file? Just curious
There was a problem hiding this comment.
Just in case people have weird formatting and we match whitespace only when trying to match the middlewares, unlikely case but shouldn't hurt to have it
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| // Only wrap requestMiddleware and functionMiddleware in createStart() | ||
| if (!code.includes('createStart(')) { |
There was a problem hiding this comment.
Just a minor improvement which could make sense: createStart() is always in start.ts right? I think you could check if id (the filename) contains start first as it's probably faster than checking every long code string if it contains createStart(.
There was a problem hiding this comment.
Jep I think that makes sense for now, added that as an additional check. Not sure if this is gonna stay, since I will extend the auto-instrumentation for middleware to also apply to other files, but for now it's a good improvement
Follow up to #18844 Extending auto-instrumentation to non-global server request middleware. [TSS request middleware docs](https://tanstack.com/start/latest/docs/framework/react/guide/middleware#request-middleware) Closes #18846
This PR adds automatic instrumentation for global request and function middleware in TanStack Start applications.
Overview
The sentryTanstackStart Vite plugin now automatically wraps requestMiddleware and functionMiddleware arrays in
createStart()with Sentry instrumentation. This is done via a source code transformation during the build that converts:into:
Usage
Auto-instrumentation is enabled by default. To explicitly disable it:
This should give users flexibility in case things go wrong.
Implementation Details
createStart()wrapMiddlewaresWithSentryTesting
sentryTanstackStartpluginautoInstrumentMiddlewareFollow-ups
Future PRs will add support for non-global request/function middleware. This PR focuses on global middleware to make it a bit easier to review. I also want to give users a bit more control by allowing them to disable auto-instrumentation on a file-level, but this doesn't make sense yet since the current implementation only patches a single file anyways.
Closes #18845