Skip to content

Commit

Permalink
feat(node): No-code init via --import=@sentry/node/init (#11999)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed May 22, 2024
1 parent 37a83ef commit 88e002d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dev-packages/node-integration-tests/suites/no-code/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setTimeout(() => {
throw new Error('Test error');
}, 1000);
3 changes: 3 additions & 0 deletions dev-packages/node-integration-tests/suites/no-code/app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setTimeout(() => {
throw new Error('Test error');
}, 1000);
37 changes: 37 additions & 0 deletions dev-packages/node-integration-tests/suites/no-code/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { conditionalTest } from '../../utils';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

const EVENT = {
exception: {
values: [
{
type: 'Error',
value: 'Test error',
},
],
},
};

describe('no-code init', () => {
afterAll(() => {
cleanupChildProcesses();
});

test('CJS', done => {
createRunner(__dirname, 'app.js')
.withFlags('--require=@sentry/node/init')
.withMockSentryServer()
.expect({ event: EVENT })
.start(done);
});

conditionalTest({ min: 18 })('--import', () => {
test('ESM', done => {
createRunner(__dirname, 'app.mjs')
.withFlags('--import=@sentry/node/init')
.withMockSentryServer()
.expect({ event: EVENT })
.start(done);
});
});
});
8 changes: 8 additions & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"import": {
"default": "./build/loader-hook.mjs"
}
},
"./init":{
"import": {
"default": "./build/esm/init.js"
},
"require": {
"default": "./build/cjs/init.js"
}
}
},
"typesVersions": {
Expand Down
1 change: 1 addition & 0 deletions packages/node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default [
localVariablesWorkerConfig,
...makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.ts', 'src/init.ts'],
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
Expand Down
9 changes: 9 additions & 0 deletions packages/node/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { init } from './sdk/init';

/**
* The @sentry/node/init export can be used with the node --import and --require args to initialize the SDK entirely via
* environment variables.
*
* > SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 SENTRY_TRACES_SAMPLE_RATE=1.0 node --import=@sentry/node/init app.mjs
*/
init();

0 comments on commit 88e002d

Please sign in to comment.