Skip to content

Commit

Permalink
Revert "feat(node): Rework ANR to use worker script via an integration (
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Dec 20, 2023
1 parent c4d4022 commit fdd4c62
Show file tree
Hide file tree
Showing 25 changed files with 900 additions and 606 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ tmp.js
.eslintcache
**/eslintcache/*

# node worker scripts
packages/node/src/integrations/anr/worker-script.*

# deno
packages/deno/build-types
packages/deno/build-test
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type { ServerRuntimeClientOptions } from './server-runtime-client';
export type { RequestDataIntegrationOptions } from './integrations/requestdata';

export * from './tracing';
export { createEventEnvelope, createSessionEnvelope } from './envelope';
export { createEventEnvelope } from './envelope';
export {
addBreadcrumb,
captureCheckIn,
Expand Down
8 changes: 5 additions & 3 deletions packages/node-experimental/src/sdk/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
defaultIntegrations as defaultNodeIntegrations,
defaultStackParser,
getSentryRelease,
isAnrChildProcess,
makeNodeTransport,
} from '@sentry/node';
import type { Integration } from '@sentry/types';
Expand Down Expand Up @@ -112,14 +113,15 @@ function getClientOptions(options: NodeExperimentalOptions): NodeExperimentalCli

const release = getRelease(options.release);

// If there is no release, or we are in an ANR child process, we disable autoSessionTracking by default
const autoSessionTracking =
typeof release !== 'string'
typeof release !== 'string' || isAnrChildProcess()
? false
: options.autoSessionTracking === undefined
? true
: options.autoSessionTracking;

const tracesSampleRate = getTracesSampleRate(options.tracesSampleRate);
// We enforce tracesSampleRate = 0 in ANR child processes
const tracesSampleRate = isAnrChildProcess() ? 0 : getTracesSampleRate(options.tracesSampleRate);

const baseOptions = dropUndefinedKeys({
transport: makeNodeTransport,
Expand Down
29 changes: 16 additions & 13 deletions packages/node-integration-tests/suites/anr/basic-session.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
const crypto = require('crypto');
const assert = require('assert');

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

const { transport } = require('./test-transport.js');

// close both processes after 5 seconds
setTimeout(() => {
process.exit();
}, 10000);
}, 5000);

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
debug: true,
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
transport,
});

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

setTimeout(() => {
longWork();
}, 1000);
setTimeout(() => {
longWork();
}, 1000);
});
29 changes: 16 additions & 13 deletions packages/node-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
const crypto = require('crypto');
const assert = require('assert');

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

const { transport } = require('./test-transport.js');

// close both processes after 5 seconds
setTimeout(() => {
process.exit();
}, 10000);
}, 5000);

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
debug: true,
autoSessionTracking: false,
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
transport,
});

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

setTimeout(() => {
longWork();
}, 1000);
setTimeout(() => {
longWork();
}, 1000);
});
11 changes: 7 additions & 4 deletions packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import * as assert from 'assert';
import * as crypto from 'crypto';

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

const { transport } = await import('./test-transport.js');

// close both processes after 5 seconds
setTimeout(() => {
process.exit();
}, 10000);
}, 5000);

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
debug: true,
autoSessionTracking: false,
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
transport,
});

await Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 });

function longWork() {
for (let i = 0; i < 100; i++) {
const salt = crypto.randomBytes(128).toString('base64');
// eslint-disable-next-line no-unused-vars
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
}
}

Expand Down
29 changes: 16 additions & 13 deletions packages/node-integration-tests/suites/anr/forked.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
const crypto = require('crypto');
const assert = require('assert');

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

const { transport } = require('./test-transport.js');

// close both processes after 5 seconds
setTimeout(() => {
process.exit();
}, 10000);
}, 5000);

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
debug: true,
autoSessionTracking: false,
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })],
transport,
});

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

setTimeout(() => {
longWork();
}, 1000);
setTimeout(() => {
longWork();
}, 1000);
});
31 changes: 0 additions & 31 deletions packages/node-integration-tests/suites/anr/legacy.js

This file was deleted.

17 changes: 17 additions & 0 deletions packages/node-integration-tests/suites/anr/test-transport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { TextEncoder, TextDecoder } = require('util');

const { createTransport } = require('@sentry/core');
const { parseEnvelope } = require('@sentry/utils');

const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();

// A transport that just logs the envelope payloads to console for checking in tests
exports.transport = () => {
return createTransport({ recordDroppedEvent: () => {}, textEncoder }, async request => {
const env = parseEnvelope(request.body, textEncoder, textDecoder);
// eslint-disable-next-line no-console
console.log(JSON.stringify(env[1][0][1]));
return { statusCode: 200 };
});
};
Loading

0 comments on commit fdd4c62

Please sign in to comment.