-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(tanstackstart-react): Trace server routes #18546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { createFileRoute } from '@tanstack/react-router'; | ||
|
|
||
| export const Route = createFileRoute('/api/hello')({ | ||
| server: { | ||
| handlers: { | ||
| GET: async () => { | ||
| return new Response('Hello, world!'); | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node'; | ||
| import type { SpanAttributes } from '@sentry/core'; | ||
| import { SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD } from '@sentry/core'; | ||
| import { | ||
| SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
| startSpan, | ||
| } from '@sentry/node'; | ||
| import { extractServerFunctionSha256 } from './utils'; | ||
|
|
||
| export type ServerEntry = { | ||
|
|
@@ -37,30 +44,39 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry { | |
| const url = new URL(request.url); | ||
| const method = request.method || 'GET'; | ||
|
|
||
| // instrument server functions | ||
| let op: string; | ||
| let spanAttributes: SpanAttributes; | ||
|
|
||
| if (url.pathname.includes('_serverFn') || url.pathname.includes('createServerFn')) { | ||
| // server function call | ||
| op = 'function.tanstackstart'; | ||
| const functionSha256 = extractServerFunctionSha256(url.pathname); | ||
| const op = 'function.tanstackstart'; | ||
|
|
||
| const serverFunctionSpanAttributes = { | ||
| spanAttributes = { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.tanstackstart.server', | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op, | ||
| 'tanstackstart.function.hash.sha256': functionSha256, | ||
| }; | ||
|
|
||
| return startSpan( | ||
| { | ||
| op: op, | ||
| name: `${method} ${url.pathname}`, | ||
| attributes: serverFunctionSpanAttributes, | ||
| }, | ||
| () => { | ||
| return target.apply(thisArg, args); | ||
| }, | ||
| ); | ||
| } else { | ||
| // API route or other server request | ||
| op = 'http.server'; | ||
| spanAttributes = { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.tanstackstart.server', | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op, | ||
| [SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD]: method, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
| }; | ||
nicohrubec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return target.apply(thisArg, args); | ||
| return startSpan( | ||
| { | ||
| op, | ||
| name: `${method} ${url.pathname}`, | ||
| attributes: spanAttributes, | ||
| }, | ||
| () => { | ||
| return target.apply(thisArg, args); | ||
| }, | ||
| ); | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Nested http.server spans duplicate root spansWrapping every |
||
| }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the correct op or if we should use something tanstack specific here