Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- Drop support for Node.js versions 16, 18, 20, 21 and 23
- Metric internal storage ('hashMap') changed to a separate object, LabelMap. If you have
subclassed the built-in metric types you may need to adjust your code.
- Counter Exemplars now report the value rather than the delta

### Changed

Expand Down
4 changes: 2 additions & 2 deletions lib/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Counter extends Metric {
throw new Error('It is not possible to decrease a counter');
}

if (value === null || value === undefined) value = 1;
value = value ?? 1;

this.store.validate(labels);
this.store.setDelta(labels, value);
Expand All @@ -68,7 +68,7 @@ class Counter extends Metric {
exemplarLabels = this.defaultExemplarLabelSet,
} = {}) {
this.incWithoutExemplar(labels, value);
this.updateExemplar(labels, exemplarLabels, value);
this.updateExemplar(labels, exemplarLabels, this.store.get(labels));
}

updateExemplar(labels, exemplarLabels, value) {
Expand Down
5 changes: 4 additions & 1 deletion test/exemplarsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ describe('Exemplars', () => {
labelNames: ['method', 'code'],
enableExemplars: true,
});

counterInstance.inc({
labels: { method: 'get', code: '200' },
}); // 1
counterInstance.inc({
value: 2,
labels: { method: 'get', code: '200' },
exemplarLabels: { traceId: 'trace_id_test', spanId: 'span_id_test' },
});
Expand Down
Loading