You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
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 viaNODE_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 aregister
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:Configure
NODE_OPTIONS
with an environment variableNext, I tried to be clever and configure
NODE_OPTIONS
by an environment variable and added a custom build step to copy theinstrument.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.Beta Was this translation helpful? Give feedback.
All reactions