Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Dec 15, 2025

This PR adds tracing for tss server functions. To achieve this I added a new wrapFetchWithSentry wrapper that can be used to instrument the tss server entry point:

import { wrapFetchWithSentry } from '@sentry/tanstackstart-react';

import handler, { createServerEntry } from '@tanstack/react-start/server-entry';

const requestHandler = wrapFetchWithSentry({
  fetch(request: Request) {
    return handler.fetch(request);
  },
});

export default createServerEntry(requestHandler);

With this we get spans for server functions executed via fetch calls to the server. A limitation of this approach is that out-of-the-box this will only start a single span for the initial request made to the server. So for instance if a server function calls another server function, we will still only get a single span for the outer server function and users would need to wrap the inner call manually.

Screenshot from my sample app with the current state:
Screenshot 2025-12-17 at 11 11 33

Tests added:

  • E2E: Basic transaction test to verify that we get spans if a server function is executed.
  • E2E: Another transaction test documenting that users need to manually wrap "nested" server functions.
  • Unit: Tests to verify the sha256 extraction.

Closes #18287

@nicohrubec nicohrubec self-assigned this Dec 15, 2025
@nicohrubec nicohrubec marked this pull request as ready for review December 15, 2025 16:39
@nicohrubec nicohrubec requested a review from TkDodo December 16, 2025 13:05
@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 24.81 kB - -
@sentry/browser - with treeshaking flags 23.3 kB - -
@sentry/browser (incl. Tracing) 41.58 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.18 kB - -
@sentry/browser (incl. Tracing, Replay) 80.16 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.9 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.85 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 97.08 kB - -
@sentry/browser (incl. Feedback) 41.52 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB - -
@sentry/browser (incl. FeedbackAsync) 34.48 kB - -
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.78 kB - -
@sentry/vue 29.27 kB - -
@sentry/vue (incl. Tracing) 43.39 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.23 kB - -
CDN Bundle (incl. Tracing) 42.22 kB - -
CDN Bundle (incl. Tracing, Replay) 78.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 84.39 kB - -
CDN Bundle - uncompressed 80.02 kB - -
CDN Bundle (incl. Tracing) - uncompressed 125.37 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.91 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.67 kB - -
@sentry/nextjs (client) 46 kB - -
@sentry/sveltekit (client) 41.95 kB - -
@sentry/node-core 51.6 kB - -
@sentry/node 161.48 kB -0.01% -1 B 🔽
@sentry/node - without tracing 93.03 kB - -
@sentry/aws-serverless 108.54 kB -0.01% -1 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,883 - 8,745 +2%
GET With Sentry 1,794 20% 1,748 +3%
GET With Sentry (error only) 6,204 70% 6,043 +3%
POST Baseline 1,210 - 1,200 +1%
POST With Sentry 611 50% 580 +5%
POST With Sentry (error only) 1,077 89% 1,061 +2%
MYSQL Baseline 3,355 - 3,310 +1%
MYSQL With Sentry 561 17% 457 +23%
MYSQL With Sentry (error only) 2,706 81% 2,676 +1%

View base workflow run

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

LGTM overall, happy to go with this if you decide withSentry is the right api.

@nicohrubec nicohrubec merged commit 2c45b73 into develop Dec 17, 2025
35 checks passed
@nicohrubec nicohrubec deleted the nh/tss-server-fn-tracing branch December 17, 2025 11:50
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.

Server functions tracing

3 participants