fix(core): use Promise.allSettled in TracingSDK flush/shutdown
Switch TracingSDK.flush() and shutdown() from Promise.all to Promise.allSettled to prevent one provider's rejection from abandoning the other providers' in-flight exports. This fixes an issue where user-emitted trace data (logger.info calls, child spans) could be silently dropped on shutdown when any provider fails to flush, particularly affecting self-hosted deployments with processKeepAliveEnabled: false. Fixes #3556 Co-authored-by: Eric Allam <ericallam@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/core": patch
|
||||
---
|
||||
|
||||
Fixed TracingSDK.flush() and shutdown() to use Promise.allSettled instead of Promise.all, preventing one provider's rejection from abandoning the other providers' in-flight exports. This fixes an issue where user-emitted trace data (logger.info calls, child spans) could be silently dropped on shutdown when any provider fails to flush.
|
||||
@@ -369,19 +369,31 @@ export class TracingSDK {
|
||||
}
|
||||
|
||||
public async flush() {
|
||||
await Promise.all([
|
||||
const results = await Promise.allSettled([
|
||||
this._traceProvider.forceFlush(),
|
||||
this._logProvider.forceFlush(),
|
||||
this._meterProvider.forceFlush(),
|
||||
]);
|
||||
const providerNames = ["trace", "log", "meter"] as const;
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === "rejected") {
|
||||
console.error(`Failed to flush ${providerNames[index]} provider:`, result.reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async shutdown() {
|
||||
await Promise.all([
|
||||
const results = await Promise.allSettled([
|
||||
this._traceProvider.shutdown(),
|
||||
this._logProvider.shutdown(),
|
||||
this._meterProvider.shutdown(),
|
||||
]);
|
||||
const providerNames = ["trace", "log", "meter"] as const;
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === "rejected") {
|
||||
console.error(`Failed to shutdown ${providerNames[index]} provider:`, result.reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user