@@ -18,6 +18,7 @@ import * as api from '@opentelemetry/api';
18
18
import { ConsoleLogger } from '@opentelemetry/core' ;
19
19
import { Resource } from '@opentelemetry/resources' ;
20
20
import { BaseBoundInstrument } from './BoundInstrument' ;
21
+ import { UpDownCounterMetric } from './UpDownCounterMetric' ;
21
22
import {
22
23
Metric ,
23
24
CounterMetric ,
@@ -72,10 +73,9 @@ export class Meter implements api.Meter {
72
73
return api . NOOP_VALUE_RECORDER_METRIC ;
73
74
}
74
75
const opt : MetricOptions = {
75
- absolute : true , // value recorders are defined as absolute by default
76
- monotonic : false , // not applicable to value recorder, set to false
77
76
logger : this . _logger ,
78
77
...DEFAULT_METRIC_OPTIONS ,
78
+ absolute : true , // value recorders are defined as absolute by default
79
79
...options ,
80
80
} ;
81
81
@@ -104,8 +104,6 @@ export class Meter implements api.Meter {
104
104
return api . NOOP_COUNTER_METRIC ;
105
105
}
106
106
const opt : MetricOptions = {
107
- monotonic : true , // Counters are defined as monotonic by default
108
- absolute : false , // not applicable to counter, set to false
109
107
logger : this . _logger ,
110
108
...DEFAULT_METRIC_OPTIONS ,
111
109
...options ,
@@ -115,6 +113,41 @@ export class Meter implements api.Meter {
115
113
return counter ;
116
114
}
117
115
116
+ /**
117
+ * Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous
118
+ * instrument and very similar to Counter except that Add(increment)
119
+ * supports negative increments. It is generally useful for capturing changes
120
+ * in an amount of resources used, or any quantity that rises and falls
121
+ * during a request.
122
+ *
123
+ * @param name the name of the metric.
124
+ * @param [options] the metric options.
125
+ */
126
+ createUpDownCounter (
127
+ name : string ,
128
+ options ?: api . MetricOptions
129
+ ) : api . UpDownCounter {
130
+ if ( ! this . _isValidName ( name ) ) {
131
+ this . _logger . warn (
132
+ `Invalid metric name ${ name } . Defaulting to noop metric implementation.`
133
+ ) ;
134
+ return api . NOOP_COUNTER_METRIC ;
135
+ }
136
+ const opt : MetricOptions = {
137
+ logger : this . _logger ,
138
+ ...DEFAULT_METRIC_OPTIONS ,
139
+ ...options ,
140
+ } ;
141
+ const upDownCounter = new UpDownCounterMetric (
142
+ name ,
143
+ opt ,
144
+ this . _batcher ,
145
+ this . _resource
146
+ ) ;
147
+ this . _registerMetric ( name , upDownCounter ) ;
148
+ return upDownCounter ;
149
+ }
150
+
118
151
/**
119
152
* Creates a new observer metric.
120
153
* @param name the name of the metric.
@@ -128,8 +161,6 @@ export class Meter implements api.Meter {
128
161
return api . NOOP_OBSERVER_METRIC ;
129
162
}
130
163
const opt : MetricOptions = {
131
- monotonic : false , // Observers are defined as non-monotonic by default
132
- absolute : false , // not applicable to observer, set to false
133
164
logger : this . _logger ,
134
165
...DEFAULT_METRIC_OPTIONS ,
135
166
...options ,
@@ -188,7 +219,8 @@ export class Meter implements api.Meter {
188
219
*
189
220
* 2. The first character must be non-numeric, non-space, non-punctuation
190
221
*
191
- * 3. Subsequent characters must be belong to the alphanumeric characters, '_', '.', and '-'.
222
+ * 3. Subsequent characters must be belong to the alphanumeric characters,
223
+ * '_', '.', and '-'.
192
224
*
193
225
* Names are case insensitive
194
226
*
0 commit comments