wrapMiddlewaresWithSentry

Learn how to add tracing to your TanStack Start middleware.

Available since: v10.34.0

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.ts
Copied
import { 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).

Was this helpful?
Help improve this content
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").