File tree 6 files changed +50
-2
lines changed
test/common/noop-implementations
experimental/packages/opentelemetry-exporter-metrics-otlp-http/src
6 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export { MeterProvider } from './metrics/MeterProvider';
43
43
export {
44
44
ValueType ,
45
45
Counter ,
46
+ Gauge ,
46
47
Histogram ,
47
48
MetricOptions ,
48
49
Observable ,
Original file line number Diff line number Diff line change 17
17
import {
18
18
BatchObservableCallback ,
19
19
Counter ,
20
+ Gauge ,
20
21
Histogram ,
21
22
MetricAttributes ,
22
23
MetricOptions ,
@@ -45,6 +46,16 @@ export interface MeterOptions {
45
46
* for the exported metric are deferred.
46
47
*/
47
48
export interface Meter {
49
+ /**
50
+ * Creates and returns a new `Gauge`.
51
+ * @param name the name of the metric.
52
+ * @param [options] the metric options.
53
+ */
54
+ createGauge < AttributesTypes extends MetricAttributes = MetricAttributes > (
55
+ name : string ,
56
+ options ?: MetricOptions
57
+ ) : Gauge < AttributesTypes > ;
58
+
48
59
/**
49
60
* Creates and returns a new `Histogram`.
50
61
* @param name the name of the metric.
Original file line number Diff line number Diff line change @@ -98,6 +98,15 @@ export interface UpDownCounter<
98
98
add ( value : number , attributes ?: AttributesTypes , context ?: Context ) : void ;
99
99
}
100
100
101
+ export interface Gauge <
102
+ AttributesTypes extends MetricAttributes = MetricAttributes ,
103
+ > {
104
+ /**
105
+ * Records a measurement. Value of the measurement must not be negative.
106
+ */
107
+ record ( value : number , attributes ?: AttributesTypes , context ?: Context ) : void ;
108
+ }
109
+
101
110
export interface Histogram <
102
111
AttributesTypes extends MetricAttributes = MetricAttributes ,
103
112
> {
Original file line number Diff line number Diff line change @@ -18,15 +18,16 @@ import { Meter } from './Meter';
18
18
import {
19
19
BatchObservableCallback ,
20
20
Counter ,
21
+ Gauge ,
21
22
Histogram ,
23
+ MetricAttributes ,
22
24
MetricOptions ,
25
+ Observable ,
23
26
ObservableCallback ,
24
27
ObservableCounter ,
25
28
ObservableGauge ,
26
29
ObservableUpDownCounter ,
27
30
UpDownCounter ,
28
- MetricAttributes ,
29
- Observable ,
30
31
} from './Metric' ;
31
32
32
33
/**
@@ -36,6 +37,13 @@ import {
36
37
export class NoopMeter implements Meter {
37
38
constructor ( ) { }
38
39
40
+ /**
41
+ * @see {@link Meter.createGauge }
42
+ */
43
+ createGauge ( _name : string , _options ?: MetricOptions ) : Histogram {
44
+ return NOOP_GAUGE_METRIC ;
45
+ }
46
+
39
47
/**
40
48
* @see {@link Meter.createHistogram }
41
49
*/
@@ -114,6 +122,10 @@ export class NoopUpDownCounterMetric
114
122
add ( _value : number , _attributes : MetricAttributes ) : void { }
115
123
}
116
124
125
+ export class NoopGaugeMetric extends NoopMetric implements Gauge {
126
+ record ( _value : number , _attributes : MetricAttributes ) : void { }
127
+ }
128
+
117
129
export class NoopHistogramMetric extends NoopMetric implements Histogram {
118
130
record ( _value : number , _attributes : MetricAttributes ) : void { }
119
131
}
@@ -140,6 +152,7 @@ export const NOOP_METER = new NoopMeter();
140
152
141
153
// Synchronous instruments
142
154
export const NOOP_COUNTER_METRIC = new NoopCounterMetric ( ) ;
155
+ export const NOOP_GAUGE_METRIC = new NoopGaugeMetric ( ) ;
143
156
export const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric ( ) ;
144
157
export const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric ( ) ;
145
158
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
24
24
NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC ,
25
25
NOOP_UP_DOWN_COUNTER_METRIC ,
26
26
createNoopMeter ,
27
+ NOOP_GAUGE_METRIC ,
27
28
} from '../../../src/metrics/NoopMeter' ;
28
29
import { NoopMeterProvider } from '../../../src/metrics/NoopMeterProvider' ;
29
30
@@ -116,6 +117,17 @@ describe('NoopMeter', () => {
116
117
) ;
117
118
} ) ;
118
119
120
+ it ( 'gauge should not crash' , ( ) => {
121
+ const meter = new NoopMeterProvider ( ) . getMeter ( 'test-noop' ) ;
122
+ const observableGauge = meter . createGauge ( 'some-name' ) ;
123
+
124
+ // ensure the correct noop const is returned
125
+ assert . strictEqual ( observableGauge , NOOP_GAUGE_METRIC ) ;
126
+
127
+ const gaugeWithOptions = meter . createGauge ( 'some-name' , options ) ;
128
+ assert . strictEqual ( gaugeWithOptions , NOOP_GAUGE_METRIC ) ;
129
+ } ) ;
130
+
119
131
it ( 'observable up down counter should not crash' , ( ) => {
120
132
const meter = new NoopMeterProvider ( ) . getMeter ( 'test-noop' ) ;
121
133
const observableUpDownCounter =
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ export const DeltaTemporalitySelector: AggregationTemporalitySelector = (
41
41
switch ( instrumentType ) {
42
42
case InstrumentType . COUNTER :
43
43
case InstrumentType . OBSERVABLE_COUNTER :
44
+ case InstrumentType . GAUGE :
44
45
case InstrumentType . HISTOGRAM :
45
46
case InstrumentType . OBSERVABLE_GAUGE :
46
47
return AggregationTemporality . DELTA ;
@@ -57,6 +58,7 @@ export const LowMemoryTemporalitySelector: AggregationTemporalitySelector = (
57
58
case InstrumentType . COUNTER :
58
59
case InstrumentType . HISTOGRAM :
59
60
return AggregationTemporality . DELTA ;
61
+ case InstrumentType . GAUGE :
60
62
case InstrumentType . UP_DOWN_COUNTER :
61
63
case InstrumentType . OBSERVABLE_UP_DOWN_COUNTER :
62
64
case InstrumentType . OBSERVABLE_COUNTER :
You can’t perform that action at this time.
0 commit comments