-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(remix): Add orchestrion-based remix instrumentation #22244
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
Open
mydea
wants to merge
9
commits into
develop
Choose a base branch
from
francesconovy/js-2483-rewrite-remixinstrumentation-to-orchestrion
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28c2398
WIP
mydea 02a91ae
fixes and stuff
mydea 538a224
fix(remix): Always instrument callRouteAction in channel integration
mydea 22b6f85
use channels from server-utils package
mydea 1a3d491
ref stuff
mydea 4e71580
fix(remix): Pass form-data keys as options to RemixInstrumentation
mydea e524832
test(remix-e2e): Assert all four remix channels in build-injection check
mydea 0b48e6f
fix(remix): Read action form data concurrently with the action
mydea 7957bd3
cleanup
mydea 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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
dev-packages/e2e-tests/test-applications/create-remix-app-v2/instrument.server.cjs
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
19 changes: 16 additions & 3 deletions
19
dev-packages/e2e-tests/test-applications/create-remix-app-v2/playwright.config.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,20 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: `pnpm start`, | ||
| }); | ||
| const injectOrchestrion = process.env.INJECT_ORCHESTRION === 'true'; | ||
|
|
||
| const config = getPlaywrightConfig( | ||
| { | ||
| startCommand: `pnpm start`, | ||
| }, | ||
| // The orchestrion variant exercises real MySQL/Redis. Boot them before the tests run, | ||
| // outside the webServer startup-timeout window. In the default variant no DB is needed. | ||
| injectOrchestrion | ||
| ? { | ||
| globalSetup: fileURLToPath(new URL('./global-setup.mjs', import.meta.url)), | ||
| globalTeardown: fileURLToPath(new URL('./global-teardown.mjs', import.meta.url)), | ||
| } | ||
| : {}, | ||
| ); | ||
|
|
||
| export default config; |
9 changes: 0 additions & 9 deletions
9
dev-packages/e2e-tests/test-applications/create-remix-app-v2/remix.config.js
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
dev-packages/e2e-tests/test-applications/create-remix-app-v2/tests/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,50 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| // The `db.test.ts` runtime assertions prove orchestrion spans appear, but spans alone | ||
| // don't prove they came from the BUILD-time transform: if the Vite plugin silently | ||
| // failed to load, the deps would stay external and the runtime `--require` hook would | ||
| // inject the channels at runtime instead - the span tests would still pass. These | ||
| // assertions inspect the built server bundle directly so a broken plugin can't hide | ||
| // behind that runtime fallback. Only relevant in the orchestrion variant. | ||
| test.describe('orchestrion build-time injection', () => { | ||
| test.skip(process.env.INJECT_ORCHESTRION !== 'true', 'Only runs in the orchestrion variant'); | ||
|
|
||
| const serverBundle = readFileSync(path.join(process.cwd(), 'build/server/index.js'), 'utf8'); | ||
|
|
||
| test('force-bundles the instrumented deps instead of externalizing them', () => { | ||
| // The plugin adds mysql/ioredis to `ssr.noExternal` so the transform sees their | ||
| // source. Without it they'd be left as bare imports or `require(...)` calls resolved | ||
| // from node_modules at runtime - untouched, with no channels injected. | ||
| expect(serverBundle).not.toMatch(/(from\s*["']mysql["']|require\(["']mysql["']\))/); | ||
| expect(serverBundle).not.toMatch(/(from\s*["']ioredis["']|require\(["']ioredis["']\))/); | ||
| }); | ||
|
|
||
| test('injects the diagnostics-channel publishers into the bundled deps', () => { | ||
| // The transform wraps each instrumented function with a `tracingChannel("<name>")` | ||
| // publisher whose channel name is a string literal. The subscriber side passes the | ||
| // channel name as a variable, so a literal-arg match is unique to the injected | ||
| // publisher and proves the build-time transform ran. | ||
| expect(serverBundle).toMatch(/tracingChannel(\$?\d)?\(["']orchestrion:mysql:query["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel(\$?\d)?\(["']orchestrion:ioredis:command["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel(\$?\d)?\(["']orchestrion:ioredis:connect["']\)/); | ||
| }); | ||
|
|
||
| test('injects the diagnostics-channel publishers into @remix-run/server-runtime', () => { | ||
| // Remix's own instrumentation is orchestrion-based too: the transform force-bundles | ||
| // and injects channels into `@remix-run/server-runtime` | ||
| expect(serverBundle).toMatch( | ||
| /tracingChannel(\$?\d)?\(["']orchestrion:@remix-run\/server-runtime:requestHandler["']\)/, | ||
| ); | ||
| expect(serverBundle).toMatch( | ||
| /tracingChannel(\$?\d)?\(["']orchestrion:@remix-run\/server-runtime:matchServerRoutes["']\)/, | ||
| ); | ||
| expect(serverBundle).toMatch( | ||
| /tracingChannel(\$?\d)?\(["']orchestrion:@remix-run\/server-runtime:callRouteLoader["']\)/, | ||
| ); | ||
| expect(serverBundle).toMatch( | ||
| /tracingChannel(\$?\d)?\(["']orchestrion:@remix-run\/server-runtime:callRouteAction["']\)/, | ||
| ); | ||
| }); | ||
| }); | ||
94 changes: 94 additions & 0 deletions
94
dev-packages/e2e-tests/test-applications/create-remix-app-v2/tests/db.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,94 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| // These assertions only hold in the orchestrion variant (INJECT_ORCHESTRION=true), which | ||
| // force-bundles + transforms mysql/ioredis and boots the databases via docker-compose. | ||
| test.describe('orchestrion DB instrumentation', () => { | ||
| test.skip(process.env.INJECT_ORCHESTRION !== 'true', 'Only runs in the orchestrion variant'); | ||
|
|
||
| test('Instruments ioredis automatically via orchestrion', async ({ baseURL }) => { | ||
| const transactionEventPromise = waitForTransaction('create-remix-app-v2', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && !!transactionEvent.transaction?.includes('db-ioredis') | ||
| ); | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/db-ioredis`); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| const spans = transactionEvent.spans || []; | ||
|
|
||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.orchestrion.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.orchestrion.redis', | ||
| description: 'get test-key', | ||
| status: 'ok', | ||
| data: expect.objectContaining({ | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'get test-key', | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| test('Instruments mysql automatically via orchestrion', async ({ baseURL }) => { | ||
| const transactionEventPromise = waitForTransaction('create-remix-app-v2', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && !!transactionEvent.transaction?.includes('db-mysql') | ||
| ); | ||
| }); | ||
|
|
||
| await fetch(`${baseURL}/db-mysql`); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| const spans = transactionEvent.spans || []; | ||
|
|
||
| expect(spans).toContainEqual( | ||
| expect.objectContaining({ | ||
| op: 'db', | ||
| origin: 'auto.db.orchestrion.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.orchestrion.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, | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
9 changes: 8 additions & 1 deletion
9
dev-packages/e2e-tests/test-applications/create-remix-app-v2/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,15 +1,22 @@ | ||
| import { vitePlugin as remix } from '@remix-run/dev'; | ||
| import { sentryRemixVitePlugin } from '@sentry/remix'; | ||
| import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite'; | ||
| import { defineConfig } from 'vite'; | ||
| import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
|
||
| const injectOrchestrion = process.env.INJECT_ORCHESTRION === 'true'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| remix({ | ||
| ignoredRouteFiles: ['**/.*'], | ||
| serverModuleFormat: 'cjs', | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| }), | ||
| sentryRemixVitePlugin(), | ||
| // In the orchestrion variant, run the orchestrion code transform over the SSR | ||
| // server bundle and force-bundle the instrumented deps (mysql, ioredis, | ||
| // @remix-run/server-runtime, …) so their diagnostics-channel calls are injected | ||
| // at build time. | ||
| ...(injectOrchestrion ? [sentryOrchestrionPlugin()] : []), | ||
| tsconfigPaths(), | ||
| ], | ||
| }); | ||
10 changes: 0 additions & 10 deletions
10
dev-packages/e2e-tests/test-applications/remix-orchestrion/.gitignore
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
dev-packages/e2e-tests/test-applications/remix-orchestrion/app/entry.client.tsx
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.