@@ -633,34 +633,39 @@ test("sendActivity() exports delivery metrics through OpenTelemetry SDK", async
633633 fetchMock . spyGlobal ( ) ;
634634 fetchMock . post ( "https://sdk-metrics.example/inbox" , { status : 202 } ) ;
635635
636- await sendActivity ( {
637- activity : {
638- "@context" : "https://www.w3.org/ns/activitystreams" ,
639- type : "Create" ,
640- id : "https://example.com/activity" ,
641- actor : "https://example.com/person" ,
642- } ,
643- activityId : "https://example.com/activity" ,
644- activityType : "https://www.w3.org/ns/activitystreams#Create" ,
645- keys : [ ] ,
646- inbox : new URL ( "https://sdk-metrics.example/inbox" ) ,
647- meterProvider,
648- } ) ;
649-
650- await meterProvider . forceFlush ( ) ;
651- const exportedMetrics = exporter . getMetrics ( )
652- . flatMap ( ( resourceMetrics ) => resourceMetrics . scopeMetrics )
653- . flatMap ( ( scopeMetrics ) => scopeMetrics . metrics ) ;
654- const sent = exportedMetrics . find ( ( metric ) =>
655- metric . descriptor . name === "activitypub.delivery.sent"
656- ) ;
657- assert ( sent != null ) ;
658- assertEquals ( sent . dataPoints . length , 1 ) ;
659- assertEquals (
660- sent . dataPoints [ 0 ] . attributes [ "activitypub.remote.host" ] ,
661- "sdk-metrics.example" ,
662- ) ;
636+ try {
637+ await sendActivity ( {
638+ activity : {
639+ "@context" : "https://www.w3.org/ns/activitystreams" ,
640+ type : "Create" ,
641+ id : "https://example.com/activity" ,
642+ actor : "https://example.com/person" ,
643+ } ,
644+ activityId : "https://example.com/activity" ,
645+ activityType : "https://www.w3.org/ns/activitystreams#Create" ,
646+ keys : [ ] ,
647+ inbox : new URL ( "https://sdk-metrics.example/inbox" ) ,
648+ meterProvider,
649+ } ) ;
663650
664- await meterProvider . shutdown ( ) ;
665- fetchMock . hardReset ( ) ;
651+ await meterProvider . forceFlush ( ) ;
652+ const exportedMetrics = exporter . getMetrics ( )
653+ . flatMap ( ( resourceMetrics ) => resourceMetrics . scopeMetrics )
654+ . flatMap ( ( scopeMetrics ) => scopeMetrics . metrics ) ;
655+ const sent = exportedMetrics . find ( ( metric ) =>
656+ metric . descriptor . name === "activitypub.delivery.sent"
657+ ) ;
658+ assert ( sent != null ) ;
659+ assertEquals ( sent . dataPoints . length , 1 ) ;
660+ assertEquals (
661+ sent . dataPoints [ 0 ] . attributes [ "activitypub.remote.host" ] ,
662+ "sdk-metrics.example" ,
663+ ) ;
664+ } finally {
665+ try {
666+ await meterProvider . shutdown ( ) ;
667+ } finally {
668+ fetchMock . hardReset ( ) ;
669+ }
670+ }
666671} ) ;
0 commit comments