Skip to content

feat(server-utils): Allow integrations to be part of marker#22094

Open
JPeer264 wants to merge 2 commits into
developfrom
jp/orchestrion-integrations
Open

feat(server-utils): Allow integrations to be part of marker#22094
JPeer264 wants to merge 2 commits into
developfrom
jp/orchestrion-integrations

Conversation

@JPeer264

@JPeer264 JPeer264 commented Jul 8, 2026

Copy link
Copy Markdown
Member

This adds a way to add orchestrion integrations into the bundle during the build time and dev for only that things which are instrumented by Orchestrion.

Problem

We can't use Sentry.experimentalUseDiagnosticsChannelInjection(), because the bundle would blow up, even if only one integration would be needed.

I was in between adding a new transform to every single config, but that would have meant that the bundle size would increase for the runtime config, which I didn't want to do, so I added a toSubscribeInjections function that is separately exported from all configs (not sure if that scales well)

Solution (for now)

__SENTRY_ORCHESTRION__.integrations is now added with a list of integrations via a virtual import with side effects. The registerChannelIntegrations() is actually here to do that. (In the future this list can be adapted in the best case, depending on what is really needed).

This is explicitly not adding anything into Cloudflare to keep it small, this is in the PR stack further up.

@JPeer264 JPeer264 self-assigned this Jul 8, 2026
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch 3 times, most recently from 332ece3 to 31572d5 Compare July 14, 2026 15:40
@JPeer264

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 31572d5 to 0ab49df Compare July 14, 2026 15:43
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

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

Path Size % Change Change
@sentry/browser 27.74 kB - -
@sentry/browser - with treeshaking flags 26.19 kB - -
@sentry/browser (incl. Tracing) 46.57 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.34 kB - -
@sentry/browser (incl. Tracing, Replay) 85.83 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.47 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.19 kB - -
@sentry/browser (incl. Feedback) 44.92 kB - -
@sentry/browser (incl. sendFeedback) 32.54 kB - -
@sentry/browser (incl. FeedbackAsync) 37.67 kB - -
@sentry/browser (incl. Metrics) 28.84 kB - -
@sentry/browser (incl. Logs) 29.07 kB - -
@sentry/browser (incl. Metrics & Logs) 29.76 kB - -
@sentry/react 29.54 kB - -
@sentry/react (incl. Tracing) 48.82 kB - -
@sentry/vue 33.17 kB - -
@sentry/vue (incl. Tracing) 48.55 kB - -
@sentry/svelte 27.77 kB - -
CDN Bundle 30.14 kB - -
CDN Bundle (incl. Tracing) 48.52 kB - -
CDN Bundle (incl. Logs, Metrics) 31.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.83 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.97 kB - -
CDN Bundle (incl. Tracing, Replay) 86.04 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.1 kB - -
CDN Bundle - uncompressed 89.85 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.64 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.29 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.84 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.57 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.53 kB - -
@sentry/nextjs (client) 51.38 kB - -
@sentry/sveltekit (client) 47 kB - -
@sentry/core/server 78.71 kB - -
@sentry/core/browser 65.08 kB - -
@sentry/node-core 63.21 kB - -
@sentry/node 125.54 kB - -
@sentry/node (incl. diagnostics channel injection) 148.37 kB +0.19% +277 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB -0.01% -2 B 🔽
@sentry/node/light 51.33 kB - -
@sentry/node - without tracing 74.7 kB -0.01% -2 B 🔽
@sentry/aws-serverless 83.92 kB - -
@sentry/cloudflare (withSentry) - minified 182.1 kB - -
@sentry/cloudflare (withSentry) 450.9 kB - -

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch 4 times, most recently from 95c6874 to c0dfebc Compare July 15, 2026 09:20
@JPeer264
JPeer264 marked this pull request as ready for review July 15, 2026 09:20
@JPeer264
JPeer264 requested a review from a team as a code owner July 15, 2026 09:20
@JPeer264
JPeer264 requested review from chargome, isaacs, s1gr1d and timfish and removed request for a team July 15, 2026 09:20
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/test/orchestrion/vite-register-integrations.test.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from b341ad9 to 06971c5 Compare July 15, 2026 10:59
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/test/orchestrion/vite-register-integrations.test.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from e7262f3 to 6713fc3 Compare July 15, 2026 11:38
Comment on lines +178 to +181
const require = createRequire(import.meta.url);
const packageRoot = dirname(require.resolve('@sentry/server-utils/package.json'));
// This avoids any backslash-escaping concerns on Windows
const resolvedRegisterModule = resolve(packageRoot, 'build/esm/orchestrion/index.js').replace(/\\/g, '/');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not 100% clear what all this nastiness is for!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had it before, like I had it now pushed. But clankers were alwys like "You can't do this! You need to do it like this because XY". Since I have no idea what is hacky in bundlers and what not I went for this. I moved now point directly to the package, which also works for now.

Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 6713fc3 to 0d56181 Compare July 16, 2026 06:39
Comment thread packages/server-utils/src/orchestrion/index.ts Outdated
Comment thread packages/server-utils/src/orchestrion/detect.ts Outdated
Comment thread packages/server-utils/src/orchestrion/index.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 4465fbd to b59ebba Compare July 16, 2026 07:33
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/index.ts Outdated
Comment thread packages/server-utils/src/orchestrion/index.ts Outdated

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure the best way forward to be honest, but I think there are some conflicts to comb through between this and the other orchestrion bundler stuff.

Comment thread packages/server-utils/package.json Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
Comment thread packages/server-utils/src/orchestrion/bundler/vite.ts Outdated
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from b59ebba to 157e383 Compare July 17, 2026 06:57
Comment thread packages/server-utils/src/orchestrion/bundler/subscribeInjection.ts
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 157e383 to 6755627 Compare July 17, 2026 07:21
`${importStmt}\n` +
'(globalThis.__SENTRY_ORCHESTRION__ ??= {}).integrations ??= new Map();\n' +
`globalThis.__SENTRY_ORCHESTRION__.integrations.set(${JSON.stringify(exportName)}, ${exportName});\n` +
`__sentryGetClient()?.addIntegration(${exportName}());`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note: This one is something where I don't know how else to solve. I have a test in the GH stack above that is using MYSQL within Cloudflare. The lib/Connection.js is being required inline in some file, that means that this file is only being executed once this file is called.

Since at this time the client got already set up, and .integrations.push() would be too late for the first execution and only .addIntegration() would work. Not sure if there are better ways to do this.

I tried to kinda move that snipped then out of this file, but that didn't work that nicely

// creates the Map; keying by export name dedupes packages split across files.
return (
`${importStmt}\n` +
'(globalThis.__SENTRY_ORCHESTRION__ ??= {}).integrations ??= new Map();\n' +

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note: This is now a new Map() instead of a [], as it could be that multiple files are modified by Orchestrion and this would not add any duplicates.

Comment on lines +91 to +92
const directiveIndex = node.body.findIndex(n => n.type === 'ExpressionStatement' && n.directive === 'use strict');
node.body.splice(directiveIndex + 1, 0, ...statements);

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: Code injection in ESM modules occurs at index 0 because 'use strict' is not found. This can place expressions before existing import statements, causing a syntax error.
Severity: MEDIUM

Suggested Fix

The injection logic should be updated to handle ESM modules correctly. Instead of searching for 'use strict', the code should parse the module to find the last import statement and inject the new code after it. If no imports exist, the code can be injected at the beginning of the module.

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/subscribeInjection.ts#L91-L92

Potential issue: The code injects instrumentation by finding a `'use strict'` directive
and inserting statements after it. However, ESM modules are strict by default and lack
this directive. In such cases, `findIndex` returns `-1`, and the code incorrectly
splices new statements at the beginning of the module's body (`node.body.splice(0,
...)`). If the target ESM module contains its own `import` statements, this injection
will place other expression statements before them, which is a syntax error in
JavaScript. While existing tests do not cover this specific scenario, the logical flaw
could break instrumentation for any ESM module that has top-level imports.

@JPeer264
JPeer264 requested review from isaacs and timfish July 17, 2026 07:29
@JPeer264

Copy link
Copy Markdown
Member Author

bugbot run

@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 3 potential issues.

Fix All in Cursor

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

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6755627. Configure here.

{ exportName: 'redisChannelIntegration', modules: ['redis', '@redis/client'] },
{ exportName: 'ioredisChannelIntegration', modules: ['ioredis'] },
{ exportName: 'dataloaderChannelIntegration', modules: ['dataloader'] },
] as const satisfies ReadonlyArray<{ exportName: string; modules: readonly string[] }>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AWS subscribe mapping missing

Medium Severity

awsSdkSubscribeInjection is included in SUBSCRIBE_INJECTIONS, but CHANNEL_INTEGRATION_DEFINITIONS has no entry for @smithy/core, @smithy/smithy-client, or @aws-sdk/smithy-client. subscriberExportForModule therefore returns nothing and injectSubscribe exits early, so AWS never self-registers awsChannelIntegration on the marker when injectChannelSubscribers is enabled.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6755627. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The rebase was adding more. I think I'll leave this until it is reviewed, do another rebase (as other integrations will come soon) and then push all of them

Comment thread packages/server-utils/test/orchestrion/subscribeInjection.test.ts
Comment thread packages/server-utils/src/orchestrion/bundler/subscribeInjection.ts Outdated
Comment on lines +33 to +43
{ exportName: 'googleGenAIChannelIntegration', modules: ['@google/genai'] },
{ exportName: 'vercelAiChannelIntegration', modules: ['ai'] },
{ exportName: 'amqplibChannelIntegration', modules: ['amqplib'] },
{ exportName: 'hapiChannelIntegration', modules: ['@hapi/hapi'] },
{ exportName: 'expressChannelIntegration', modules: ['express', 'router'] },
{ exportName: 'graphqlChannelIntegration', modules: ['graphql'] },
{ exportName: 'kafkajsChannelIntegration', modules: ['kafkajs'] },
{ exportName: 'redisChannelIntegration', modules: ['redis', '@redis/client'] },
{ exportName: 'ioredisChannelIntegration', modules: ['ioredis'] },
{ exportName: 'dataloaderChannelIntegration', modules: ['dataloader'] },
] as const satisfies ReadonlyArray<{ exportName: string; modules: readonly string[] }>;

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 CHANNEL_INTEGRATION_DEFINITIONS array is missing entries for AWS SDK modules, causing the injectSubscribe transform to silently no-op and disabling the awsChannelIntegration in bundler-only environments.
Severity: HIGH

Suggested Fix

Add an entry to the CHANNEL_INTEGRATION_DEFINITIONS array for the AWS SDK modules. This entry should associate the awsChannelIntegration export with the module names @smithy/core, @smithy/smithy-client, and @aws-sdk/smithy-client. For example: { exportName: 'awsChannelIntegration', modules: ['@smithy/core', '@smithy/smithy-client', '@aws-sdk/smithy-client'] }.

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/config/channel-integration-definitions.ts#L24-L43

Potential issue: The `CHANNEL_INTEGRATION_DEFINITIONS` array lacks definitions for the
AWS SDK modules `@smithy/core`, `@smithy/smithy-client`, and `@aws-sdk/smithy-client`.
Consequently, when the `injectSubscribe` transform processes an AWS SDK file in a
bundler-only setup, the `subscriberExportForModule` function returns `undefined` for
these module names. This triggers a guard condition that causes the transform to exit
silently without injecting the necessary channel subscriber. As a result, the
`awsChannelIntegration` is completely non-functional in these environments, despite the
clear intent to support it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

3 participants