Skip to content

Commit d339cf4

Browse files
committed
fixup! feat(instrumentation): added synchronous gauge
1 parent b57098d commit d339cf4

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

api/src/metrics/Metric.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface Gauge<
102102
AttributesTypes extends MetricAttributes = MetricAttributes,
103103
> {
104104
/**
105-
* Records a measurement. Value of the measurement must not be negative.
105+
* Records a measurement.
106106
*/
107107
record(value: number, attributes?: AttributesTypes, context?: Context): void;
108108
}

packages/sdk-metrics/test/Instruments.test.ts

+41-6
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ import * as sinon from 'sinon';
1919
import { InstrumentationScope } from '@opentelemetry/core';
2020
import { Resource } from '@opentelemetry/resources';
2121
import {
22-
InstrumentType,
23-
MeterProvider,
24-
MetricReader,
2522
DataPoint,
2623
DataPointType,
2724
Histogram,
25+
InstrumentType,
26+
MeterProvider,
2827
MetricDescriptor,
28+
MetricReader,
2929
} from '../src';
3030
import {
3131
TestDeltaMetricReader,
3232
TestMetricReader,
3333
} from './export/TestMetricReader';
3434
import {
35-
assertMetricData,
3635
assertDataPoint,
37-
commonValues,
36+
assertMetricData,
3837
commonAttributes,
39-
defaultResource,
38+
commonValues,
4039
defaultInstrumentationScope,
40+
defaultResource,
4141
} from './util';
4242
import { ObservableResult, ValueType } from '@opentelemetry/api';
4343

@@ -764,6 +764,41 @@ describe('Instruments', () => {
764764
});
765765
});
766766
});
767+
768+
describe('Gauge', () => {
769+
it('should record common values and attributes without exceptions', async () => {
770+
const { meter } = setup();
771+
const gauge = meter.createGauge('test');
772+
773+
for (const values of commonValues) {
774+
for (const attributes of commonAttributes) {
775+
gauge.record(values, attributes);
776+
}
777+
}
778+
});
779+
780+
it('should record values', async () => {
781+
const { meter, cumulativeReader } = setup();
782+
const gauge = meter.createGauge('test');
783+
784+
gauge.record(1, { foo: 'bar' });
785+
gauge.record(-1);
786+
787+
await validateExport(cumulativeReader, {
788+
dataPointType: DataPointType.GAUGE,
789+
dataPoints: [
790+
{
791+
attributes: { foo: 'bar' },
792+
value: 1,
793+
},
794+
{
795+
attributes: {},
796+
value: -1,
797+
},
798+
],
799+
});
800+
});
801+
});
767802
});
768803

769804
function setup() {

0 commit comments

Comments
 (0)