diff --git a/.changeset/fix-tracing-sdk-flush.md b/.changeset/fix-tracing-sdk-flush.md new file mode 100644 index 00000000000..e11a84397fd --- /dev/null +++ b/.changeset/fix-tracing-sdk-flush.md @@ -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. diff --git a/packages/core/src/v3/otel/tracingSDK.ts b/packages/core/src/v3/otel/tracingSDK.ts index a301946c755..46e3fbfbf8f 100644 --- a/packages/core/src/v3/otel/tracingSDK.ts +++ b/packages/core/src/v3/otel/tracingSDK.ts @@ -369,19 +369,43 @@ 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; + const errors: Error[] = []; + const failedNames: string[] = []; + results.forEach((result, index) => { + if (result.status === "rejected") { + failedNames.push(providerNames[index]); + errors.push(result.reason instanceof Error ? result.reason : new Error(String(result.reason))); + } + }); + if (errors.length > 0) { + throw new AggregateError(errors, `One or more providers failed to flush: ${failedNames.join(", ")}`); + } } 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; + const errors: Error[] = []; + const failedNames: string[] = []; + results.forEach((result, index) => { + if (result.status === "rejected") { + failedNames.push(providerNames[index]); + errors.push(result.reason instanceof Error ? result.reason : new Error(String(result.reason))); + } + }); + if (errors.length > 0) { + throw new AggregateError(errors, `One or more providers failed to shutdown: ${failedNames.join(", ")}`); + } } }