Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Jan 30, 2026

Automatically copy instrument.server.mjs into the server build output after build. Output directory is auto-detected based on the deployment target (Nitro, Cloudflare, Netlify). We also provide instrumentationFilePath and serverOutputDir options as escape hatches if auto-detection doesn't work.

To detect the deployment target we search the vite plugin list for plugins with names containing the deployment target (e.g. nitro). In the nitro case we then read the target directory from nitroEnv.build.rollupOptions.output. For netlify and cloudflare we assume dist/server.

Limitations:

  • Currently by default only works for instrument.server.mjs files in the root of the project. This is how we ask users to set it up in the docs and has basically no performance overhead. For other cases users will have to use the override options as it is now, but we could definitely think about extending that.

Closes #18665

@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

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.
⚠️ 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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,751 - 8,882 -1%
GET With Sentry 1,659 19% 1,756 -6%
GET With Sentry (error only) 5,993 68% 6,178 -3%
POST Baseline 1,199 - 1,182 +1%
POST With Sentry 595 50% 592 +1%
POST With Sentry (error only) 1,058 88% 1,038 +2%
MYSQL Baseline 3,249 - 3,315 -2%
MYSQL With Sentry 427 13% 446 -4%
MYSQL With Sentry (error only) 2,637 81% 2,680 -2%

View base workflow run

@nicohrubec nicohrubec marked this pull request as ready for review February 10, 2026 15:51
}

const instrumentationFileName = options?.instrumentationFilePath || 'instrument.server.mjs';
const instrumentationSource = path.resolve(process.cwd(), instrumentationFileName);
Copy link

Choose a reason for hiding this comment

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

Bug: The source instrumentation file path is resolved using process.cwd(), while the destination uses resolvedConfig.root. This will fail when these paths differ, like in monorepos.
Severity: MEDIUM

Suggested Fix

In the configResolved hook, store resolvedConfig.root in a closure-scoped variable. Then, in the closeBundle hook, use this stored variable instead of process.cwd() to resolve the source instrumentation file's path. This ensures both source and destination paths are resolved relative to the same Vite project root.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/tanstackstart-react/src/vite/copyInstrumentationFile.ts#L75

Potential issue: The plugin resolves the destination directory for the instrumentation
file using `resolvedConfig.root` but resolves the source file path using
`process.cwd()`. This inconsistency causes a problem when Vite is run with a custom root
directory or in a monorepo setup, as `process.cwd()` and `resolvedConfig.root` will
differ. In such cases, the plugin will fail to find the `instrument.server.mjs` file at
the expected location (relative to the project root), causing it to be silently omitted
from the final build, defeating the purpose of the plugin.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

Automatically move server config file to build output

1 participant