Skip to content

Commit a4af9bc

Browse files
committed
fix(core): do not retry a metric reader that failed to shut down
1 parent 93933a2 commit a4af9bc

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@ class FailingMetricReader extends MetricReader {
8888
}
8989

9090
class 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
});

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,8 @@ export class TracingSDK {
359359
}
360360

361361
private async _shutdownMetricReadersSerially() {
362-
try {
363-
await this._eachMetricReaderSerially("shut down", (reader) => reader.shutdown());
364-
} finally {
365-
await this._meterProvider.shutdown();
366-
}
362+
await this._eachMetricReaderSerially("shut down", (reader) => reader.shutdown());
363+
await this._meterProvider.shutdown();
367364
}
368365

369366
private async _eachMetricReaderSerially(

packages/core/src/v3/taskContext/otelProcessors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function gauge(name: string, values: number[]): MetricData {
3939
aggregationTemporality: AggregationTemporality.CUMULATIVE,
4040
dataPointType: DataPointType.GAUGE,
4141
dataPoints: values.map((value) => ({
42-
attributes: { "process.cpu.state": String(value) },
42+
attributes: { "process.cpu.state": "user" },
4343
startTime: [1786481102, 584000000],
4444
endTime: [1786481102, 698000000],
4545
value,
@@ -71,7 +71,7 @@ function histogram(name: string, sums: number[]): MetricData {
7171
aggregationTemporality: AggregationTemporality.DELTA,
7272
dataPointType: DataPointType.HISTOGRAM,
7373
dataPoints: sums.map((sum) => ({
74-
attributes: { sum: String(sum) },
74+
attributes: { "task.status": "completed" },
7575
startTime: [1786481102, 584000000],
7676
endTime: [1786481102, 698000000],
7777
value: {

0 commit comments

Comments
 (0)