Skip to content

Commit 915e6b6

Browse files
committed
start span for other server requests
1 parent 9f29bfc commit 915e6b6

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ test('Sends a server function transaction for a nested server function only if i
102102
test('Sends an API route transaction with auto-instrumentation', async ({ page }) => {
103103
const transactionEventPromise = waitForTransaction('tanstackstart-react', transactionEvent => {
104104
return (
105-
transactionEvent?.contexts?.trace?.op === 'http.server' &&
106-
transactionEvent?.transaction === 'GET /api/hello'
105+
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'GET /api/hello'
107106
);
108107
});
109108

@@ -125,11 +124,11 @@ test('Sends an API route transaction with auto-instrumentation', async ({ page }
125124
description: 'GET /api/hello',
126125
op: 'http.server',
127126
origin: 'auto.http.tanstackstart.server',
128-
source: 'route',
129127
data: {
130128
'sentry.op': 'http.server',
131129
'sentry.origin': 'auto.http.tanstackstart.server',
132-
'http.route': '/api/hello',
130+
'sentry.source': 'route',
131+
'http.request.method': 'GET',
133132
},
134133
}),
135134
]),

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node';
1+
import type { SpanAttributes } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD } from '@sentry/core';
3+
import {
4+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
5+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
6+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
7+
startSpan,
8+
} from '@sentry/node';
29
import { extractServerFunctionSha256 } from './utils';
310

411
export type ServerEntry = {
@@ -42,7 +49,7 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry {
4249
const functionSha256 = extractServerFunctionSha256(url.pathname);
4350
const op = 'function.tanstackstart';
4451

45-
const serverFunctionSpanAttributes = {
52+
const serverFunctionSpanAttributes: SpanAttributes = {
4653
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.tanstackstart.server',
4754
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
4855
'tanstackstart.function.hash.sha256': functionSha256,
@@ -60,7 +67,25 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry {
6067
);
6168
}
6269

63-
return target.apply(thisArg, args);
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+
79+
return startSpan(
80+
{
81+
op: op,
82+
name: `${method} ${url.pathname}`,
83+
attributes: httpServerSpanAttributes,
84+
},
85+
() => {
86+
return target.apply(thisArg, args);
87+
},
88+
);
6489
},
6590
});
6691
}

0 commit comments

Comments
 (0)