Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Instrumentation for React Router 7 Framework + Vercel #16437

Unanswered
bottrall asked this question in Q&A
Discussion options

Trying to figure out how to enable backend traces with React Router 7 Framework, deployed on Vercel.

The Sentry documentation advises to create an instrument.server.js file and then import it via NODE_OPTIONS in the start script. However, Vercel doesn't allow custom start scripts, which is where the problems begin. Here are some things I've tried to get this working:

Move initialization to entry.server.tsx

The obvious next step is "Well, let's move the initialization to the entry point of the server". This enables error handling, but it does not enable tracing. This is because the relevant react-router modules are imported before the initialization occurs, meaning any and all instrumentation does not take effect.

Use Vercel's instrumentation.ts

Vercel has a way to configure custom open telemetry collection via an instrumentation.ts file. So I created the file and exported a register function as per the docs that initializes Sentry. However, it doesn't seem to do anything. My best guess is Vercel doesn't look for the file unless there's an integration with tracing enabled, as per their docs:

To use OTEL, you must enable Traces for the Integration. You can do this either during initial setup or if you already have the integration installed, select Manage next to the Integration in the Integrations tab and then select Configure.

Configure NODE_OPTIONS with an environment variable

Next, I tried to be clever and configure NODE_OPTIONS by an environment variable and added a custom build step to copy the instrument.server.js into the build directory. Unfortunately, all env vars are provided to both build and deploy. So this ends up causing your builds to fail because the file isn't present when the build process starts. As far as I can see, there is no way to configure env vars to be runtime only.

Has anyone figured out how to get this working? I'm trying this specifically with react-router, but I'm assuming this would be a problem deploying any Node service (besides next.js) to Vercel.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /