wrapMiddlewaresWithSentry
Learn how to add tracing to your TanStack Start middleware.
Available since: v10.34.0
If you're using the sentryTanstackStart Vite plugin, middlewares are automatically instrumented. Use this wrapper for more granular control or when auto-instrumentation doesn't work for specific cases.
The wrapMiddlewaresWithSentry function allows you to add tracing to your TanStack Start middleware. This feature enables more granular performance monitoring and helps you gather detailed insights into the performance of individual middlewares within your application.
Pass your middlewares as an object to wrapMiddlewaresWithSentry. The function returns an array of wrapped middlewares in the same order:
app/middleware.tsimport { wrapMiddlewaresWithSentry } from "@sentry/tanstackstart-react";
import { createMiddleware } from "@tanstack/react-start";
const authMiddleware = createMiddleware().server(async ({ next }) => {
// Your auth logic
return next();
});
const loggingMiddleware = createMiddleware().server(async ({ next }) => {
// Your logging logic
return next();
});
const [wrappedAuth, wrappedLogging] = wrapMiddlewaresWithSentry({
authMiddleware,
loggingMiddleware,
});
export {
wrappedAuth as authMiddleware,
wrappedLogging as loggingMiddleware,
};
The middleware name in Sentry is automatically assigned based on the object key (e.g., authMiddleware, loggingMiddleware).
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").