Skip to content

Commit 549d0b1

Browse files
committed
refactor
1 parent 915e6b6 commit 549d0b1

2 files changed

Lines changed: 17 additions & 28 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ test('Sends an API route transaction with auto-instrumentation', async ({ page }
110110

111111
const transactionEvent = await transactionEventPromise;
112112

113-
console.log('transactionEvent: ', transactionEvent);
114-
115113
expect(transactionEvent).toEqual(
116114
expect.objectContaining({
117115
transaction: 'GET /api/hello',

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,34 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry {
4444
const url = new URL(request.url);
4545
const method = request.method || 'GET';
4646

47-
// instrument server functions
47+
let op: string;
48+
let spanAttributes: SpanAttributes;
49+
4850
if (url.pathname.includes('_serverFn') || url.pathname.includes('createServerFn')) {
51+
// server function call
52+
op = 'function.tanstackstart';
4953
const functionSha256 = extractServerFunctionSha256(url.pathname);
50-
const op = 'function.tanstackstart';
51-
52-
const serverFunctionSpanAttributes: SpanAttributes = {
54+
spanAttributes = {
5355
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.tanstackstart.server',
5456
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
5557
'tanstackstart.function.hash.sha256': functionSha256,
5658
};
57-
58-
return startSpan(
59-
{
60-
op: op,
61-
name: `${method} ${url.pathname}`,
62-
attributes: serverFunctionSpanAttributes,
63-
},
64-
() => {
65-
return target.apply(thisArg, args);
66-
},
67-
);
59+
} else {
60+
// API route or other server request
61+
op = 'http.server';
62+
spanAttributes = {
63+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.tanstackstart.server',
64+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
65+
[SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD]: method,
66+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
67+
};
6868
}
6969

70-
// instrument other server requests including API routes
71-
const op = 'http.server';
72-
const httpServerSpanAttributes: SpanAttributes = {
73-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.tanstackstart.server',
74-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
75-
[SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD]: method,
76-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
77-
};
78-
7970
return startSpan(
8071
{
81-
op: op,
72+
op,
8273
name: `${method} ${url.pathname}`,
83-
attributes: httpServerSpanAttributes,
74+
attributes: spanAttributes,
8475
},
8576
() => {
8677
return target.apply(thisArg, args);

0 commit comments

Comments
 (0)