Skip to content

Commit 6628ad8

Browse files
author
Luca Forstner
authored
feat(tanstackstart): Add passthrough entrypoints for instrumentation (#15539)
1 parent 2049ade commit 6628ad8

File tree

7 files changed

+70
-44
lines changed

7 files changed

+70
-44
lines changed

packages/tanstackstart/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
"import": "./build/esm/index.client.js",
2424
"require": "./build/cjs/index.client.js"
2525
},
26-
"node": "./build/cjs/index.server.js",
27-
"import": "./build/esm/index.server.js"
26+
"node": {
27+
"import": "./build/esm/index.server.js",
28+
"require": "./build/cjs/index.server.js"
29+
}
2830
},
2931
"./import": {
3032
"import": {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* 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.
3+
*/
4+
export function sentryGlobalServerMiddlewareHandler() {
5+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6+
return function <T>(server: { next: (...args: any[]) => T }): T {
7+
return server.next();
8+
};
9+
}
10+
11+
/**
12+
* Wraps a TanStack Start stream handler with Sentry instrumentation that can be passed to `createStartHandler(...)`.
13+
*/
14+
export function wrapStreamHandlerWithSentry<H>(handler: H): H {
15+
return handler;
16+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export {};
1+
/**
2+
* Wraps a TanStack Start config.
3+
*/
4+
export function wrapVinxiConfigWithSentry<C>(config: C): C {
5+
return config;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './client';
2+
export * from './common';
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
11
export * from './config';
22
export * from './server';
3-
4-
/**
5-
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
6-
* so they should simply be a passthrough.
7-
*/
8-
export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => {
9-
if (!props.children) {
10-
return null;
11-
}
12-
13-
if (typeof props.children === 'function') {
14-
return (props.children as () => React.ReactNode)();
15-
}
16-
17-
return props.children;
18-
};
19-
20-
/**
21-
* A passthrough redux enhancer for the server that doesn't depend on anything from the `@sentry/react` package.
22-
*/
23-
export function createReduxEnhancer() {
24-
return (createStore: unknown) => createStore;
25-
}
26-
27-
/**
28-
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
29-
* SSR errors so they should simply be a passthrough.
30-
*/
31-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32-
export function withErrorBoundary<P extends Record<string, any>>(
33-
WrappedComponent: React.ComponentType<P>,
34-
): React.FC<P> {
35-
return WrappedComponent as React.FC<P>;
36-
}
37-
38-
/**
39-
* Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
40-
*/
41-
export function showReportDialog(): void {
42-
return;
43-
}
3+
export * from './common';

packages/tanstackstart/src/index.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export * from './config';
44
export * from './client';
55
export * from './server';
6+
export * from './common';
67

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
11
export * from '@sentry/node';
2+
3+
/**
4+
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
5+
* so they should simply be a passthrough.
6+
*/
7+
export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => {
8+
if (!props.children) {
9+
return null;
10+
}
11+
12+
if (typeof props.children === 'function') {
13+
return (props.children as () => React.ReactNode)();
14+
}
15+
16+
return props.children;
17+
};
18+
19+
/**
20+
* A passthrough redux enhancer for the server that doesn't depend on anything from the `@sentry/react` package.
21+
*/
22+
export function createReduxEnhancer() {
23+
return (createStore: unknown) => createStore;
24+
}
25+
26+
/**
27+
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
28+
* SSR errors so they should simply be a passthrough.
29+
*/
30+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31+
export function withErrorBoundary<P extends Record<string, any>>(
32+
WrappedComponent: React.ComponentType<P>,
33+
): React.FC<P> {
34+
return WrappedComponent as React.FC<P>;
35+
}
36+
37+
/**
38+
* Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
39+
*/
40+
export function showReportDialog(): void {
41+
return;
42+
}

0 commit comments

Comments
 (0)