Skip to content

Conversation

@nicohrubec
Copy link
Member

Depends on: #18989 (i.e. no need to review until that is merged)

Follow up to #18844

Extending auto-instrumentation to non-global server function middleware.

TSS function middleware docs

Closes #18847

@nicohrubec nicohrubec changed the title Nh/automatic function middleware instrumentation feat(tanstackstart-react): Auto-instrument server function middleware Jan 27, 2026
@nicohrubec nicohrubec marked this pull request as ready for review January 27, 2026 14:32
}
default:
break;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch statement skips server function middleware in start files

Medium Severity

The switch (true) statement treats file types as mutually exclusive. If a file is both a "start file" (isStartFile) AND contains createServerFn().middleware([...]) (isServerFnFile), the case isStartFile: branch matches first and breaks, preventing the server function middleware from being wrapped. The server function middleware in such files would silently fail to be auto-instrumented.

Fix in Cursor Fix in Web

@nicohrubec nicohrubec force-pushed the nh/automatic-function-middleware-instrumentation branch from e856eba to a910011 Compare January 27, 2026 16:36
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

* Wraps route middleware arrays in createFileRoute() files.
*/
export function wrapRouteMiddleware(code: string, id: string, debug: boolean): WrapResult {
return wrapMiddlewareArrays(code, id, debug, /(middleware)\s*:\s*\[([^\]]*)\]/g);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Route regex matches destructuring patterns causing invalid output

Low Severity

The wrapRouteMiddleware regex /(middleware)\s*:\s*\[([^\]]*)\]/g matches any middleware: [...] pattern, including JavaScript destructuring assignments. If a route file contains destructuring like const { middleware: [first] } = config;, it gets transformed to const { middleware: wrapMiddlewaresWithSentry({ first }) } = config; which is syntactically invalid JavaScript (function calls cannot appear on the left side of destructuring). This would cause a build failure.

Fix in Cursor Fix in Web

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-instrument server function middleware

2 participants