Skip to content

Commit

Permalink
refactor(sdk-metrics): replace MetricsAttributes with Attributes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna authored Sep 27, 2024
1 parent 2f919a4 commit 466140b
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

* deps: set `@opentelemetry/api` dependency min version to 1.3.0 in `examples`, `experimental/packages`, `integration-tests` and `selenium-tests`
[#4992](https://github.com/open-telemetry/opentelemetry-js/pull/4992)
* refactor(sdk-metrics): replace `MetricsAttributes` with `Attributes` [#5021](https://github.com/open-telemetry/opentelemetry-js/pull/5021) @david-luna

## 1.26.0

Expand Down
12 changes: 6 additions & 6 deletions packages/sdk-metrics/src/Instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
context as contextApi,
diag,
Context,
MetricAttributes,
Attributes,
ValueType,
UpDownCounter,
Counter,
Expand Down Expand Up @@ -46,7 +46,7 @@ export class SyncInstrument {

protected _record(
value: number,
attributes: MetricAttributes = {},
attributes: Attributes = {},
context: Context = contextApi.active()
) {
if (typeof value !== 'number') {
Expand Down Expand Up @@ -87,7 +87,7 @@ export class UpDownCounterInstrument
/**
* Increment value of counter by the input. Inputs may be negative.
*/
add(value: number, attributes?: MetricAttributes, ctx?: Context): void {
add(value: number, attributes?: Attributes, ctx?: Context): void {
this._record(value, attributes, ctx);
}
}
Expand All @@ -99,7 +99,7 @@ export class CounterInstrument extends SyncInstrument implements Counter {
/**
* Increment value of counter by the input. Inputs may not be negative.
*/
add(value: number, attributes?: MetricAttributes, ctx?: Context): void {
add(value: number, attributes?: Attributes, ctx?: Context): void {
if (value < 0) {
diag.warn(
`negative value provided to counter ${this._descriptor.name}: ${value}`
Expand All @@ -118,7 +118,7 @@ export class GaugeInstrument extends SyncInstrument implements Gauge {
/**
* Records a measurement.
*/
record(value: number, attributes?: MetricAttributes, ctx?: Context): void {
record(value: number, attributes?: Attributes, ctx?: Context): void {
this._record(value, attributes, ctx);
}
}
Expand All @@ -130,7 +130,7 @@ export class HistogramInstrument extends SyncInstrument implements Histogram {
/**
* Records a measurement. Value of the measurement must not be negative.
*/
record(value: number, attributes?: MetricAttributes, ctx?: Context): void {
record(value: number, attributes?: Attributes, ctx?: Context): void {
if (value < 0) {
diag.warn(
`negative value provided to histogram ${this._descriptor.name}: ${value}`
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-metrics/src/ObservableResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
diag,
ObservableResult,
MetricAttributes,
Attributes,
ValueType,
BatchObservableResult,
Observable,
Expand All @@ -42,7 +42,7 @@ export class ObservableResultImpl implements ObservableResult {
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(value: number, attributes: MetricAttributes = {}): void {
observe(value: number, attributes: Attributes = {}): void {
if (typeof value !== 'number') {
diag.warn(
`non-number value provided to metric ${this._instrumentName}: ${value}`
Expand Down Expand Up @@ -78,7 +78,7 @@ export class BatchObservableResultImpl implements BatchObservableResult {
observe(
metric: Observable,
value: number,
attributes: MetricAttributes = {}
attributes: Attributes = {}
): void {
if (!isObservableInstrument(metric)) {
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/aggregator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HrTime, MetricAttributes } from '@opentelemetry/api';
import { HrTime, Attributes } from '@opentelemetry/api';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData, MetricDescriptor } from '../export/MetricData';
import { Maybe } from '../utils';
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface Accumulation {
record(value: number): void;
}

export type AccumulationRecord<T> = [MetricAttributes, T];
export type AccumulationRecord<T> = [Attributes, T];

/**
* Base interface for aggregators. Aggregators are responsible for holding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';

/**
Expand All @@ -32,7 +32,7 @@ export class AlignedHistogramBucketExemplarReservoir extends FixedSizeExemplarRe
private _findBucketIndex(
value: number,
_timestamp: HrTime,
_attributes: MetricAttributes,
_attributes: Attributes,
_ctx: Context
) {
for (let i = 0; i < this._boundaries.length; i++) {
Expand All @@ -46,7 +46,7 @@ export class AlignedHistogramBucketExemplarReservoir extends FixedSizeExemplarRe
offer(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): void {
const index = this._findBucketIndex(value, timestamp, attributes, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';

export class AlwaysSampleExemplarFilter implements ExemplarFilter {
shouldSample(
_value: number,
_timestamp: HrTime,
_attributes: MetricAttributes,
_attributes: Attributes,
_ctx: Context
): boolean {
return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/exemplar/Exemplar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HrTime, MetricAttributes } from '@opentelemetry/api';
import { HrTime, Attributes } from '@opentelemetry/api';

/**
* A representation of an exemplar, which is a sample input measurement.
Expand All @@ -26,7 +26,7 @@ export type Exemplar = {
// The set of key/value pairs that were filtered out by the aggregator, but
// recorded alongside the original measurement. Only key/value pairs that were
// filtered out by the aggregator should be included
filteredAttributes: MetricAttributes;
filteredAttributes: Attributes;

// The value of the measurement that was recorded.
value: number;
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-metrics/src/exemplar/ExemplarFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';

/**
* This interface represents a ExemplarFilter. Exemplar filters are
Expand All @@ -27,13 +27,13 @@ export interface ExemplarFilter {
*
* @param value The value of the measurement
* @param timestamp A timestamp that best represents when the measurement was taken
* @param attributes The complete set of MetricAttributes of the measurement
* @param attributes The complete set of Attributes of the measurement
* @param ctx The Context of the measurement
*/
shouldSample(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): boolean;
}
16 changes: 8 additions & 8 deletions packages/sdk-metrics/src/exemplar/ExemplarReservoir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
HrTime,
isSpanContextValid,
trace,
MetricAttributes,
Attributes,
} from '@opentelemetry/api';
import { Exemplar } from './Exemplar';

Expand All @@ -31,7 +31,7 @@ export interface ExemplarReservoir {
offer(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): void;
/**
Expand All @@ -43,12 +43,12 @@ export interface ExemplarReservoir {
* @returns a list of {@link Exemplar}s. Returned exemplars contain the attributes that were filtered out by the
* aggregator, but recorded alongside the original measurement.
*/
collect(pointAttributes: MetricAttributes): Exemplar[];
collect(pointAttributes: Attributes): Exemplar[];
}

class ExemplarBucket {
private value: number = 0;
private attributes: MetricAttributes = {};
private attributes: Attributes = {};
private timestamp: HrTime = [0, 0];
private spanId?: string;
private traceId?: string;
Expand All @@ -57,7 +57,7 @@ class ExemplarBucket {
offer(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
) {
this.value = value;
Expand All @@ -71,7 +71,7 @@ class ExemplarBucket {
this._offered = true;
}

collect(pointAttributes: MetricAttributes): Exemplar | null {
collect(pointAttributes: Attributes): Exemplar | null {
if (!this._offered) return null;
const currentAttributes = this.attributes;
// filter attributes
Expand Down Expand Up @@ -114,7 +114,7 @@ export abstract class FixedSizeExemplarReservoirBase
abstract offer(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): void;

Expand All @@ -127,7 +127,7 @@ export abstract class FixedSizeExemplarReservoirBase
*/
protected reset(): void {}

collect(pointAttributes: MetricAttributes): Exemplar[] {
collect(pointAttributes: Attributes): Exemplar[] {
const exemplars: Exemplar[] = [];
this._reservoirStorage.forEach(storageItem => {
const res = storageItem.collect(pointAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';

export class NeverSampleExemplarFilter implements ExemplarFilter {
shouldSample(
_value: number,
_timestamp: HrTime,
_attributes: MetricAttributes,
_attributes: Attributes,
_ctx: Context
): boolean {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';

/**
Expand All @@ -37,7 +37,7 @@ export class SimpleFixedSizeExemplarReservoir extends FixedSizeExemplarReservoir
private _findBucketIndex(
_value: number,
_timestamp: HrTime,
_attributes: MetricAttributes,
_attributes: Attributes,
_ctx: Context
) {
if (this._numMeasurementsSeen < this._size)
Expand All @@ -49,7 +49,7 @@ export class SimpleFixedSizeExemplarReservoir extends FixedSizeExemplarReservoir
offer(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): void {
const index = this._findBucketIndex(value, timestamp, attributes, ctx);
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/exemplar/WithTraceExemplarFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {
isSpanContextValid,
trace,
TraceFlags,
MetricAttributes,
Attributes,
} from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';

export class WithTraceExemplarFilter implements ExemplarFilter {
shouldSample(
value: number,
timestamp: HrTime,
attributes: MetricAttributes,
attributes: Attributes,
ctx: Context
): boolean {
const spanContext = trace.getSpanContext(ctx);
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/export/MetricData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HrTime, MetricAttributes, ValueType } from '@opentelemetry/api';
import { HrTime, Attributes, ValueType } from '@opentelemetry/api';
import { InstrumentationScope } from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { InstrumentType } from '../InstrumentDescriptor';
Expand Down Expand Up @@ -159,7 +159,7 @@ export interface DataPoint<T> {
/**
* The attributes associated with this DataPoint.
*/
readonly attributes: MetricAttributes;
readonly attributes: Attributes;
/**
* The value for this DataPoint. The type of the value is indicated by the
* {@link DataPointType}.
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/state/DeltaMetricProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { Maybe } from '../utils';
import { Accumulation, Aggregator } from '../aggregator/types';
import { AttributeHashMap } from './HashMap';
Expand All @@ -36,7 +36,7 @@ export class DeltaMetricProcessor<T extends Maybe<Accumulation>> {

record(
value: number,
attributes: MetricAttributes,
attributes: Attributes,
_context: Context,
collectionTime: HrTime
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/state/HashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { MetricAttributes } from '@opentelemetry/api';
import { Attributes } from '@opentelemetry/api';
import { hashAttributes } from '../utils';

export interface Hash<ValueType, HashCodeType> {
Expand Down Expand Up @@ -84,7 +84,7 @@ export class HashMap<KeyType, ValueType, HashCodeType> {
}

export class AttributeHashMap<ValueType> extends HashMap<
MetricAttributes,
Attributes,
ValueType,
string
> {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-metrics/src/state/MultiWritableMetricStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Context, HrTime, MetricAttributes } from '@opentelemetry/api';
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { WritableMetricStorage } from './WritableMetricStorage';

/**
Expand All @@ -25,7 +25,7 @@ export class MultiMetricStorage implements WritableMetricStorage {

record(
value: number,
attributes: MetricAttributes,
attributes: Attributes,
context: Context,
recordTime: HrTime
) {
Expand Down
Loading

0 comments on commit 466140b

Please sign in to comment.