-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(react-router): Auto-wire orchestrion build-time instrumentation #22809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chargome
merged 6 commits into
develop
from
charlygomez/js-3182-react-router-auto-wire-orchestrion-bundler-plugin
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e2013c9
auto-wire orchestrion
chargome 6b044e0
tests
chargome 0b7f0b3
feat(react-router): Auto-wire orchestrion build-time instrumentation
chargome 141cd74
Merge remote-tracking branch 'origin/develop' into charlygomez/js-318…
chargome 490cdf4
test(react-router): Auto-wire orchestrion in react-router-8-framework…
chargome 017294d
pr feedback
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...e2e-tests/test-applications/react-router-7-framework-instrumentation/app/entry.server.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...st-applications/react-router-7-framework-instrumentation/app/routes/performance/redis.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...kages/e2e-tests/test-applications/react-router-7-framework-instrumentation/instrument.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ations/react-router-7-framework-instrumentation/tests/performance/build-injection.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { readFileSync, readdirSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| function readBundle(dir: string): string { | ||
| const root = path.join(process.cwd(), dir); | ||
| return readdirSync(root, { recursive: true }) | ||
| .filter((file): file is string => typeof file === 'string' && file.endsWith('.js')) | ||
| .map(file => readFileSync(path.join(root, file), 'utf8')) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| test.describe('Orchestrion build-time injection', () => { | ||
| const serverBundle = readBundle('build/server'); | ||
| const clientBundle = readBundle('build/client'); | ||
|
|
||
| test('force-bundles instrumented dependencies', () => { | ||
| expect(serverBundle).not.toMatch(/(from\s*["']mysql["']|require\(["']mysql["']\))/); | ||
| expect(serverBundle).not.toMatch(/(from\s*["']ioredis["']|require\(["']ioredis["']\))/); | ||
| }); | ||
|
|
||
| test('injects diagnostics-channel publishers into the server build', () => { | ||
| expect(serverBundle).toContain('__SENTRY_ORCHESTRION__'); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:mysql:query["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:ioredis:command["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:ioredis:connect["']\)/); | ||
| }); | ||
|
|
||
| test('does not inject diagnostics-channel publishers into the client build', () => { | ||
| // The client build may carry the inert `__SENTRY_ORCHESTRION__.bundler = []` detection marker | ||
| // (it's environment-agnostic and harmless in a browser), but the actual `tracingChannel` publishers | ||
| // and their channel names must never leak — `applyToEnvironment` keeps the transform server-only, so | ||
| // a browser never hits a `diagnostics_channel` call that would throw. | ||
| expect(clientBundle).not.toMatch(/tracingChannel\(/); | ||
| expect(clientBundle).not.toMatch(/orchestrion:[a-z]/); | ||
| }); | ||
| }); |
114 changes: 114 additions & 0 deletions
114
...applications/react-router-7-framework-instrumentation/tests/performance/db.server.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
| import { APP_NAME } from '../constants'; | ||
|
|
||
| // Orchestrion injects `diagnostics_channel` publishers at build time, so these spans only exist in the | ||
| // bundled server build. `react-router dev` serves an unbundled SSR pipeline where the transform never | ||
| // runs, so the assertions are meaningless there — skip them in the dev run. | ||
| const isDev = process.env.TEST_ENV === 'development'; | ||
|
|
||
| test.describe('server - orchestrion build-time db instrumentation', () => { | ||
| test.skip(isDev, 'orchestrion only injects into the bundled server build, not the dev server'); | ||
|
|
||
| test('instruments ioredis automatically via orchestrion', async ({ page }) => { | ||
| const transactionEventPromise = waitForTransaction(APP_NAME, transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| transactionEvent.transaction === 'GET /performance/db-ioredis' | ||
| ); | ||
| }); | ||
|
|
||
| await page.goto('/performance/db-ioredis'); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const spans = transactionEvent.spans || []; | ||
|
|
||
| // The server transaction must come from the native instrumentation API (not the legacy handler), | ||
| // proving the orchestrion-injected db spans share context with the React Router server span. | ||
| expect(transactionEvent.contexts?.trace?.origin).toBe('auto.http.react_router.instrumentation_api'); | ||
|
|
||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.redis', | ||
| description: 'set test-key [1 other arguments]', | ||
| status: 'ok', | ||
| data: expect.objectContaining({ | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'set test-key [1 other arguments]', | ||
| }), | ||
| }), | ||
| ); | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.redis', | ||
| description: 'get test-key', | ||
| status: 'ok', | ||
| data: expect.objectContaining({ | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'get test-key', | ||
| }), | ||
| }), | ||
| ); | ||
|
|
||
| // Each command maps to exactly one span (no offline-queue duplicate). | ||
| const setSpans = spans.filter(span => span.description === 'set test-key [1 other arguments]'); | ||
| expect(setSpans).toHaveLength(1); | ||
|
|
||
| // Every db span nests under the native instrumentation-API http.server transaction. | ||
| const rootSpanId = transactionEvent.contexts?.trace?.span_id; | ||
| const spanIds = new Set([rootSpanId, ...spans.map(span => span.span_id)]); | ||
| const dbSpans = spans.filter(span => span.op === 'db'); | ||
| expect(dbSpans.every(span => typeof span.parent_span_id === 'string' && spanIds.has(span.parent_span_id))).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test('instruments mysql automatically via orchestrion', async ({ page }) => { | ||
| const transactionEventPromise = waitForTransaction(APP_NAME, transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| transactionEvent.transaction === 'GET /performance/db-mysql' | ||
| ); | ||
| }); | ||
|
|
||
| await page.goto('/performance/db-mysql'); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
| const spans = transactionEvent.spans || []; | ||
|
|
||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.mysql', | ||
| description: 'SELECT 1 + 1 AS solution', | ||
| status: 'ok', | ||
| data: expect.objectContaining({ | ||
| 'db.system': 'mysql', | ||
| 'db.statement': 'SELECT 1 + 1 AS solution', | ||
| 'db.user': 'root', | ||
| 'db.connection_string': expect.any(String), | ||
| 'net.peer.name': expect.any(String), | ||
| 'net.peer.port': 3306, | ||
| }), | ||
| }), | ||
| ); | ||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.mysql', | ||
| description: 'SELECT NOW()', | ||
| status: 'ok', | ||
| data: expect.objectContaining({ | ||
| 'db.system': 'mysql', | ||
| 'db.statement': 'SELECT NOW()', | ||
| 'db.user': 'root', | ||
| 'db.connection_string': expect.any(String), | ||
| 'net.peer.name': expect.any(String), | ||
| 'net.peer.port': 3306, | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
38 changes: 0 additions & 38 deletions
38
...lications/react-router-7-framework-instrumentation/tests/performance/redis.server.test.ts
This file was deleted.
Oops, something went wrong.
7 changes: 5 additions & 2 deletions
7
dev-packages/e2e-tests/test-applications/react-router-8-framework/vite.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| import { reactRouter } from '@react-router/dev/vite'; | ||
| import { sentryReactRouter } from '@sentry/react-router'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [reactRouter()], | ||
| export default defineConfig(config => { | ||
| return { | ||
| plugins: [reactRouter(), sentryReactRouter({ sourcemaps: { disable: true } }, config)], | ||
| }; | ||
| }); |
32 changes: 0 additions & 32 deletions
32
dev-packages/e2e-tests/test-applications/react-router-8-orchestrion/.gitignore
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.