@@ -3,6 +3,7 @@ import * as Sentry from '@sentry/node';
33import testAdminPayload from '@test/payloads/sentry-options/test-admin-payload.json' ;
44import testBadPayload from '@test/payloads/sentry-options/test-bad-payload.json' ;
55import testEmptyPayload from '@test/payloads/sentry-options/test-empty-payload.json' ;
6+ import testLatencyPayload from '@test/payloads/sentry-options/test-latency-payload.json' ;
67import testMegaPayload from '@test/payloads/sentry-options/test-mega-payload.json' ;
78import testPartialPayload from '@test/payloads/sentry-options/test-partial-payload.json' ;
89import testPayload from '@test/payloads/sentry-options/test-payload.json' ;
@@ -628,4 +629,63 @@ describe('sentry-options webhook', function () {
628629 } ,
629630 } ) ;
630631 } ) ;
632+
633+ it ( 'should include latency_seconds tag when present' , async function ( ) {
634+ await sendSentryOptionsUpdatesToDatadog ( testLatencyPayload , 1699563828 ) ;
635+ expect ( datadogApiInstanceSpy ) . toHaveBeenCalledTimes ( 2 ) ;
636+
637+ // Check the drifted_options message
638+ const driftedMessage = datadogApiInstanceSpy . mock . calls [ 0 ] [ 0 ] ;
639+ expect ( driftedMessage ) . toEqual ( {
640+ body : {
641+ dateHappened : 1699563828 ,
642+ text : '{"change":"drifted_options","option":{"option_name":"drifted_option_1","option_value":"value_1"},"latency_seconds":2.5}' ,
643+ title : 'Sentry Options Update' ,
644+ alertType : 'error' ,
645+ tags : [
646+ 'sentry_region:st-test_region' ,
647+ 'source_tool:options-automator' ,
648+ 'source:options-automator' ,
649+ 'source_category:infra-tools' ,
650+ 'option_name:drifted_option_1' ,
651+ 'sentry_user:options-automator' ,
652+ 'latency_seconds:2.5' ,
653+ ] ,
654+ } ,
655+ } ) ;
656+
657+ const updatedMessage = datadogApiInstanceSpy . mock . calls [ 1 ] [ 0 ] ;
658+ expect ( updatedMessage ) . toEqual ( {
659+ body : {
660+ dateHappened : 1699563828 ,
661+ text : '{"change":"updated_options","option":{"option_name":"updated_option_1","db_value":"db_value_1","value":"new_value_1"},"latency_seconds":2.5}' ,
662+ title : 'Sentry Options Update' ,
663+ alertType : 'success' ,
664+ tags : [
665+ 'sentry_region:st-test_region' ,
666+ 'source_tool:options-automator' ,
667+ 'source:options-automator' ,
668+ 'source_category:infra-tools' ,
669+ 'option_name:updated_option_1' ,
670+ 'sentry_user:options-automator' ,
671+ 'latency_seconds:2.5' ,
672+ ] ,
673+ } ,
674+ } ) ;
675+ } ) ;
676+
677+ it ( 'should not include latency_seconds tag when not present' , async function ( ) {
678+ await sendSentryOptionsUpdatesToDatadog ( testPartialPayload , 1699563828 ) ;
679+ expect ( datadogApiInstanceSpy ) . toHaveBeenCalledTimes ( 2 ) ;
680+
681+ const firstMessage = datadogApiInstanceSpy . mock . calls [ 0 ] [ 0 ] ;
682+ const secondMessage = datadogApiInstanceSpy . mock . calls [ 1 ] [ 0 ] ;
683+
684+ expect ( firstMessage . body . tags ) . not . toContain (
685+ expect . stringMatching ( / ^ l a t e n c y _ s e c o n d s : / )
686+ ) ;
687+ expect ( secondMessage . body . tags ) . not . toContain (
688+ expect . stringMatching ( / ^ l a t e n c y _ s e c o n d s : / )
689+ ) ;
690+ } ) ;
631691} ) ;
0 commit comments