Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as Sentry from '@sentry/node';
import { disableBlockDetectionForCallback, eventLoopBlockIntegration } from '@sentry/node-native';
import { longWork, longWorkOther } from './long-work.js';

global._sentryDebugIds = { [new Error().stack]: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa' };

setTimeout(() => {
process.exit();
}, 15000);

Sentry.init({
debug: true,
dsn: process.env.SENTRY_DSN,
release: '1.0',
integrations: [eventLoopBlockIntegration()],
});

setTimeout(() => {
disableBlockDetectionForCallback(() => {
// This wont be captured
longWork();
});

setTimeout(() => {
// But this will be captured
longWorkOther();
}, 2000);
}, 2000);
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const crypto = require('crypto');
const assert = require('assert');

function longWork() {
function longWork(count = 100) {
for (let i = 0; i < count; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
assert.ok(hash);
}
}

function longWorkOther() {
for (let i = 0; i < 200; i++) {
const salt = crypto.randomBytes(128).toString('base64');
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512');
Expand All @@ -10,3 +18,4 @@ function longWork() {
}

exports.longWork = longWork;
exports.longWorkOther = longWorkOther;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Event } from '@sentry/core';
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

function EXCEPTION(thread_id = '0') {
function EXCEPTION(thread_id = '0', fn = 'longWork') {
return {
values: [
{
Expand All @@ -24,7 +24,7 @@ function EXCEPTION(thread_id = '0') {
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: 'longWork',
function: fn,
in_app: true,
}),
]),
Expand Down Expand Up @@ -155,6 +155,19 @@ describe('Thread Blocked Native', { timeout: 30_000 }, () => {
expect(runner.childHasExited()).toBe(true);
});

test('can be disabled with disableBlockDetectionForCallback', async () => {
await createRunner(__dirname, 'basic-disabled.mjs')
.withMockSentryServer()
.expect({
event: {
...ANR_EVENT,
exception: EXCEPTION('0', 'longWorkOther'),
},
})
.start()
.completed();
});

test('worker thread', async () => {
const instrument = join(__dirname, 'instrument.mjs');
await createRunner(__dirname, 'worker-main.mjs')
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function makeBaseNPMConfig(options = {}) {
}

return true;
}
},
},

plugins: [nodeResolvePlugin, sucrasePlugin, debugBuildStatementReplacePlugin, rrwebBuildPlugin, cleanupPlugin],
Expand Down
2 changes: 1 addition & 1 deletion packages/node-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"build:tarball": "npm pack"
},
"dependencies": {
"@sentry-internal/node-native-stacktrace": "^0.1.0",
"@sentry-internal/node-native-stacktrace": "^0.2.0",
"@sentry/core": "9.38.0",
"@sentry/node": "9.38.0"
},
Expand Down
Loading
Loading