Skip to content

Commit 4abea77

Browse files
committed
add test and add guards for unref
1 parent 31b0cde commit 4abea77

File tree

6 files changed

+66
-5
lines changed

6 files changed

+66
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Sentry = require('@sentry/node');
2+
3+
function configureSentry() {
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
autoSessionTracking: false,
8+
});
9+
10+
Sentry.metrics.increment('test');
11+
}
12+
13+
async function main() {
14+
configureSentry();
15+
await new Promise(resolve => setTimeout(resolve, 1000));
16+
process.exit(0);
17+
}
18+
19+
main();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const Sentry = require('@sentry/node');
2+
3+
function configureSentry() {
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
autoSessionTracking: false,
8+
});
9+
10+
Sentry.metrics.increment('test');
11+
}
12+
13+
async function main() {
14+
configureSentry();
15+
await new Promise(resolve => setTimeout(resolve, 1000));
16+
}
17+
18+
main();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createRunner } from '../../utils/runner';
2+
3+
describe('metrics', () => {
4+
test('should exit', done => {
5+
const runner = createRunner(__dirname, 'should-exit.js').start();
6+
7+
setTimeout(() => {
8+
expect(runner.childHasExited()).toBe(true);
9+
done();
10+
}, 5_000);
11+
});
12+
13+
test('should exit forced', done => {
14+
const runner = createRunner(__dirname, 'should-exit-forced.js').start();
15+
16+
setTimeout(() => {
17+
expect(runner.childHasExited()).toBe(true);
18+
done();
19+
}, 5_000);
20+
});
21+
});

dev-packages/node-integration-tests/suites/tracing/metric-summaries/scenario.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Sentry.init({
88
transport: loggingTransport,
99
});
1010

11-
// Stop the process from exiting before the transaction is sent
12-
setInterval(() => {}, 1000);
13-
1411
Sentry.startSpan(
1512
{
1613
name: 'Test Transaction',

packages/core/src/metrics/aggregator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export class MetricsAggregator implements MetricsAggregatorBase {
3737
public constructor(private readonly _client: Client) {
3838
this._buckets = new Map();
3939
this._bucketsTotalWeight = 0;
40-
this._interval = setInterval(() => this._flush(), DEFAULT_FLUSH_INTERVAL).unref();
40+
this._interval = setInterval(() => this._flush(), DEFAULT_FLUSH_INTERVAL);
41+
if (this._interval.unref) {
42+
this._interval.unref();
43+
}
4144
this._flushShift = Math.floor((Math.random() * DEFAULT_FLUSH_INTERVAL) / 1000);
4245
this._forceFlush = false;
4346
}

packages/core/src/sessionflusher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export class SessionFlusher implements SessionFlusherLike {
3131
this._isEnabled = true;
3232

3333
// Call to setInterval, so that flush is called every 60 seconds.
34-
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000).unref();
34+
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);
35+
if (this._intervalId.unref) {
36+
this._intervalId.unref();
37+
}
3538
this._sessionAttrs = attrs;
3639
}
3740

0 commit comments

Comments
 (0)