Skip to content

Commit

Permalink
feat(sdk-metrics)!: drop deprecated InstrumentDescriptor export
Browse files Browse the repository at this point in the history
Note that this public `InstrumentDescriptor` has always been just
an alias of `MetricDescriptor`, and does not actually point to the
internal type with the same name.

Separately:

* Refactor the internal `InstrumentDescriptor` type to extend from
  the public `MetricDescriptor`, adding only the `advice` field

* Move the `InstrumentType` enum into `./src/export/MetricData.ts`
  as it is a public export, plus to avoid a circular dependency
  after the refactor
  • Loading branch information
chancancode committed Dec 18, 2024
1 parent 107637e commit befe9b5
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :boom: Breaking Change

* feat(sdk-metrics)!: drop deprecated `InstrumentDescriptor` type; use `MetricDescriptor` instead [#5277](https://github.com/open-telemetry/opentelemetry-js/pull/5266)
* feat(sdk-metrics)!: bump minimum version of `@opentelemetry/api` peer dependency to 1.9.0 [#5254](https://github.com/open-telemetry/opentelemetry-js/pull/5254) @chancancode
* chore(shim-opentracing): replace deprecated SpanAttributes [#4430](https://github.com/open-telemetry/opentelemetry-js/pull/4430) @JamieDanielson
* chore(otel-core): replace deprecated SpanAttributes [#4408](https://github.com/open-telemetry/opentelemetry-js/pull/4408) @JamieDanielson
Expand All @@ -33,6 +34,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :house: (Internal)

* refactor(sdk-metrics): the internal `InstrumentDescriptor` type now extends `MetricDescriptor`; moved public `InstrumentType` type enum into `./src/export/MetricData.ts` [#5277](https://github.com/open-telemetry/opentelemetry-js/pull/5266)
* refactor(sdk-metrics): remove `Gauge` and `MetricAdvice` workaround types in favor of the upstream `@opentelemetry/api` types [#5254](https://github.com/open-telemetry/opentelemetry-js/pull/5254) @chancancode
* chore: remove checks for unsupported node versions [#4341](https://github.com/open-telemetry/opentelemetry-js/pull/4341) @dyladan
* refactor(sdk-trace-base): remove `BasicTracerProvider._registeredSpanProcessors` private property. [#5134](https://github.com/open-telemetry/opentelemetry-js/pull/5134) @david-luna
Expand Down
21 changes: 2 additions & 19 deletions packages/sdk-metrics/src/InstrumentDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,15 @@ import {
} from '@opentelemetry/api';
import { View } from './view/View';
import { equalsCaseInsensitive } from './utils';

/**
* Supported types of metric instruments.
*/
export enum InstrumentType {
COUNTER = 'COUNTER',
GAUGE = 'GAUGE',
HISTOGRAM = 'HISTOGRAM',
UP_DOWN_COUNTER = 'UP_DOWN_COUNTER',
OBSERVABLE_COUNTER = 'OBSERVABLE_COUNTER',
OBSERVABLE_GAUGE = 'OBSERVABLE_GAUGE',
OBSERVABLE_UP_DOWN_COUNTER = 'OBSERVABLE_UP_DOWN_COUNTER',
}
import { InstrumentType, MetricDescriptor } from './export/MetricData';

/**
* An internal interface describing the instrument.
*
* This is intentionally distinguished from the public MetricDescriptor (a.k.a. InstrumentDescriptor)
* which may not contains internal fields like metric advice.
*/
export interface InstrumentDescriptor {
readonly name: string;
readonly description: string;
readonly unit: string;
readonly type: InstrumentType;
readonly valueType: ValueType;
export interface InstrumentDescriptor extends MetricDescriptor {
/**
* See {@link MetricAdvice}
*
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import {
BatchObservableCallback,
Observable,
} from '@opentelemetry/api';
import {
createInstrumentDescriptor,
InstrumentType,
} from './InstrumentDescriptor';
import { createInstrumentDescriptor } from './InstrumentDescriptor';
import {
CounterInstrument,
GaugeInstrument,
Expand All @@ -41,6 +38,7 @@ import {
UpDownCounterInstrument,
} from './Instruments';
import { MeterSharedState } from './state/MeterSharedState';
import { InstrumentType } from './export/MetricData';

/**
* This class implements the {@link IMeter} interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {
import {
DataPointType,
ExponentialHistogramMetricData,
InstrumentType,
MetricDescriptor,
} from '../export/MetricData';
import { diag, HrTime } from '@opentelemetry/api';
import { InstrumentType } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { Buckets } from './exponential-histogram/Buckets';
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/aggregator/Histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
import {
DataPointType,
HistogramMetricData,
InstrumentType,
MetricDescriptor,
} from '../export/MetricData';
import { HrTime } from '@opentelemetry/api';
import { InstrumentType } from '../InstrumentDescriptor';
import { binarySearchUB, Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/export/AggregationSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { InstrumentType } from '../InstrumentDescriptor';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from './MetricData';
import { AggregationOption, AggregationType } from '../view/AggregationOption';

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-metrics/src/export/CardinalitySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { InstrumentType } from '../InstrumentDescriptor';
import { InstrumentType } from './MetricData';

/**
* Cardinality Limit selector based on metric instrument types.
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk-metrics/src/export/ConsoleMetricExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/
import { ExportResult, ExportResultCode } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { ResourceMetrics, InstrumentType } from './MetricData';
import { PushMetricExporter } from './MetricExporter';
import {
AggregationTemporalitySelector,
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk-metrics/src/export/InMemoryMetricExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import { ExportResultCode } from '@opentelemetry/core';
import { ExportResult } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { InstrumentType, ResourceMetrics } from './MetricData';
import { PushMetricExporter } from './MetricExporter';

/**
Expand Down
14 changes: 13 additions & 1 deletion packages/sdk-metrics/src/export/MetricData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@
import { HrTime, Attributes, ValueType } from '@opentelemetry/api';
import { InstrumentationScope } from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { InstrumentType } from '../InstrumentDescriptor';
import { AggregationTemporality } from './AggregationTemporality';
import { Histogram, ExponentialHistogram } from '../aggregator/types';

/**
* Supported types of metric instruments.
*/
export enum InstrumentType {
COUNTER = 'COUNTER',
GAUGE = 'GAUGE',
HISTOGRAM = 'HISTOGRAM',
UP_DOWN_COUNTER = 'UP_DOWN_COUNTER',
OBSERVABLE_COUNTER = 'OBSERVABLE_COUNTER',
OBSERVABLE_GAUGE = 'OBSERVABLE_GAUGE',
OBSERVABLE_UP_DOWN_COUNTER = 'OBSERVABLE_UP_DOWN_COUNTER',
}

export interface MetricDescriptor {
readonly name: string;
readonly description: string;
Expand Down
5 changes: 2 additions & 3 deletions packages/sdk-metrics/src/export/MetricExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*/

import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { ExportResult } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType, ResourceMetrics } from './MetricData';
import { AggregationOption } from '../view/AggregationOption';

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk-metrics/src/export/MetricReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import * as api from '@opentelemetry/api';
import { AggregationTemporality } from './AggregationTemporality';
import { MetricProducer } from './MetricProducer';
import { CollectionResult } from './MetricData';
import { CollectionResult, InstrumentType } from './MetricData';
import { FlatMap, callWithTimeout } from '../utils';
import { InstrumentType } from '../InstrumentDescriptor';
import {
CollectionOptions,
ForceFlushOptions,
Expand Down
9 changes: 1 addition & 8 deletions packages/sdk-metrics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import { MetricDescriptor } from './export/MetricData';

export {
Sum,
LastValue,
Expand All @@ -36,6 +34,7 @@ export {
SumMetricData,
GaugeMetricData,
HistogramMetricData,
InstrumentType,
ExponentialHistogramMetricData,
ResourceMetrics,
ScopeMetrics,
Expand All @@ -59,12 +58,6 @@ export { ConsoleMetricExporter } from './export/ConsoleMetricExporter';

export { MetricCollectOptions, MetricProducer } from './export/MetricProducer';

export { InstrumentType } from './InstrumentDescriptor';
/**
* @deprecated Use {@link MetricDescriptor} instead.
*/
export type InstrumentDescriptor = MetricDescriptor;

export { MeterProvider, MeterProviderOptions } from './MeterProvider';

export { AggregationOption, AggregationType } from './view/AggregationOption';
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/state/MeterProviderSharedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import { InstrumentationScope } from '@opentelemetry/core';
import { IResource } from '@opentelemetry/resources';
import { InstrumentType } from '..';
import { instrumentationScopeId } from '../utils';
import { ViewRegistry } from '../view/ViewRegistry';
import { MeterSharedState } from './MeterSharedState';
import { MetricCollector, MetricCollectorHandle } from './MetricCollector';
import { toAggregation } from '../view/AggregationOption';
import { Aggregation } from '../view/Aggregation';
import { InstrumentType } from '../export/MetricData';

/**
* An internal record for shared meter provider states.
Expand Down
7 changes: 5 additions & 2 deletions packages/sdk-metrics/src/state/MetricCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

import { millisToHrTime } from '@opentelemetry/core';
import { AggregationTemporalitySelector } from '../export/AggregationSelector';
import { CollectionResult, ScopeMetrics } from '../export/MetricData';
import {
CollectionResult,
InstrumentType,
ScopeMetrics,
} from '../export/MetricData';
import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';
import { MetricReader } from '../export/MetricReader';
import { InstrumentType } from '../InstrumentDescriptor';
import { ForceFlushOptions, ShutdownOptions } from '../types';
import { MeterProviderSharedState } from './MeterProviderSharedState';

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-metrics/src/view/Aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
ExponentialHistogramAggregator,
} from '../aggregator';
import { Accumulation } from '../aggregator/types';
import { InstrumentDescriptor, InstrumentType } from '../InstrumentDescriptor';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
import { InstrumentType } from '../export/MetricData';

/**
* Configures how measurements are combined into metrics for views.
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/view/InstrumentSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { InstrumentType } from '../InstrumentDescriptor';
import { ExactPredicate, PatternPredicate, Predicate } from './Predicate';
import { InstrumentType } from '../export/MetricData';

export interface InstrumentSelectorCriteria {
name?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/src/view/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
import { InstrumentSelector } from './InstrumentSelector';
import { MeterSelector } from './MeterSelector';
import { Aggregation } from './Aggregation';
import { InstrumentType } from '../InstrumentDescriptor';
import {
AggregationOption,
AggregationType,
toAggregation,
} from './AggregationOption';
import { InstrumentType } from '../export/MetricData';

export type ViewOptions = {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-metrics/test/InstrumentDescriptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import * as assert from 'assert';
import {
createInstrumentDescriptor,
InstrumentDescriptor,
InstrumentType,
isValidName,
isDescriptorCompatibleWith,
} from '../src/InstrumentDescriptor';
import { InstrumentType } from '../src';
import { invalidNames, validNames } from './util';
import { ValueType } from '@opentelemetry/api';

Expand Down
4 changes: 1 addition & 3 deletions packages/sdk-metrics/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import {
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import { InstrumentDescriptor } from '../src/InstrumentDescriptor';
import {
InstrumentDescriptor,
InstrumentType,
} from '../src/InstrumentDescriptor';
import {
MetricData,
DataPoint,
DataPointType,
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk-metrics/test/view/Aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
*/

import * as assert from 'assert';
import { InstrumentType } from '../../src';
import {
Aggregator,
DropAggregator,
HistogramAggregator,
LastValueAggregator,
SumAggregator,
} from '../../src/aggregator';
import {
InstrumentDescriptor,
InstrumentType,
} from '../../src/InstrumentDescriptor';
import { InstrumentDescriptor } from '../../src/InstrumentDescriptor';
import {
DefaultAggregation,
ExplicitBucketHistogramAggregation,
Expand Down

0 comments on commit befe9b5

Please sign in to comment.