@@ -88,10 +88,13 @@ class FailingMetricReader extends MetricReader {
8888}
8989
9090class FailingShutdownMetricReader extends MetricReader {
91+ shutdownAttempts = 0 ;
92+
9193 protected async onForceFlush ( ) : Promise < void > { }
9294
9395 protected async onShutdown ( ) : Promise < void > {
94- throw new Error ( "reader shutdown failed" ) ;
96+ this . shutdownAttempts ++ ;
97+ throw new Error ( `reader shutdown failed (attempt ${ this . shutdownAttempts } )` ) ;
9598 }
9699}
97100
@@ -202,4 +205,30 @@ describe("TracingSDK shutdown", () => {
202205
203206 expect ( recordingReader . shutdownCount ) . toBeGreaterThan ( 0 ) ;
204207 } ) ;
208+
209+ it ( "does not retry a metric reader that failed to shut down" , async ( ) => {
210+ const failingReader = new FailingShutdownMetricReader ( ) ;
211+
212+ const tracingSDK = new TracingSDK ( {
213+ url : "http://localhost:1" ,
214+ forceFlushTimeoutMillis : 5_000 ,
215+ diagLogLevel : "none" ,
216+ metricReaders : [ failingReader ] ,
217+ } ) ;
218+
219+ await tracingSDK . shutdown ( ) . catch ( ( ) => { } ) ;
220+
221+ expect ( failingReader . shutdownAttempts ) . toBe ( 1 ) ;
222+ } ) ;
223+
224+ it ( "reports the original shutdown failure, not a later one" , async ( ) => {
225+ const tracingSDK = new TracingSDK ( {
226+ url : "http://localhost:1" ,
227+ forceFlushTimeoutMillis : 5_000 ,
228+ diagLogLevel : "none" ,
229+ metricReaders : [ new FailingShutdownMetricReader ( ) ] ,
230+ } ) ;
231+
232+ await expect ( tracingSDK . shutdown ( ) ) . rejects . toThrow ( "attempt 1" ) ;
233+ } ) ;
205234} ) ;
0 commit comments