-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
-
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.
Beta Was this translation helpful? Give feedback.