Skip to content

Commit

Permalink
feat(sdk-metrics): PeriodicExportingMetricReader now flushes pending …
Browse files Browse the repository at this point in the history
…tasks at shutdown (#5242)
  • Loading branch information
macno authored Dec 10, 2024
1 parent 5387343 commit 79e2875
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :rocket: (Enhancement)

* feat(sdk-metrics): PeriodicExportingMetricReader now flushes pending tasks at shutdown [#5242](https://github.com/open-telemetry/opentelemetry-js/pull/5242)

### :bug: (Bug Fix)

* fix(sdk-trace-base): do not load OTEL_ env vars on module load, but when needed [#5224](https://github.com/open-telemetry/opentelemetry-js/pull/5224)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ describe('OTLPMetricExporter', () => {
meterProvider.getMeter('test-meter').createCounter('test-counter').add(1);

// act
meterProvider.forceFlush();
meterProvider.shutdown();
meterProvider.forceFlush().then(() => {
return meterProvider.shutdown();
});
});
});
});
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/MeterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class MeterProvider implements IMeterProvider {
}

/**
* Flush all buffered data and shut down the MeterProvider and all registered
* Shut down the MeterProvider and all registered
* MetricReaders.
*
* Returns a promise which is resolved when all flushes are complete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class PeriodicExportingMetricReader extends MetricReader {
if (this._interval) {
clearInterval(this._interval);
}

await this.onForceFlush();
await this._exporter.shutdown();
}
}
4 changes: 2 additions & 2 deletions packages/sdk-metrics/test/MeterProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ describe('MeterProvider', () => {
assert.strictEqual(meter1, meter2);
});

it('get a noop meter on shutdown', () => {
it('get a noop meter on shutdown', async () => {
const meterProvider = new MeterProvider();
meterProvider.shutdown();
await meterProvider.shutdown();
const meter = meterProvider.getMeter('meter1', '1.0.0');
// returned tracer should be no-op, not instance of Meter (from SDK)
assert.ok(!(meter instanceof Meter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ class TestMetricExporter implements PushMetricExporter {

async shutdown(): Promise<void> {
if (this._shutdown) return;
const flushPromise = this.forceFlush();
this._shutdown = true;
await flushPromise;
}

async forceFlush(): Promise<void> {
Expand Down

0 comments on commit 79e2875

Please sign in to comment.