Skip to content

Commit 0f425fd

Browse files
committed
stuff works
1 parent 6de8816 commit 0f425fd

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import type { ServerEntry } from '@tanstack/react-start/server-entry';
55

66
const requestHandler: ServerEntry = withSentry({
77
fetch(request: Request) {
8-
console.log('requestHandler fetch');
9-
console.log(request);
108
return handler.fetch(request);
119
},
1210
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('Sends a server function transaction', async ({ page }) => {
2121
expect(transactionEvent?.spans).toEqual(
2222
expect.arrayContaining([
2323
expect.objectContaining({
24-
description: 'server.fetch',
24+
description: expect.stringContaining('/_serverFn/'),
2525
op: 'function.tanstackstart',
2626
origin: 'auto.function.tanstackstart.serverFn',
2727
data: {

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,42 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSp
33
export type ServerEntry = { fetch?: (request: Request) => Promise<unknown> };
44

55
/**
6+
* This function can be used to wrap the server entry request handler to add tracing to server-side functionality.
7+
* You must explicitly define a server entry point in your application for this to work. This is done by passing the request handler to the `createServerEntry` function.
8+
* For more information about the server entry point, see the [TanStack Start documentation](https://tanstack.com/start/docs/server-entry).
69
*
7-
* @param serverEntry - server entry function to wrap
8-
* @returns - wrapped server entry function
10+
* @example
11+
* ```ts
12+
* import { withSentry } from '@sentry/tanstackstart-react';
13+
*
14+
* import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
15+
* import type { ServerEntry } from '@tanstack/react-start/server-entry';
16+
*
17+
* const requestHandler: ServerEntry = withSentry({
18+
* fetch(request: Request) {
19+
* return handler.fetch(request);
20+
* },
21+
* });
22+
*
23+
* export default serverEntry = createServerEntry(requestHandler);
24+
* ```
25+
*
26+
* @param serverEntry - request handler to wrap
27+
* @returns - wrapped request handler
928
*/
1029
export function withSentry(serverEntry: ServerEntry): ServerEntry {
1130
if (serverEntry.fetch) {
1231
serverEntry.fetch = new Proxy<typeof serverEntry.fetch>(serverEntry.fetch, {
1332
apply: async (target, thisArg, args) => {
14-
console.log(args[0].url?.toString());
15-
console.log('serverFn: ', args[0].url?.includes('_serverFn') || args[0].url?.includes('createServerFn'));
16-
if (args[0].url?.includes('_serverFn') || args[0].url?.includes('createServerFn')) {
33+
const request: Request = args[0];
34+
35+
// instrument server functions
36+
if (request.url?.includes('_serverFn') || request.url?.includes('createServerFn')) {
1737
const op = 'function.tanstackstart';
18-
console.log('fetch with startSpan');
1938
return await startSpan(
2039
{
2140
op: op,
22-
name: 'server.fetch', // TODO: use the actual server function name
41+
name: request.url,
2342
attributes: {
2443
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.tanstackstart.serverFn',
2544
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
@@ -31,7 +50,6 @@ export function withSentry(serverEntry: ServerEntry): ServerEntry {
3150
);
3251
}
3352

34-
console.log('fetch without startSpan');
3553
return await target.apply(thisArg, args);
3654
},
3755
});

0 commit comments

Comments
 (0)