Skip to content

Commit 723dcec

Browse files
committed
try to implement exception monitoring in tss but doesn't work yet
1 parent a538901 commit 723dcec

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy
5252
value: 'Sentry Server Function Test Error',
5353
mechanism: {
5454
handled: false,
55+
type: 'auto.function.tanstackstart.server',
5556
},
5657
},
5758
],
@@ -61,7 +62,7 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy
6162
expect(errorEvent.transaction).toBe('/');
6263
});
6364

64-
test('Sends API route error to Sentry if manually instrumented', async ({ page }) => {
65+
test('Sends API route error to Sentry with auto-instrumentation', async ({ page }) => {
6566
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
6667
return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error';
6768
});
@@ -81,7 +82,8 @@ test('Sends API route error to Sentry if manually instrumented', async ({ page }
8182
type: 'Error',
8283
value: 'Sentry API Route Test Error',
8384
mechanism: {
84-
handled: true,
85+
handled: false,
86+
type: 'auto.function.tanstackstart.server',
8587
},
8688
},
8789
],

packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node';
1+
import { captureException, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node';
22
import { extractServerFunctionSha256 } from './utils';
33

44
export type ServerEntry = {
@@ -55,12 +55,32 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry {
5555
attributes: serverFunctionSpanAttributes,
5656
},
5757
() => {
58-
return target.apply(thisArg, args);
58+
try {
59+
return target.apply(thisArg, args);
60+
} catch (error) {
61+
captureException(error, {
62+
mechanism: {
63+
handled: false,
64+
type: 'auto.function.tanstackstart.server',
65+
},
66+
});
67+
throw error;
68+
}
5969
},
6070
);
6171
}
6272

63-
return target.apply(thisArg, args);
73+
try {
74+
return target.apply(thisArg, args);
75+
} catch (error) {
76+
captureException(error, {
77+
mechanism: {
78+
handled: false,
79+
type: 'auto.function.tanstackstart.server',
80+
},
81+
});
82+
throw error;
83+
}
6484
},
6585
});
6686
}

0 commit comments

Comments
 (0)