File tree Expand file tree Collapse file tree 6 files changed +77
-7
lines changed
dev-packages/node-integration-tests/suites Expand file tree Collapse file tree 6 files changed +77
-7
lines changed Original file line number Diff line number Diff line change
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 ( ) ;
Original file line number Diff line number Diff line change
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 ( ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -11,9 +11,6 @@ Sentry.init({
11
11
} ,
12
12
} ) ;
13
13
14
- // Stop the process from exiting before the transaction is sent
15
- setInterval ( ( ) => { } , 1000 ) ;
16
-
17
14
Sentry . startSpan (
18
15
{
19
16
name : 'Test Transaction' ,
Original file line number Diff line number Diff line change @@ -25,7 +25,9 @@ export class MetricsAggregator implements MetricsAggregatorBase {
25
25
// that we store in memory.
26
26
private _bucketsTotalWeight ;
27
27
28
- private readonly _interval : ReturnType < typeof setInterval > ;
28
+ // Cast to any so that it can use Node.js timeout
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ private readonly _interval : any ;
29
31
30
32
// SDKs are required to shift the flush interval by random() * rollup_in_seconds.
31
33
// That shift is determined once per startup to create jittering.
@@ -42,7 +44,13 @@ export class MetricsAggregator implements MetricsAggregatorBase {
42
44
public constructor ( private readonly _client : Client < ClientOptions > ) {
43
45
this . _buckets = new Map ( ) ;
44
46
this . _bucketsTotalWeight = 0 ;
45
- this . _interval = setInterval ( ( ) => this . _flush ( ) , DEFAULT_FLUSH_INTERVAL ) ;
47
+
48
+ this . _interval = setInterval ( ( ) => this . _flush ( ) , DEFAULT_FLUSH_INTERVAL ) as any ;
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
50
+ if ( this . _interval . unref ) {
51
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
52
+ this . _interval . unref ( ) ;
53
+ }
46
54
this . _flushShift = Math . floor ( ( Math . random ( ) * DEFAULT_FLUSH_INTERVAL ) / 1000 ) ;
47
55
this . _forceFlush = false ;
48
56
}
Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ export class SessionFlusher implements SessionFlusherLike {
20
20
public readonly flushTimeout : number ;
21
21
private _pendingAggregates : Record < number , AggregationCounts > ;
22
22
private _sessionAttrs : ReleaseHealthAttributes ;
23
- private _intervalId : ReturnType < typeof setInterval > ;
23
+ // Cast to any so that it can use Node.js timeout
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ private _intervalId : any ;
24
26
private _isEnabled : boolean ;
25
27
private _client : Client ;
26
28
@@ -30,8 +32,13 @@ export class SessionFlusher implements SessionFlusherLike {
30
32
this . _pendingAggregates = { } ;
31
33
this . _isEnabled = true ;
32
34
33
- // Call to setInterval, so that flush is called every 60 seconds
35
+ // Call to setInterval, so that flush is called every 60 seconds.
34
36
this . _intervalId = setInterval ( ( ) => this . flush ( ) , this . flushTimeout * 1000 ) ;
37
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38
+ if ( this . _intervalId . unref ) {
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
40
+ this . _intervalId . unref ( ) ;
41
+ }
35
42
this . _sessionAttrs = attrs ;
36
43
}
37
44
You can’t perform that action at this time.
0 commit comments