Skip to content

feat(tanstackstart): Add passthrough entrypoints for instrumentation #15539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/tanstackstart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"import": "./build/esm/index.client.js",
"require": "./build/cjs/index.client.js"
},
"node": "./build/cjs/index.server.js",
"import": "./build/esm/index.server.js"
"node": {
"import": "./build/esm/index.server.js",
"require": "./build/cjs/index.server.js"
}
},
"./import": {
"import": {
Expand Down
16 changes: 16 additions & 0 deletions packages/tanstackstart/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* A middleware handler that can be passed to TanStack Start's `createMiddleware().server(...)` method as [global middleware](https://tanstack.com/start/latest/docs/framework/react/middleware#global-middleware) for instrumenting server functions.
*/
export function sentryGlobalServerMiddlewareHandler() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function <T>(server: { next: (...args: any[]) => T }): T {
return server.next();
};
}

/**
* Wraps a TanStack Start stream handler with Sentry instrumentation that can be passed to `createStartHandler(...)`.
*/
export function wrapStreamHandlerWithSentry<H>(handler: H): H {
return handler;
}
7 changes: 6 additions & 1 deletion packages/tanstackstart/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export {};
/**
* Wraps a TanStack Start config.
*/
export function wrapVinxiConfigWithSentry<C>(config: C): C {
return config;
}
1 change: 1 addition & 0 deletions packages/tanstackstart/src/index.client.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './client';
export * from './common';
42 changes: 1 addition & 41 deletions packages/tanstackstart/src/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
export * from './config';
export * from './server';

/**
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
* so they should simply be a passthrough.
*/
export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => {
if (!props.children) {
return null;
}

if (typeof props.children === 'function') {
return (props.children as () => React.ReactNode)();
}

return props.children;
};

/**
* A passthrough redux enhancer for the server that doesn't depend on anything from the `@sentry/react` package.
*/
export function createReduxEnhancer() {
return (createStore: unknown) => createStore;
}

/**
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
* SSR errors so they should simply be a passthrough.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function withErrorBoundary<P extends Record<string, any>>(
WrappedComponent: React.ComponentType<P>,
): React.FC<P> {
return WrappedComponent as React.FC<P>;
}

/**
* Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
*/
export function showReportDialog(): void {
return;
}
export * from './common';
1 change: 1 addition & 0 deletions packages/tanstackstart/src/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export * from './config';
export * from './client';
export * from './server';
export * from './common';

import type { Client, Integration, Options, StackParser } from '@sentry/core';

Expand Down
41 changes: 41 additions & 0 deletions packages/tanstackstart/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
export * from '@sentry/node';

/**
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
* so they should simply be a passthrough.
*/
export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => {
if (!props.children) {
return null;
}

if (typeof props.children === 'function') {
return (props.children as () => React.ReactNode)();
}

return props.children;
};

/**
* A passthrough redux enhancer for the server that doesn't depend on anything from the `@sentry/react` package.
*/
export function createReduxEnhancer() {
return (createStore: unknown) => createStore;
}

/**
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
* SSR errors so they should simply be a passthrough.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function withErrorBoundary<P extends Record<string, any>>(
WrappedComponent: React.ComponentType<P>,
): React.FC<P> {
return WrappedComponent as React.FC<P>;
}

/**
* Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
*/
export function showReportDialog(): void {
return;
}
Loading