Repository navigation
fix(node): restore tsx runtime instrumentation #25351
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d5002b
fix(node): restore tsx runtime instrumentation
jpdefo a255fd3
fix(node): avoid repeated instrumentation for queried modules
jpdefo 9a97d9c
fix(node): apply runtime instrumentation review feedback
jpdefo 1efa955
Merge branch 'develop' into feat/tsx-runtime-injection
jpdefo 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
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 |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| "tsx": "^4.20.3" | ||
| }, | ||
| "volta": { | ||
| "node": "20.19.5", | ||
| "extends": "../../package.json" | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
dev-packages/node-integration-tests/suites/tracing/orchestrion-tsx/scenario-reload.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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { tracingChannel } from 'node:diagnostics_channel'; | ||
| import { createRequire } from 'node:module'; | ||
|
|
||
| Sentry.init({ tracesSampleRate: 0 }); | ||
|
|
||
| let loads = 0; | ||
| let injections = 0; | ||
| Sentry.getClient().on('orchestrion.module-injected', moduleName => { | ||
| if (moduleName === 'dataloader') { | ||
| injections++; | ||
| } | ||
| }); | ||
| tracingChannel('orchestrion:dataloader:load').start.subscribe(() => { | ||
| loads++; | ||
| }); | ||
|
|
||
| const url = import.meta.resolve('dataloader'); | ||
| await import(`${url}?first`); | ||
| await import(`${url}?second`); | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| delete require.cache[require.resolve('dataloader')]; | ||
| injections = 0; | ||
|
|
||
| const DataLoader = require('dataloader'); | ||
| const value = await new DataLoader(async keys => keys).load('real-key'); | ||
| process.stdout.write(JSON.stringify([{ value, loads, injections }])); |
29 changes: 29 additions & 0 deletions
29
dev-packages/node-integration-tests/suites/tracing/orchestrion-tsx/scenario.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const Sentry = require('@sentry/node'); | ||
| const { tracingChannel } = require('node:diagnostics_channel'); | ||
|
|
||
| Sentry.init({ tracesSampleRate: 0 }); | ||
|
|
||
| let loads = 0; | ||
| let injections = 0; | ||
| Sentry.getClient().on('orchestrion.module-injected', moduleName => { | ||
| if (moduleName === 'dataloader') { | ||
| injections++; | ||
| } | ||
| }); | ||
| tracingChannel('orchestrion:dataloader:load').start.subscribe(() => { | ||
| loads++; | ||
| }); | ||
|
|
||
| async function run() { | ||
| const observations = []; | ||
| for (let attempt = 0; attempt < 2; attempt++) { | ||
| const DataLoader = require('dataloader'); | ||
| const value = await new DataLoader(async keys => keys).load('real-key'); | ||
| observations.push({ value, loads, injections }); | ||
| delete require.cache[require.resolve('dataloader')]; | ||
| } | ||
| await Sentry.close(1000); | ||
| process.stdout.write(JSON.stringify(observations)); | ||
| } | ||
|
|
||
| run(); |
22 changes: 22 additions & 0 deletions
22
dev-packages/node-integration-tests/suites/tracing/orchestrion-tsx/scenario.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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { tracingChannel } from 'node:diagnostics_channel'; | ||
|
|
||
| Sentry.init({ tracesSampleRate: 0 }); | ||
|
|
||
| let loads = 0; | ||
| let injections = 0; | ||
| Sentry.getClient().on('orchestrion.module-injected', moduleName => { | ||
| if (moduleName === 'dataloader') { | ||
| injections++; | ||
| } | ||
| }); | ||
| tracingChannel('orchestrion:dataloader:load').start.subscribe(() => { | ||
| loads++; | ||
| }); | ||
|
|
||
| const { default: DataLoader } = await import( | ||
| `${import.meta.resolve('dataloader')}${process.argv[2] ?? '?instrumentation-test'}` | ||
| ); | ||
| const value = await new DataLoader(async keys => keys).load('real-key'); | ||
| await Sentry.close(1000); | ||
| process.stdout.write(JSON.stringify([{ value, loads, injections }])); |
49 changes: 49 additions & 0 deletions
49
dev-packages/node-integration-tests/suites/tracing/orchestrion-tsx/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,49 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { join } from 'node:path'; | ||
| import { expect, test } from 'vitest'; | ||
|
|
||
| test.each([ | ||
| { name: 'plain Node CommonJS', flags: [], scenario: 'scenario.cjs', operations: 2 }, | ||
| { name: 'tsx CommonJS', flags: ['--require', 'tsx/cjs'], scenario: 'scenario.cjs', operations: 2 }, | ||
| { name: 'plain Node ESM', flags: [], scenario: 'scenario.mjs', operations: 1 }, | ||
| // tsx can replace the hook's source, requiring another transform before compilation. | ||
| { | ||
| name: 'tsx ESM', | ||
| flags: ['--import', 'tsx'], | ||
| scenario: 'scenario.mjs', | ||
| operations: 1, | ||
| injections: expect.any(Number), | ||
| }, | ||
| { | ||
| name: 'plain Node ESM fragment', | ||
| flags: [], | ||
| scenario: 'scenario.mjs', | ||
| operations: 1, | ||
| suffix: '#instrumentation-test', | ||
| }, | ||
| { | ||
| name: 'tsx ESM fragment', | ||
| flags: ['--import', 'tsx'], | ||
| scenario: 'scenario.mjs', | ||
| operations: 1, | ||
| suffix: '#instrumentation-test', | ||
| injections: expect.any(Number), | ||
| }, | ||
| { name: 'plain Node after queried imports', flags: [], scenario: 'scenario-reload.mjs', operations: 1 }, | ||
| { name: 'tsx after queried imports', flags: ['--import', 'tsx'], scenario: 'scenario-reload.mjs', operations: 1 }, | ||
| ])('instruments each operation exactly once with $name', ({ flags, scenario, operations, suffix, injections }) => { | ||
| const result = spawnSync(process.execPath, [...flags, join(__dirname, scenario), suffix ?? '?instrumentation-test'], { | ||
| encoding: 'utf8', | ||
| timeout: 30_000, | ||
| }); | ||
|
|
||
| expect(result.error).toBeUndefined(); | ||
| expect(result.status, result.stderr).toBe(0); | ||
| expect(JSON.parse(result.stdout)).toEqual( | ||
| Array.from({ length: operations }, (_, index) => ({ | ||
| value: 'real-key', | ||
| loads: index + 1, | ||
| injections: injections ?? index + 1, | ||
| })), | ||
| ); | ||
| }); |
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
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.