@@ -4,9 +4,9 @@ use serde::Deserialize;
4
4
use thiserror:: Error ;
5
5
use uuid:: Uuid ;
6
6
7
- use super :: {
8
- attachment :: AttachmentType ,
9
- v7 :: { Attachment , Event , SampleProfile , SessionAggregates , SessionUpdate , Transaction } ,
7
+ use super :: v7 :: {
8
+ Attachment , AttachmentType , Event , MonitorCheckIn , SampleProfile , SessionAggregates ,
9
+ SessionUpdate , Transaction ,
10
10
} ;
11
11
12
12
/// Raised if a envelope cannot be parsed from a given input.
@@ -61,6 +61,9 @@ enum EnvelopeItemType {
61
61
/// A Profile Item Type
62
62
#[ serde( rename = "profile" ) ]
63
63
Profile ,
64
+ /// A Monitor Check In Item Type
65
+ #[ serde( rename = "check_in" ) ]
66
+ MonitorCheckIn ,
64
67
}
65
68
66
69
/// An Envelope Item Header.
@@ -109,6 +112,8 @@ pub enum EnvelopeItem {
109
112
Attachment ( Attachment ) ,
110
113
/// A Profile Item.
111
114
Profile ( SampleProfile ) ,
115
+ /// A MonitorCheckIn item.
116
+ MonitorCheckIn ( MonitorCheckIn ) ,
112
117
/// This is a sentinel item used to `filter` raw envelopes.
113
118
Raw ,
114
119
// TODO:
@@ -151,6 +156,12 @@ impl From<SampleProfile> for EnvelopeItem {
151
156
}
152
157
}
153
158
159
+ impl From < MonitorCheckIn > for EnvelopeItem {
160
+ fn from ( check_in : MonitorCheckIn ) -> Self {
161
+ EnvelopeItem :: MonitorCheckIn ( check_in)
162
+ }
163
+ }
164
+
154
165
/// An Iterator over the items of an Envelope.
155
166
#[ derive( Clone ) ]
156
167
pub struct EnvelopeItemIter < ' s > {
@@ -341,6 +352,9 @@ impl Envelope {
341
352
continue ;
342
353
}
343
354
EnvelopeItem :: Profile ( profile) => serde_json:: to_writer ( & mut item_buf, profile) ?,
355
+ EnvelopeItem :: MonitorCheckIn ( check_in) => {
356
+ serde_json:: to_writer ( & mut item_buf, check_in) ?
357
+ }
344
358
EnvelopeItem :: Raw => {
345
359
continue ;
346
360
}
@@ -352,6 +366,7 @@ impl Envelope {
352
366
EnvelopeItem :: Transaction ( _) => "transaction" ,
353
367
EnvelopeItem :: Attachment ( _) | EnvelopeItem :: Raw => unreachable ! ( ) ,
354
368
EnvelopeItem :: Profile ( _) => "profile" ,
369
+ EnvelopeItem :: MonitorCheckIn ( _) => "check_in" ,
355
370
} ;
356
371
writeln ! (
357
372
writer,
@@ -493,6 +508,9 @@ impl Envelope {
493
508
ty : header. attachment_type ,
494
509
} ) ) ,
495
510
EnvelopeItemType :: Profile => serde_json:: from_slice ( payload) . map ( EnvelopeItem :: Profile ) ,
511
+ EnvelopeItemType :: MonitorCheckIn => {
512
+ serde_json:: from_slice ( payload) . map ( EnvelopeItem :: MonitorCheckIn )
513
+ }
496
514
}
497
515
. map_err ( EnvelopeError :: InvalidItemPayload ) ?;
498
516
@@ -523,6 +541,14 @@ impl From<Transaction<'static>> for Envelope {
523
541
}
524
542
}
525
543
544
+ impl From < MonitorCheckIn > for Envelope {
545
+ fn from ( check_in : MonitorCheckIn ) -> Self {
546
+ let mut envelope = Self :: default ( ) ;
547
+ envelope. add_item ( check_in) ;
548
+ envelope
549
+ }
550
+ }
551
+
526
552
#[ cfg( test) ]
527
553
mod test {
528
554
use std:: str:: FromStr ;
@@ -532,7 +558,10 @@ mod test {
532
558
use time:: OffsetDateTime ;
533
559
534
560
use super :: * ;
535
- use crate :: protocol:: v7:: { Level , SessionAttributes , SessionStatus , Span } ;
561
+ use crate :: protocol:: v7:: {
562
+ Level , MonitorCheckInStatus , MonitorConfig , MonitorSchedule , SessionAttributes ,
563
+ SessionStatus , Span ,
564
+ } ;
536
565
537
566
fn to_str ( envelope : Envelope ) -> String {
538
567
let mut vec = Vec :: new ( ) ;
@@ -649,6 +678,35 @@ mod test {
649
678
)
650
679
}
651
680
681
+ #[ test]
682
+ fn test_monitor_checkin ( ) {
683
+ let check_in_id = Uuid :: parse_str ( "22d00b3f-d1b1-4b5d-8d20-49d138cd8a9c" ) . unwrap ( ) ;
684
+
685
+ let check_in = MonitorCheckIn {
686
+ check_in_id,
687
+ monitor_slug : "my-monitor" . into ( ) ,
688
+ status : MonitorCheckInStatus :: Ok ,
689
+ duration : Some ( 123.4 ) ,
690
+ environment : Some ( "production" . into ( ) ) ,
691
+ monitor_config : Some ( MonitorConfig {
692
+ schedule : MonitorSchedule :: Crontab {
693
+ value : "12 0 * * *" . into ( ) ,
694
+ } ,
695
+ checkin_margin : Some ( 5 ) ,
696
+ max_runtime : Some ( 30 ) ,
697
+ timezone : Some ( "UTC" . into ( ) ) ,
698
+ } ) ,
699
+ } ;
700
+ let envelope: Envelope = check_in. into ( ) ;
701
+ assert_eq ! (
702
+ to_str( envelope) ,
703
+ r#"{}
704
+ {"type":"check_in","length":259}
705
+ {"check_in_id":"22d00b3fd1b14b5d8d2049d138cd8a9c","monitor_slug":"my-monitor","status":"ok","environment":"production","duration":123.4,"monitor_config":{"schedule":{"type":"crontab","value":"12 0 * * *"},"checkin_margin":5,"max_runtime":30,"timezone":"UTC"}}
706
+ "#
707
+ )
708
+ }
709
+
652
710
#[ test]
653
711
fn test_event_with_attachment ( ) {
654
712
let event_id = Uuid :: parse_str ( "22d00b3f-d1b1-4b5d-8d20-49d138cd8a9c" ) . unwrap ( ) ;
0 commit comments