File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,5 @@ export { wrapRouteHandlerWithSentry } from './wrapRouteHandlerWithSentry';
41
41
export { wrapApiHandlerWithSentryVercelCrons } from './wrapApiHandlerWithSentryVercelCrons' ;
42
42
43
43
export { wrapMiddlewareWithSentry } from './wrapMiddlewareWithSentry' ;
44
+
45
+ export { wrapPageComponentWithSentry } from './wrapPageComponentWithSentry' ;
Original file line number Diff line number Diff line change
1
+ import { captureException } from '@sentry/core' ;
2
+
3
+ /**
4
+ * Wraps a page component with Sentry error instrumentation.
5
+ */
6
+ export function wrapPageComponentWithSentry ( pageComponent : any ) : unknown {
7
+ const patchingTarget =
8
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
9
+ typeof pageComponent . render === 'function'
10
+ ? // eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-unsafe-member-access
11
+ pageComponent . render
12
+ : typeof pageComponent === 'function'
13
+ ? pageComponent
14
+ : undefined ;
15
+
16
+ if ( patchingTarget === undefined ) {
17
+ return pageComponent ;
18
+ }
19
+
20
+ return new Proxy ( patchingTarget , {
21
+ apply ( target , thisArg , argArray ) {
22
+ try {
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
24
+ return target . apply ( thisArg , argArray ) ;
25
+ } catch ( e ) {
26
+ captureException ( e ) ;
27
+ throw e ;
28
+ }
29
+ } ,
30
+ } ) ;
31
+ }
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export const getServerSideProps =
49
49
? Sentry . wrapGetServerSidePropsWithSentry ( origGetServerSideProps , '__ROUTE__' )
50
50
: undefined ;
51
51
52
- export default pageComponent ;
52
+ export default pageComponent ? Sentry . wrapPageComponentWithSentry ( pageComponent as any ) : pageComponent ;
53
53
54
54
// Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to
55
55
// not include anything whose name matchs something we've explicitly exported above.
Original file line number Diff line number Diff line change @@ -186,3 +186,10 @@ export declare function wrapApiHandlerWithSentryVercelCrons<F extends (...args:
186
186
WrappingTarget : F ,
187
187
vercelCronsConfig : VercelCronsConfig ,
188
188
) : F ;
189
+
190
+ /**
191
+ * Wraps a page component with Sentry error instrumentation.
192
+ */
193
+ export declare function wrapPageComponentWithSentry <
194
+ F extends ( ( ...args : any [ ] ) => any ) | ( new ( ...args : any [ ] ) => any ) ,
195
+ > ( WrappingTarget : F ) : F ;
You can’t perform that action at this time.
0 commit comments