Skip to content

feat(bundlers): Add orchestrion bundler plugins#22124

Open
timfish wants to merge 4 commits into
developfrom
timfish/feat/orchestrion-bundler-plugins
Open

feat(bundlers): Add orchestrion bundler plugins#22124
timfish wants to merge 4 commits into
developfrom
timfish/feat/orchestrion-bundler-plugins

Conversation

@timfish

@timfish timfish commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

There was already a Vite bundler plugin for orchestrion that included our instrumentations but this PR adds the ability to include additional instrumentations and adds plugins for other bundlers.

I left the Bun plugin out of @sentry/server-utils because there is already one in the Bun package and I can't see it being used anywhere else 🤷‍♂️

@timfish timfish marked this pull request as ready for review July 9, 2026 02:36
@timfish timfish requested a review from a team as a code owner July 9, 2026 02:36
@timfish timfish requested review from JPeer264, andreiborza, isaacs and mydea and removed request for a team July 9, 2026 02:36
Comment on lines -14 to -18
type UnknownPlugin = any;

import codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/vite';
import MagicString from 'magic-string';
import { INSTRUMENTED_MODULE_NAMES, SENTRY_INSTRUMENTATIONS } from '../config';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The Rollup plugin spreads the upstream plugin and then redefines the options hook, which will silently drop any logic from the original hook.
Severity: MEDIUM

Suggested Fix

Instead of overwriting the options hook, the new implementation should call the original hook if it exists. A safer pattern would be to capture the original options hook before spreading, and then call it from within the new hook implementation to ensure both sets of logic are executed.

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/server-utils/src/orchestrion/bundler/vite.ts#L14-L18

Potential issue: In `rollup.ts`, the code creates a new Rollup plugin by spreading the
properties of the upstream `@apm-js-collab/code-transformer-bundler-plugins/rollup`
plugin and then defining a new `options` hook. This pattern overwrites the `options`
hook from the upstream plugin. If the upstream plugin has its own `options` hook for
configuration, which is a common pattern for bundler plugins, its logic will be silently
lost. This could lead to incorrect bundler behavior or misconfiguration, as the upstream
plugin's setup logic would not be executed.

Also affects:

  • packages/server-utils/src/orchestrion/bundler/rollup.ts:18~24

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f9aaa97. Configure here.

* ```
*/
export function sentryOrchestrionPlugin(options: PluginOptions = {}): ReturnType<typeof codeTransformer> {
return codeTransformer(orchestrionTransformOptions(options));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Webpack skips externals stripping

Medium Severity

The new webpack orchestrion plugin only forwards to the upstream transformer and never adjusts externals, unlike the Rollup, esbuild, and Vite wrappers. When instrumented packages stay external, webpack resolves them from node_modules at runtime and the transform never runs, so channel injection silently fails.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f9aaa97. Configure here.

export function sentryOrchestrionPlugin(options: PluginOptions = {}): ReturnType<typeof codeTransformer> {
const transformer = codeTransformer(orchestrionTransformOptions(options)) as unknown as {
setup: (build: EsbuildPluginBuild) => void;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Double cast lacks explanation

Low Severity

The esbuild plugin uses an as unknown as { setup: ... } double cast without a comment explaining why safer typing is not possible. SDK review guidelines require a comment for each such cast.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit f9aaa97. Configure here.

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.

1 participant