File tree 3 files changed +42
-3
lines changed
3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ export class ServerRuntimeClient<
147
147
* to create a monitor automatically when sending a check in.
148
148
*/
149
149
public captureCheckIn ( checkIn : CheckIn , monitorConfig ?: MonitorConfig , scope ?: Scope ) : string {
150
- const id = checkIn . status !== 'in_progress' && checkIn . checkInId ? checkIn . checkInId : uuid4 ( ) ;
150
+ const id = 'checkInId' in checkIn && checkIn . checkInId ? checkIn . checkInId : uuid4 ( ) ;
151
151
if ( ! this . _isEnabled ( ) ) {
152
152
DEBUG_BUILD && logger . warn ( 'SDK not enabled, will not capture checkin.' ) ;
153
153
return id ;
@@ -164,7 +164,7 @@ export class ServerRuntimeClient<
164
164
environment,
165
165
} ;
166
166
167
- if ( checkIn . status !== 'in_progress' ) {
167
+ if ( 'duration' in checkIn ) {
168
168
serializedCheckIn . duration = checkIn . duration ;
169
169
}
170
170
Original file line number Diff line number Diff line change @@ -354,6 +354,38 @@ describe('NodeClient', () => {
354
354
] ) ;
355
355
} ) ;
356
356
357
+ it ( 'sends a checkIn envelope for heartbeat checkIns' , ( ) => {
358
+ const options = getDefaultNodeClientOptions ( {
359
+ dsn : PUBLIC_DSN ,
360
+ serverName : 'server' ,
361
+ release : '1.0.0' ,
362
+ environment : 'dev' ,
363
+ } ) ;
364
+ client = new NodeClient ( options ) ;
365
+
366
+ // @ts -expect-error accessing private method
367
+ const sendEnvelopeSpy = jest . spyOn ( client , '_sendEnvelope' ) ;
368
+
369
+ const id = client . captureCheckIn ( { monitorSlug : 'heartbeat-monitor' , status : 'ok' } ) ;
370
+
371
+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
372
+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledWith ( [
373
+ expect . any ( Object ) ,
374
+ [
375
+ [
376
+ expect . any ( Object ) ,
377
+ {
378
+ check_in_id : id ,
379
+ monitor_slug : 'heartbeat-monitor' ,
380
+ status : 'ok' ,
381
+ release : '1.0.0' ,
382
+ environment : 'dev' ,
383
+ } ,
384
+ ] ,
385
+ ] ,
386
+ ] ) ;
387
+ } ) ;
388
+
357
389
it ( 'does not send a checkIn envelope if disabled' , ( ) => {
358
390
const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , serverName : 'bar' , enabled : false } ) ;
359
391
client = new NodeClient ( options ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ export interface SerializedCheckIn {
43
43
} ;
44
44
}
45
45
46
+ export interface HeartbeatCheckIn {
47
+ // The distinct slug of the monitor.
48
+ monitorSlug : SerializedCheckIn [ 'monitor_slug' ] ;
49
+ // The status of the check-in.
50
+ status : 'ok' | 'error' ;
51
+ }
52
+
46
53
export interface InProgressCheckIn {
47
54
// The distinct slug of the monitor.
48
55
monitorSlug : SerializedCheckIn [ 'monitor_slug' ] ;
@@ -61,7 +68,7 @@ export interface FinishedCheckIn {
61
68
duration ?: SerializedCheckIn [ 'duration' ] ;
62
69
}
63
70
64
- export type CheckIn = InProgressCheckIn | FinishedCheckIn ;
71
+ export type CheckIn = HeartbeatCheckIn | InProgressCheckIn | FinishedCheckIn ;
65
72
66
73
type SerializedMonitorConfig = NonNullable < SerializedCheckIn [ 'monitor_config' ] > ;
67
74
You can’t perform that action at this time.
0 commit comments