File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ export class ServerRuntimeClient<
147147 * to create a monitor automatically when sending a check in.
148148 */
149149 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 ( ) ;
151151 if ( ! this . _isEnabled ( ) ) {
152152 DEBUG_BUILD && logger . warn ( 'SDK not enabled, will not capture checkin.' ) ;
153153 return id ;
@@ -164,7 +164,7 @@ export class ServerRuntimeClient<
164164 environment,
165165 } ;
166166
167- if ( checkIn . status !== 'in_progress' ) {
167+ if ( 'duration' in checkIn ) {
168168 serializedCheckIn . duration = checkIn . duration ;
169169 }
170170
Original file line number Diff line number Diff line change @@ -354,6 +354,38 @@ describe('NodeClient', () => {
354354 ] ) ;
355355 } ) ;
356356
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+
357389 it ( 'does not send a checkIn envelope if disabled' , ( ) => {
358390 const options = getDefaultNodeClientOptions ( { dsn : PUBLIC_DSN , serverName : 'bar' , enabled : false } ) ;
359391 client = new NodeClient ( options ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ export interface SerializedCheckIn {
4343 } ;
4444}
4545
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+
4653export interface InProgressCheckIn {
4754 // The distinct slug of the monitor.
4855 monitorSlug : SerializedCheckIn [ 'monitor_slug' ] ;
@@ -61,7 +68,7 @@ export interface FinishedCheckIn {
6168 duration ?: SerializedCheckIn [ 'duration' ] ;
6269}
6370
64- export type CheckIn = InProgressCheckIn | FinishedCheckIn ;
71+ export type CheckIn = HeartbeatCheckIn | InProgressCheckIn | FinishedCheckIn ;
6572
6673type SerializedMonitorConfig = NonNullable < SerializedCheckIn [ 'monitor_config' ] > ;
6774
You can’t perform that action at this time.
0 commit comments