Skip to content

Commit b6f9d2a

Browse files
authored
chore: rename meaure to value recorder (#1117)
1 parent c7461d4 commit b6f9d2a

File tree

15 files changed

+168
-128
lines changed

15 files changed

+168
-128
lines changed

Diff for: packages/opentelemetry-api/src/metrics/BoundInstrument.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ export interface BoundCounter {
2626
add(value: number): void;
2727
}
2828

29-
/** Measure to report instantaneous measurement of a value. */
30-
export interface BoundMeasure {
29+
/** ValueRecorder to report instantaneous measurement of a value. */
30+
export interface BoundValueRecorder {
3131
/**
32-
* Records the given value to this measure.
33-
* @param value the measurement to record.
32+
* Records the given value to this value recorder.
33+
* @param value to record.
3434
* @param correlationContext the correlationContext associated with the
35-
* measurements.
35+
* values.
3636
* @param spanContext the {@link SpanContext} that identifies the {@link Span}
37-
* for which the measurements are associated with.
37+
* which the values are associated with.
3838
*/
3939
record(value: number): void;
4040
record(value: number, correlationContext: CorrelationContext): void;

Diff for: packages/opentelemetry-api/src/metrics/Meter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { MetricOptions, Counter, Measure, Observer } from './Metric';
17+
import { MetricOptions, Counter, ValueRecorder, Observer } from './Metric';
1818

1919
/**
2020
* An interface to allow the recording metrics.
2121
*
2222
* {@link Metric}s are used for recording pre-defined aggregation (`Counter`),
23-
* or raw values (`Measure`) in which the aggregation and labels
23+
* or raw values (`ValueRecorder`) in which the aggregation and labels
2424
* for the exported metric are deferred.
2525
*/
2626
export interface Meter {
2727
/**
28-
* Creates and returns a new `Measure`.
28+
* Creates and returns a new `ValueRecorder`.
2929
* @param name the name of the metric.
3030
* @param [options] the metric options.
3131
*/
32-
createMeasure(name: string, options?: MetricOptions): Measure;
32+
createValueRecorder(name: string, options?: MetricOptions): ValueRecorder;
3333

3434
/**
3535
* Creates a new `Counter` metric. Generally, this kind of metric when the

Diff for: packages/opentelemetry-api/src/metrics/Metric.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { CorrelationContext } from '../correlation_context/CorrelationContext';
1818
import { SpanContext } from '../trace/span_context';
1919
import { ObserverResult } from './ObserverResult';
20-
import { BoundCounter, BoundMeasure } from './BoundInstrument';
20+
import { BoundCounter, BoundValueRecorder } from './BoundInstrument';
2121

2222
/**
2323
* Options needed for metric creation
@@ -56,7 +56,7 @@ export interface MetricOptions {
5656
monotonic?: boolean;
5757

5858
/**
59-
* (Measure only, default true) Asserts that this metric will only accept
59+
* (ValueRecorder only, default true) Asserts that this metric will only accept
6060
* non-negative values (e.g. disk usage).
6161
*/
6262
absolute?: boolean;
@@ -128,9 +128,9 @@ export interface Counter extends UnboundMetric<BoundCounter> {
128128
add(value: number, labels?: Labels): void;
129129
}
130130

131-
export interface Measure extends UnboundMetric<BoundMeasure> {
131+
export interface ValueRecorder extends UnboundMetric<BoundValueRecorder> {
132132
/**
133-
* Records the given value to this measure.
133+
* Records the given value to this value recorder.
134134
*/
135135
record(value: number, labels?: Labels): void;
136136

Diff for: packages/opentelemetry-api/src/metrics/NoopMeter.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import {
2020
UnboundMetric,
2121
Labels,
2222
Counter,
23-
Measure,
23+
ValueRecorder,
2424
Observer,
2525
} from './Metric';
26-
import { BoundMeasure, BoundCounter } from './BoundInstrument';
26+
import { BoundValueRecorder, BoundCounter } from './BoundInstrument';
2727
import { CorrelationContext } from '../correlation_context/CorrelationContext';
2828
import { SpanContext } from '../trace/span_context';
2929
import { ObserverResult } from './ObserverResult';
@@ -36,12 +36,12 @@ export class NoopMeter implements Meter {
3636
constructor() {}
3737

3838
/**
39-
* Returns constant noop measure.
39+
* Returns constant noop value recorder.
4040
* @param name the name of the metric.
4141
* @param [options] the metric options.
4242
*/
43-
createMeasure(name: string, options?: MetricOptions): Measure {
44-
return NOOP_MEASURE_METRIC;
43+
createValueRecorder(name: string, options?: MetricOptions): ValueRecorder {
44+
return NOOP_VALUE_RECORDER_METRIC;
4545
}
4646

4747
/**
@@ -103,8 +103,8 @@ export class NoopCounterMetric extends NoopMetric<BoundCounter>
103103
}
104104
}
105105

106-
export class NoopMeasureMetric extends NoopMetric<BoundMeasure>
107-
implements Measure {
106+
export class NoopValueRecorderMetric extends NoopMetric<BoundValueRecorder>
107+
implements ValueRecorder {
108108
record(
109109
value: number,
110110
labels: Labels,
@@ -131,7 +131,7 @@ export class NoopBoundCounter implements BoundCounter {
131131
}
132132
}
133133

134-
export class NoopBoundMeasure implements BoundMeasure {
134+
export class NoopBoundValueRecorder implements BoundValueRecorder {
135135
record(
136136
value: number,
137137
correlationContext?: CorrelationContext,
@@ -145,7 +145,9 @@ export const NOOP_METER = new NoopMeter();
145145
export const NOOP_BOUND_COUNTER = new NoopBoundCounter();
146146
export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER);
147147

148-
export const NOOP_BOUND_MEASURE = new NoopBoundMeasure();
149-
export const NOOP_MEASURE_METRIC = new NoopMeasureMetric(NOOP_BOUND_MEASURE);
148+
export const NOOP_BOUND_VALUE_RECORDER = new NoopBoundValueRecorder();
149+
export const NOOP_VALUE_RECORDER_METRIC = new NoopValueRecorderMetric(
150+
NOOP_BOUND_VALUE_RECORDER
151+
);
150152

151153
export const NOOP_OBSERVER_METRIC = new NoopObserverMetric();

Diff for: packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import * as assert from 'assert';
1818
import {
1919
NoopMeterProvider,
2020
NOOP_BOUND_COUNTER,
21-
NOOP_BOUND_MEASURE,
21+
NOOP_BOUND_VALUE_RECORDER,
2222
NOOP_COUNTER_METRIC,
23-
NOOP_MEASURE_METRIC,
23+
NOOP_VALUE_RECORDER_METRIC,
2424
} from '../../src';
2525

2626
describe('NoopMeter', () => {
@@ -38,20 +38,23 @@ describe('NoopMeter', () => {
3838
assert.strictEqual(counter.bind(labels), NOOP_BOUND_COUNTER);
3939
counter.clear();
4040

41-
const measure = meter.createMeasure('some-name');
42-
measure.bind(labels).record(1);
41+
const valueRecorder = meter.createValueRecorder('some-name');
42+
valueRecorder.bind(labels).record(1);
4343

4444
// ensure the correct noop const is returned
45-
assert.strictEqual(measure, NOOP_MEASURE_METRIC);
46-
assert.strictEqual(measure.bind(labels), NOOP_BOUND_MEASURE);
45+
assert.strictEqual(valueRecorder, NOOP_VALUE_RECORDER_METRIC);
46+
assert.strictEqual(valueRecorder.bind(labels), NOOP_BOUND_VALUE_RECORDER);
4747

4848
const options = {
4949
component: 'tests',
5050
description: 'the testing package',
5151
};
5252

53-
const measureWithOptions = meter.createMeasure('some-name', options);
54-
assert.strictEqual(measureWithOptions, NOOP_MEASURE_METRIC);
53+
const valueRecorderWithOptions = meter.createValueRecorder(
54+
'some-name',
55+
options
56+
);
57+
assert.strictEqual(valueRecorderWithOptions, NOOP_VALUE_RECORDER_METRIC);
5558
const counterWithOptions = meter.createCounter('some-name', options);
5659
assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC);
5760
});

Diff for: packages/opentelemetry-metrics/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ setInterval(()=> {
7373

7474
See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/prometheus) for a short example.
7575

76-
### Measure
77-
***Work in progress***
76+
### Value Recorder
77+
78+
`ValueRecorder` is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative.
79+
Values captured by `ValueRecorder.record(value)` are treated as individual events belonging to a distribution that is being summarized.
80+
`ValueRecorder` should be chosen either when capturing measurements that do not contribute meaningfully to a sum, or when capturing numbers that are additive in nature, but where the distribution of individual increments is considered interesting.
7881

7982
## Useful links
8083
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

Diff for: packages/opentelemetry-metrics/src/BoundInstrument.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export class BoundCounter extends BaseBoundInstrument
9393
}
9494

9595
/**
96-
* BoundMeasure is an implementation of the {@link BoundMeasure} interface.
96+
* BoundValueRecorder is an implementation of the {@link BoundValueRecorder} interface.
9797
*/
98-
export class BoundMeasure extends BaseBoundInstrument
99-
implements api.BoundMeasure {
98+
export class BoundValueRecorder extends BaseBoundInstrument
99+
implements api.BoundValueRecorder {
100100
private readonly _absolute: boolean;
101101

102102
constructor(
@@ -119,7 +119,7 @@ export class BoundMeasure extends BaseBoundInstrument
119119
): void {
120120
if (this._absolute && value < 0) {
121121
this._logger.error(
122-
`Absolute measure cannot contain negative values for $${Object.values(
122+
`Absolute ValueRecorder cannot contain negative values for $${Object.values(
123123
this._labels
124124
)}`
125125
);

Diff for: packages/opentelemetry-metrics/src/Meter.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import * as api from '@opentelemetry/api';
1818
import { ConsoleLogger } from '@opentelemetry/core';
1919
import { Resource } from '@opentelemetry/resources';
2020
import { BaseBoundInstrument } from './BoundInstrument';
21-
import { Metric, CounterMetric, MeasureMetric, ObserverMetric } from './Metric';
21+
import {
22+
Metric,
23+
CounterMetric,
24+
ValueRecorderMetric,
25+
ObserverMetric,
26+
} from './Metric';
2227
import {
2328
MetricOptions,
2429
DEFAULT_METRIC_OPTIONS,
@@ -52,28 +57,36 @@ export class Meter implements api.Meter {
5257
}
5358

5459
/**
55-
* Creates and returns a new {@link Measure}.
60+
* Creates and returns a new {@link ValueRecorder}.
5661
* @param name the name of the metric.
5762
* @param [options] the metric options.
5863
*/
59-
createMeasure(name: string, options?: api.MetricOptions): api.Measure {
64+
createValueRecorder(
65+
name: string,
66+
options?: api.MetricOptions
67+
): api.ValueRecorder {
6068
if (!this._isValidName(name)) {
6169
this._logger.warn(
6270
`Invalid metric name ${name}. Defaulting to noop metric implementation.`
6371
);
64-
return api.NOOP_MEASURE_METRIC;
72+
return api.NOOP_VALUE_RECORDER_METRIC;
6573
}
6674
const opt: MetricOptions = {
67-
absolute: true, // Measures are defined as absolute by default
68-
monotonic: false, // not applicable to measure, set to false
75+
absolute: true, // value recorders are defined as absolute by default
76+
monotonic: false, // not applicable to value recorder, set to false
6977
logger: this._logger,
7078
...DEFAULT_METRIC_OPTIONS,
7179
...options,
7280
};
7381

74-
const measure = new MeasureMetric(name, opt, this._batcher, this._resource);
75-
this._registerMetric(name, measure);
76-
return measure;
82+
const valueRecorder = new ValueRecorderMetric(
83+
name,
84+
opt,
85+
this._batcher,
86+
this._resource
87+
);
88+
this._registerMetric(name, valueRecorder);
89+
return valueRecorder;
7790
}
7891

7992
/**

Diff for: packages/opentelemetry-metrics/src/Metric.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Resource } from '@opentelemetry/resources';
1919
import {
2020
BoundCounter,
2121
BaseBoundInstrument,
22-
BoundMeasure,
22+
BoundValueRecorder,
2323
BoundObserver,
2424
} from './BoundInstrument';
2525
import { ObserverResult } from './ObserverResult';
@@ -139,7 +139,8 @@ export class CounterMetric extends Metric<BoundCounter> implements api.Counter {
139139
}
140140
}
141141

142-
export class MeasureMetric extends Metric<BoundMeasure> implements api.Measure {
142+
export class ValueRecorderMetric extends Metric<BoundValueRecorder>
143+
implements api.ValueRecorder {
143144
protected readonly _absolute: boolean;
144145

145146
constructor(
@@ -148,12 +149,12 @@ export class MeasureMetric extends Metric<BoundMeasure> implements api.Measure {
148149
private readonly _batcher: Batcher,
149150
resource: Resource
150151
) {
151-
super(name, options, MetricKind.MEASURE, resource);
152+
super(name, options, MetricKind.VALUE_RECORDER, resource);
152153

153154
this._absolute = options.absolute !== undefined ? options.absolute : true; // Absolute default is true
154155
}
155-
protected _makeInstrument(labels: api.Labels): BoundMeasure {
156-
return new BoundMeasure(
156+
protected _makeInstrument(labels: api.Labels): BoundValueRecorder {
157+
return new BoundValueRecorder(
157158
labels,
158159
this._disabled,
159160
this._monotonic,

Diff for: packages/opentelemetry-metrics/src/export/Batcher.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import {
1818
CounterSumAggregator,
19-
MeasureExactAggregator,
19+
ValueRecorderExactAggregator,
2020
ObserverAggregator,
2121
} from './aggregators';
2222
import {
@@ -59,7 +59,7 @@ export class UngroupedBatcher extends Batcher {
5959
case MetricKind.OBSERVER:
6060
return new ObserverAggregator();
6161
default:
62-
return new MeasureExactAggregator();
62+
return new ValueRecorderExactAggregator();
6363
}
6464
}
6565

Diff for: packages/opentelemetry-metrics/src/export/aggregators/measureexact.ts renamed to packages/opentelemetry-metrics/src/export/aggregators/ValueRecorderExact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { hrTime } from '@opentelemetry/core';
2020
import { Distribution } from '../types';
2121

2222
/** Basic aggregator keeping all raw values (events, sum, max and min). */
23-
export class MeasureExactAggregator implements Aggregator {
23+
export class ValueRecorderExactAggregator implements Aggregator {
2424
private _distribution: Distribution;
2525
private _lastUpdateTime: HrTime = [0, 0];
2626

Diff for: packages/opentelemetry-metrics/src/export/aggregators/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
export * from './countersum';
1818
export * from './observer';
19-
export * from './measureexact';
19+
export * from './ValueRecorderExact';
2020
export * from './histogram';

Diff for: packages/opentelemetry-metrics/src/export/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Resource } from '@opentelemetry/resources';
2121
/** The kind of metric. */
2222
export enum MetricKind {
2323
COUNTER,
24-
MEASURE,
24+
VALUE_RECORDER,
2525
OBSERVER,
2626
}
2727

Diff for: packages/opentelemetry-metrics/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface MetricOptions {
4343
/** Monotonic metrics may only increase. */
4444
monotonic: boolean;
4545

46-
/** (Measure only) Asserts that this metric will only accept non-negative values. */
46+
/** (ValueRecorder only) Asserts that this metric will only accept non-negative values. */
4747
absolute: boolean;
4848

4949
/** User provided logger. */

0 commit comments

Comments
 (0)