Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-metrics): InMemoryMetricExporter clear metrics after shutdown #5214

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :boom: Breaking Change

* fix(sdk-metrics): InMemoryMetricExporter clear metrics after shutdown to align with other exporters [#5131](https://github.com/open-telemetry/opentelemetry-js/issues/5131) @paper2

### :rocket: (Enhancement)

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class InMemoryMetricExporter implements PushMetricExporter {

shutdown(): Promise<void> {
this._shutdown = true;
this._metrics = [];
return Promise.resolve();
}
}
18 changes: 18 additions & 0 deletions packages/sdk-metrics/test/export/InMemoryMetricExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ describe('InMemoryMetricExporter', () => {
await metricReader.shutdown();
});

it('should get no metrics after shutdown', async () => {
const counter = meter.createCounter('counter_total', {
description: 'a test description',
});
const counterAttribute = { key1: 'attributeValue1' };
counter.add(10, counterAttribute);

const exportedMetrics = await waitForNumberOfExports(exporter, 1);
assert.ok(exportedMetrics.length > 0);

await exporter.shutdown();

const otherMetrics = exporter.getMetrics();
assert.strictEqual(otherMetrics.length, 0);

await metricReader.shutdown();
});

it('should be able to access metric', async () => {
const counter = meter.createCounter('counter_total', {
description: 'a test description',
Expand Down
Loading