Skip to content

feat(tanstackstart-react): Show readable server function names in traces#21190

Merged
nicohrubec merged 1 commit into
developfrom
feat/tanstack-start-server-fn-name
May 27, 2026
Merged

feat(tanstackstart-react): Show readable server function names in traces#21190
nicohrubec merged 1 commit into
developfrom
feat/tanstack-start-server-fn-name

Conversation

@nicohrubec
Copy link
Copy Markdown
Member

@nicohrubec nicohrubec commented May 27, 2026

Uses serverFnMeta from the TanStack Start function middleware context to replace hash-based server function span names with human-readable ones (e.g. GET /_serverFn/greet instead of GET /_serverFn/a10e70b3...). Also attaches function metadata (id, filename) as span attributes. The span still gets started in wrapFetchWithSentry but then updated with the available metadata in the global function middleware. I only update the custom server function span itself and don't update the http span, so that one will now show up with a description of GET /serverFn/* (see trace below). We can certainly think about also updating the http span, but I wasn't sure how to name this if there is for instance multiple nested server function calls. Happy to hear any thoughts on this.

The tanstackstart.function.hash.sha256 span attribute has been renamed to tanstackstart.function.id (should be more accurate name given that that is the name the framework itself uses for the metadata).

Example trace from local testing:
Screenshot 2026-05-27 at 14 01 39
Screenshot 2026-05-27 at 14 01 58

Fixes #21185

@nicohrubec nicohrubec force-pushed the feat/tanstack-start-server-fn-name branch from f01c86c to e110c50 Compare May 27, 2026 10:58
Comment thread packages/tanstackstart-react/src/server/globalMiddleware.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8d0efef. Configure here.

Comment thread packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts
@nicohrubec nicohrubec force-pushed the feat/tanstack-start-server-fn-name branch from 8d0efef to e5733b0 Compare May 27, 2026 11:28
'sentry.origin': 'auto.function.tanstackstart.server',
'tanstackstart.function.hash.sha256': expect.any(String),
}),
'sentry.source': 'route',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this because from what I can see in my experiments the name here never has parameters so we don't need relay-side route parametrization

Use `serverFnMeta` from the function middleware context to replace hash-based
server function span names with human-readable ones.

Fixes #21185

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicohrubec nicohrubec force-pushed the feat/tanstack-start-server-fn-name branch from e84a02f to aa1ed88 Compare May 27, 2026 11:45
@nicohrubec nicohrubec marked this pull request as ready for review May 27, 2026 12:07
@nicohrubec nicohrubec requested a review from a team as a code owner May 27, 2026 12:07
@nicohrubec nicohrubec requested review from chargome, mydea and s1gr1d and removed request for a team and mydea May 27, 2026 12:07
Comment on lines 26 to 40
expect(transactionEvent?.spans).toEqual([
expect.objectContaining({
description: expect.stringContaining('GET /_serverFn/'),
description: 'GET /_serverFn/testLog',
op: 'function.tanstackstart',
origin: 'auto.function.tanstackstart.server',
data: expect.objectContaining({
data: {
'sentry.op': 'function.tanstackstart',
'sentry.origin': 'auto.function.tanstackstart.server',
'tanstackstart.function.hash.sha256': expect.any(String),
}),
'sentry.source': 'route',
'tanstackstart.function.id': expect.any(String),
'tanstackstart.function.filename': 'src/routes/test-serverFn.tsx',
},
}),
]);
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that .objectContaining might ignore fields that matter as it does not to an equality check (is successful when one item is missing). You can either do toEqual or toBe on each individual item you want to check.

Same for all other checks in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's why I removed the .objectContaining, so this should now do an exact match

Comment on lines +87 to +89
server: createSentryFunctionMiddlewareHandler('auto.middleware.tanstackstart.server_function') as (
...args: any[] // eslint-disable-line @typescript-eslint/no-explicit-any
) => any, // eslint-disable-line @typescript-eslint/no-explicit-any
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why is the createSentryMiddlewareHandler removed from here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createSentryMiddlewareHandler only does a try catch essentially, so this is replaced with the new handler that also includes the logic to update the span with the metadata. createSentryMiddlewareHandler is still used for the global middleware that captures exceptions from API routes

@nicohrubec nicohrubec merged commit 41858f2 into develop May 27, 2026
45 checks passed
@nicohrubec nicohrubec deleted the feat/tanstack-start-server-fn-name branch May 27, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TanStack Start: show server function name in traces, errors and other places

2 participants