Skip to content

Commit fdd4c62

Browse files
author
Luca Forstner
authored
Revert "feat(node): Rework ANR to use worker script via an integration (#9823)" (#9931)
1 parent c4d4022 commit fdd4c62

File tree

25 files changed

+900
-606
lines changed

25 files changed

+900
-606
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ tmp.js
5050
.eslintcache
5151
**/eslintcache/*
5252

53-
# node worker scripts
54-
packages/node/src/integrations/anr/worker-script.*
55-
5653
# deno
5754
packages/deno/build-types
5855
packages/deno/build-test

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type { ServerRuntimeClientOptions } from './server-runtime-client';
55
export type { RequestDataIntegrationOptions } from './integrations/requestdata';
66

77
export * from './tracing';
8-
export { createEventEnvelope, createSessionEnvelope } from './envelope';
8+
export { createEventEnvelope } from './envelope';
99
export {
1010
addBreadcrumb,
1111
captureCheckIn,

packages/node-experimental/src/sdk/init.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
defaultIntegrations as defaultNodeIntegrations,
55
defaultStackParser,
66
getSentryRelease,
7+
isAnrChildProcess,
78
makeNodeTransport,
89
} from '@sentry/node';
910
import type { Integration } from '@sentry/types';
@@ -112,14 +113,15 @@ function getClientOptions(options: NodeExperimentalOptions): NodeExperimentalCli
112113

113114
const release = getRelease(options.release);
114115

116+
// If there is no release, or we are in an ANR child process, we disable autoSessionTracking by default
115117
const autoSessionTracking =
116-
typeof release !== 'string'
118+
typeof release !== 'string' || isAnrChildProcess()
117119
? false
118120
: options.autoSessionTracking === undefined
119121
? true
120122
: options.autoSessionTracking;
121-
122-
const tracesSampleRate = getTracesSampleRate(options.tracesSampleRate);
123+
// We enforce tracesSampleRate = 0 in ANR child processes
124+
const tracesSampleRate = isAnrChildProcess() ? 0 : getTracesSampleRate(options.tracesSampleRate);
123125

124126
const baseOptions = dropUndefinedKeys({
125127
transport: makeNodeTransport,
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
const crypto = require('crypto');
2-
const assert = require('assert');
32

43
const Sentry = require('@sentry/node');
54

5+
const { transport } = require('./test-transport.js');
6+
7+
// close both processes after 5 seconds
68
setTimeout(() => {
79
process.exit();
8-
}, 10000);
10+
}, 5000);
911

1012
Sentry.init({
1113
dsn: 'https://public@dsn.ingest.sentry.io/1337',
1214
release: '1.0',
1315
debug: true,
14-
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
16+
transport,
1517
});
1618

17-
function longWork() {
18-
for (let i = 0; i < 100; i++) {
19-
const salt = crypto.randomBytes(128).toString('base64');
20-
// eslint-disable-next-line no-unused-vars
21-
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
22-
assert.ok(hash);
19+
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => {
20+
function longWork() {
21+
for (let i = 0; i < 100; i++) {
22+
const salt = crypto.randomBytes(128).toString('base64');
23+
// eslint-disable-next-line no-unused-vars
24+
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
25+
}
2326
}
24-
}
2527

26-
setTimeout(() => {
27-
longWork();
28-
}, 1000);
28+
setTimeout(() => {
29+
longWork();
30+
}, 1000);
31+
});
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
const crypto = require('crypto');
2-
const assert = require('assert');
32

43
const Sentry = require('@sentry/node');
54

5+
const { transport } = require('./test-transport.js');
6+
7+
// close both processes after 5 seconds
68
setTimeout(() => {
79
process.exit();
8-
}, 10000);
10+
}, 5000);
911

1012
Sentry.init({
1113
dsn: 'https://public@dsn.ingest.sentry.io/1337',
1214
release: '1.0',
1315
debug: true,
1416
autoSessionTracking: false,
15-
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
17+
transport,
1618
});
1719

18-
function longWork() {
19-
for (let i = 0; i < 100; i++) {
20-
const salt = crypto.randomBytes(128).toString('base64');
21-
// eslint-disable-next-line no-unused-vars
22-
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
23-
assert.ok(hash);
20+
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => {
21+
function longWork() {
22+
for (let i = 0; i < 100; i++) {
23+
const salt = crypto.randomBytes(128).toString('base64');
24+
// eslint-disable-next-line no-unused-vars
25+
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
26+
}
2427
}
25-
}
2628

27-
setTimeout(() => {
28-
longWork();
29-
}, 1000);
29+
setTimeout(() => {
30+
longWork();
31+
}, 1000);
32+
});

packages/node-integration-tests/suites/anr/basic.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import * as assert from 'assert';
21
import * as crypto from 'crypto';
32

43
import * as Sentry from '@sentry/node';
54

5+
const { transport } = await import('./test-transport.js');
6+
7+
// close both processes after 5 seconds
68
setTimeout(() => {
79
process.exit();
8-
}, 10000);
10+
}, 5000);
911

1012
Sentry.init({
1113
dsn: 'https://public@dsn.ingest.sentry.io/1337',
1214
release: '1.0',
1315
debug: true,
1416
autoSessionTracking: false,
15-
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
17+
transport,
1618
});
1719

20+
await Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 });
21+
1822
function longWork() {
1923
for (let i = 0; i < 100; i++) {
2024
const salt = crypto.randomBytes(128).toString('base64');
2125
// eslint-disable-next-line no-unused-vars
2226
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
23-
assert.ok(hash);
2427
}
2528
}
2629

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
const crypto = require('crypto');
2-
const assert = require('assert');
32

43
const Sentry = require('@sentry/node');
54

5+
const { transport } = require('./test-transport.js');
6+
7+
// close both processes after 5 seconds
68
setTimeout(() => {
79
process.exit();
8-
}, 10000);
10+
}, 5000);
911

1012
Sentry.init({
1113
dsn: 'https://public@dsn.ingest.sentry.io/1337',
1214
release: '1.0',
1315
debug: true,
1416
autoSessionTracking: false,
15-
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
17+
transport,
1618
});
1719

18-
function longWork() {
19-
for (let i = 0; i < 100; i++) {
20-
const salt = crypto.randomBytes(128).toString('base64');
21-
// eslint-disable-next-line no-unused-vars
22-
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
23-
assert.ok(hash);
20+
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => {
21+
function longWork() {
22+
for (let i = 0; i < 100; i++) {
23+
const salt = crypto.randomBytes(128).toString('base64');
24+
// eslint-disable-next-line no-unused-vars
25+
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
26+
}
2427
}
25-
}
2628

27-
setTimeout(() => {
28-
longWork();
29-
}, 1000);
29+
setTimeout(() => {
30+
longWork();
31+
}, 1000);
32+
});

packages/node-integration-tests/suites/anr/legacy.js

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { TextEncoder, TextDecoder } = require('util');
2+
3+
const { createTransport } = require('@sentry/core');
4+
const { parseEnvelope } = require('@sentry/utils');
5+
6+
const textEncoder = new TextEncoder();
7+
const textDecoder = new TextDecoder();
8+
9+
// A transport that just logs the envelope payloads to console for checking in tests
10+
exports.transport = () => {
11+
return createTransport({ recordDroppedEvent: () => {}, textEncoder }, async request => {
12+
const env = parseEnvelope(request.body, textEncoder, textDecoder);
13+
// eslint-disable-next-line no-console
14+
console.log(JSON.stringify(env[1][0][1]));
15+
return { statusCode: 200 };
16+
});
17+
};

0 commit comments

Comments
 (0)