Skip to content

Commit 1e29a72

Browse files
fix(core): throw AggregateError after Promise.allSettled to preserve caller failure detection
Keep Promise.allSettled for resilience (all providers get a chance to flush), but throw AggregateError if any failed so callers can still detect failures. Co-authored-by: Eric Allam <ericallam@users.noreply.github.com>
1 parent c5b5fde commit 1e29a72

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎packages/core/src/v3/otel/tracingSDK.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,16 @@ export class TracingSDK {
375375
this._meterProvider.forceFlush(),
376376
]);
377377
constproviderNames=["trace","log","meter"]asconst;
378+
consterrors: Error[]=[];
378379
results.forEach((result,index)=>{
379380
if(result.status==="rejected"){
380381
console.error(`Failed to flush ${providerNames[index]} provider:`,result.reason);
382+
errors.push(result.reasoninstanceofError ? result.reason : newError(String(result.reason)));
381383
}
382384
});
385+
if(errors.length>0){
386+
thrownewAggregateError(errors,"One or more providers failed to flush");
387+
}
383388
}
384389

385390
publicasyncshutdown(){
@@ -389,11 +394,16 @@ export class TracingSDK {
389394
this._meterProvider.shutdown(),
390395
]);
391396
constproviderNames=["trace","log","meter"]asconst;
397+
consterrors: Error[]=[];
392398
results.forEach((result,index)=>{
393399
if(result.status==="rejected"){
394400
console.error(`Failed to shutdown ${providerNames[index]} provider:`,result.reason);
401+
errors.push(result.reasoninstanceofError ? result.reason : newError(String(result.reason)));
395402
}
396403
});
404+
if(errors.length>0){
405+
thrownewAggregateError(errors,"One or more providers failed to shutdown");
406+
}
397407
}
398408
}
399409

0 commit comments

Comments
 (0)