Skip to content

Commit 88e002d

Browse files
authored
feat(node): No-code init via --import=@sentry/node/init (#11999)
1 parent 37a83ef commit 88e002d

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setTimeout(() => {
2+
throw new Error('Test error');
3+
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setTimeout(() => {
2+
throw new Error('Test error');
3+
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { conditionalTest } from '../../utils';
2+
import { cleanupChildProcesses, createRunner } from '../../utils/runner';
3+
4+
const EVENT = {
5+
exception: {
6+
values: [
7+
{
8+
type: 'Error',
9+
value: 'Test error',
10+
},
11+
],
12+
},
13+
};
14+
15+
describe('no-code init', () => {
16+
afterAll(() => {
17+
cleanupChildProcesses();
18+
});
19+
20+
test('CJS', done => {
21+
createRunner(__dirname, 'app.js')
22+
.withFlags('--require=@sentry/node/init')
23+
.withMockSentryServer()
24+
.expect({ event: EVENT })
25+
.start(done);
26+
});
27+
28+
conditionalTest({ min: 18 })('--import', () => {
29+
test('ESM', done => {
30+
createRunner(__dirname, 'app.mjs')
31+
.withFlags('--import=@sentry/node/init')
32+
.withMockSentryServer()
33+
.expect({ event: EVENT })
34+
.start(done);
35+
});
36+
});
37+
});

packages/node/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
"import": {
4242
"default": "./build/loader-hook.mjs"
4343
}
44+
},
45+
"./init":{
46+
"import": {
47+
"default": "./build/esm/init.js"
48+
},
49+
"require": {
50+
"default": "./build/cjs/init.js"
51+
}
4452
}
4553
},
4654
"typesVersions": {

packages/node/rollup.npm.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default [
1919
localVariablesWorkerConfig,
2020
...makeNPMConfigVariants(
2121
makeBaseNPMConfig({
22+
entrypoints: ['src/index.ts', 'src/init.ts'],
2223
packageSpecificConfig: {
2324
output: {
2425
// set exports to 'named' or 'auto' so that rollup doesn't warn

packages/node/src/init.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { init } from './sdk/init';
2+
3+
/**
4+
* The @sentry/node/init export can be used with the node --import and --require args to initialize the SDK entirely via
5+
* environment variables.
6+
*
7+
* > SENTRY_DSN=https://[email protected]/0 SENTRY_TRACES_SAMPLE_RATE=1.0 node --import=@sentry/node/init app.mjs
8+
*/
9+
init();

0 commit comments

Comments
 (0)