@@ -21,6 +21,7 @@ import {
21
21
Meter ,
22
22
Metric ,
23
23
MetricOptions ,
24
+ MetricUtils ,
24
25
MeasureHandle ,
25
26
SpanContext ,
26
27
LabelSet ,
@@ -110,6 +111,38 @@ export class NoopMetric<T> implements Metric<T> {
110
111
}
111
112
}
112
113
114
+ export class NoopCounterMetric extends NoopMetric < CounterHandle >
115
+ implements Pick < MetricUtils , 'add' > {
116
+ add ( value : number , labelSet : LabelSet ) {
117
+ this . getHandle ( labelSet ) . add ( value ) ;
118
+ }
119
+ }
120
+
121
+ export class NoopGaugeMetric extends NoopMetric < GaugeHandle >
122
+ implements Pick < MetricUtils , 'set' > {
123
+ set ( value : number , labelSet : LabelSet ) {
124
+ this . getHandle ( labelSet ) . set ( value ) ;
125
+ }
126
+ }
127
+
128
+ export class NoopMeasureMetric extends NoopMetric < MeasureHandle >
129
+ implements Pick < MetricUtils , 'record' > {
130
+ record (
131
+ value : number ,
132
+ labelSet : LabelSet ,
133
+ distContext ?: DistributedContext ,
134
+ spanContext ?: SpanContext
135
+ ) {
136
+ if ( typeof distContext === 'undefined' ) {
137
+ this . getHandle ( labelSet ) . record ( value ) ;
138
+ } else if ( typeof spanContext === 'undefined' ) {
139
+ this . getHandle ( labelSet ) . record ( value , distContext ) ;
140
+ } else {
141
+ this . getHandle ( labelSet ) . record ( value , distContext , spanContext ) ;
142
+ }
143
+ }
144
+ }
145
+
113
146
export class NoopCounterHandle implements CounterHandle {
114
147
add ( value : number ) : void {
115
148
return ;
@@ -133,16 +166,12 @@ export class NoopMeasureHandle implements MeasureHandle {
133
166
}
134
167
135
168
export const NOOP_GAUGE_HANDLE = new NoopGaugeHandle ( ) ;
136
- export const NOOP_GAUGE_METRIC = new NoopMetric < GaugeHandle > ( NOOP_GAUGE_HANDLE ) ;
169
+ export const NOOP_GAUGE_METRIC = new NoopGaugeMetric ( NOOP_GAUGE_HANDLE ) ;
137
170
138
171
export const NOOP_COUNTER_HANDLE = new NoopCounterHandle ( ) ;
139
- export const NOOP_COUNTER_METRIC = new NoopMetric < CounterHandle > (
140
- NOOP_COUNTER_HANDLE
141
- ) ;
172
+ export const NOOP_COUNTER_METRIC = new NoopCounterMetric ( NOOP_COUNTER_HANDLE ) ;
142
173
143
174
export const NOOP_MEASURE_HANDLE = new NoopMeasureHandle ( ) ;
144
- export const NOOP_MEASURE_METRIC = new NoopMetric < MeasureHandle > (
145
- NOOP_MEASURE_HANDLE
146
- ) ;
175
+ export const NOOP_MEASURE_METRIC = new NoopMeasureMetric ( NOOP_MEASURE_HANDLE ) ;
147
176
148
177
export const NOOP_LABEL_SET = { } as LabelSet ;
0 commit comments