How to Inspect React Server Component Activity with Next.js and OpenTelemetry
42 comments
·January 23, 2025AndrewThrowaway
afavour
Difficult question to answer because it's difficult to know what you're asking. What is "it" here? Next.js? OpenTelemetry? This specific implementation?
PHP is a programming language, Rails is a framework. They're quite different propositions. What you're seeing here is equivalent to poking around in the guts of Rails, which assuredly has plenty of complexity hidden inside it. I personally have a negative reaction to this amount of stuff in a project but I feel similarly about Rails.
Next’s big “thing” is one codebase that runs both on the server and client. That introduces complexity where you might not expect it. But a Rails app and a totally disconnected JS front end will also introduce complexity, just a kind you’re more familiar with.
dbbk
Truthfully, this was never necessary. It was sold to the industry by the merchants of complexity.
You can just have a HTML file with an SPA that calls API. This is fine.
sibeliuss
Indeed. "Oh but SPAs are so complex!" Folks are completely and utterly brainwashed by Vercel's marketing.
Pondering an SSR rendered SPA with a wildcard route that calls `React.renderToPipeableStream` (or even simpler, uses `react-streaming`) and some `import()` statements sprinkled about, dropped into a tiny vite config: OMG! a handful of lines of code. Such complexity! Such slow performance! and massive bundle sizes!
Capture the market, complexify everything, then overcharge for hosting. Thanks Vercel. Love your docs!
sesm
> What exactly does it improve over lets say PHP or Rails
Uses the same code to render on server and in browser, enables moving render logic from browser to server and vice versa without doing a complete rewrite.
kobalsky
on next.js first page loads are almost instant for very complex sites with very little work on the optimization side.
it's an incredibly polished server and it does a lot of complex stuff to be so fast, but it's also well documented.
jjordan
It's far too much magic for my taste. I'm really looking forward to the first non-beta release of Tanstack Start. It offers many of the same advantages without the overkill.
logankeenan
I don’t think this answers the parent question. Database queries still needs to be made and a view still needs to be rendered. What complexity does next.js solve?
esperent
Shamelessly stollen from another comment here:
> Uses the same code to render on server and in browser, enables moving render logic from browser to server and vice versa without doing a complete rewrite.
However, the next question is, does it solve these without adding needless additional complexity of it's own?
I can't help but feel, while I'm using it, that surely it shouldn't feel this overengineered and unintuitive. I mean, I like React, and I understand it well, footguns and all.
I feel like there might be better solutions out there - even using React - and if it wasn't being heavily promoted by a large corporation then something else would be in it's place.
Also, how much of the functionality of Next.js (Image component processing, for example) is designed to funnel you into using Vercel rather than being genuinely the best solution?
kobalsky
> What complexity does next.js solve?
in our case it solves performance, it actively keeps cache warmed up preventing it from ever serving a stale page or serving a non cached hit, preloads content for fast navigation, optimizes images, it's lightweight, scales horizontally, it's stable.
it has all the bells and whistles the big boys have, for free, you almost don't need to think about it, just follow some guidance.
while people say it's too much magic (there are 4 cache layers), you are always free to pop up the hood and read the documentation, which is excellent.
jeppester
I'm really not a fan of the "what colour is your component" situation introduced by RSC.
RSC is a cool feature, but I'm still not convinced that the added churn of thinking about "colours" when building components and structuring the component tree is worth it for the benefits it gives.
csomar
It is a solution when all your developers are bootcamped on react for 6 months and don't know how to run a proper back-end. Managers like it because their front-end react dev can add a back-end feature NOW and in 1 hour.
davedx
It’s awful and I’m pretty sad that it seems the entire nodejs community has adopted next.js as standard. All projects I’ve been involved with use it and none of them use any SSR at all.
bripkens
It adds notable complexity, and I sense that the whole server/client side component reality is wildly ill-understood.
tresil
Great write up. We’ve migrated to NextJs App Router where I work. While RSCs introduce a certain level of complexity, we’ve appreciated their benefits. The telemetry on the backend is something we’ve been looking to improve, and there doesn’t seem to be a lot of info out there, so this helps.
ilrwbwrkhv
Just reading that fills me with dread
sroussey
This reminds me why I added server timing to the chrome dev tools.
The basic thing I instrumented in my projects was a count of calls to APIs and their total time. Same for DB access. Then push these out as server timings via http headers and see them in chrome.
Quick and dirty way to see what the server call was generally doing.
In addition to adding that to chrome dev tools, I had an extension that would consolidate all network requests for a given page and summarize them. Nice to show various teams how many darn db queries they were doing just to load a page.
sibeliuss
I hate RSC so much. Most hated technology of them all. And this very helpful / necessary blog post is infuriating, given that not so long ago the entirety of the react stack was capable of being held in one's head. It took very little expertise to make something that worked perfectly fine for most users.
Those days are gone. Scale your Next.js RSC app to anything larger than a toy or marketing site and get f'ing burned.
alexanderchr
Just got handed a next app that is currently just beyond toy stage. In what way am I about to get burned? Genuinely curious for opinions
sibeliuss
Well, to start with, you'll need to study this dreadful blog post on inspecting RSC activity. And then read this: https://www.comfydeploy.com/blog/you-dont-need-nextjs
Are you using the pages router or the app router? If you're using the pages router you'll probably be fine.
bripkens
Web browser developer tools are incredible, but what do you do when more of your work is shifting to the server? These tools are no longer available or only provide minimal insights. Bye-bye network tab and source tab! That's a challenge for developers adopting React Server Components (RSCs).
blenderob
Not quite sure what the big challenge is here. If the work is shifting to the server, you debug on the server! Read the logs. Attach a debugger. Instrument the code if you must! All that usual stuff. This is how web-development has been since the days of CGI. What am I missing?
nottorp
> Read the logs.
I've noted a tendency to not log stuff in some js-first devs i know ... they all say 'i'll reproduce it locally'...
gunian
how else would one reproduce a bug? in production?
or is it best practice to patch with logs only without reproduction
bripkens
What's missing are the summaries that web developers are commonly used to. For example, the network tab in the developer tools. It is arguably very handy for development – and often more actionable than having to step through individual requests.
But you are of course also right that you can just attach a debugger. That's also called out in the article.
sroussey
And these days, you use the same browser debug tools to attach to nodejs.
sesm
Yes, but it's missing the network tab, see https://github.com/nodejs/diagnostics/issues/75
mmanciop
For local development, yes. But I see that almost never done in production settings, especially with containerized workloads. Is there a neat way to do it in Kubernetes?
Excuse my ignorance but why does it look so complicated and unnecessary? What exactly does it improve over lets say PHP or Rails or whatever?