From befe9b5114b5cfcc9650b54bbcd808201274c4b7 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 13 Dec 2024 12:44:03 -0800 Subject: [PATCH] feat(sdk-metrics)!: drop deprecated `InstrumentDescriptor` export 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 --- CHANGELOG.md | 2 ++ .../sdk-metrics/src/InstrumentDescriptor.ts | 21 ++----------------- packages/sdk-metrics/src/Meter.ts | 6 ++---- .../src/aggregator/ExponentialHistogram.ts | 2 +- .../sdk-metrics/src/aggregator/Histogram.ts | 2 +- .../src/export/AggregationSelector.ts | 2 +- .../src/export/CardinalitySelector.ts | 3 ++- .../src/export/ConsoleMetricExporter.ts | 3 +-- .../src/export/InMemoryMetricExporter.ts | 3 +-- packages/sdk-metrics/src/export/MetricData.ts | 14 ++++++++++++- .../sdk-metrics/src/export/MetricExporter.ts | 5 ++--- .../sdk-metrics/src/export/MetricReader.ts | 3 +-- packages/sdk-metrics/src/index.ts | 9 +------- .../src/state/MeterProviderSharedState.ts | 2 +- .../sdk-metrics/src/state/MetricCollector.ts | 7 +++++-- packages/sdk-metrics/src/view/Aggregation.ts | 3 ++- .../src/view/InstrumentSelector.ts | 2 +- packages/sdk-metrics/src/view/View.ts | 2 +- .../test/InstrumentDescriptor.test.ts | 2 +- packages/sdk-metrics/test/util.ts | 4 +--- .../sdk-metrics/test/view/Aggregation.test.ts | 6 ++---- 21 files changed, 44 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 305495ddd31..5d2af8ed127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/packages/sdk-metrics/src/InstrumentDescriptor.ts b/packages/sdk-metrics/src/InstrumentDescriptor.ts index 39c9cffd927..e6d68f7e8fa 100644 --- a/packages/sdk-metrics/src/InstrumentDescriptor.ts +++ b/packages/sdk-metrics/src/InstrumentDescriptor.ts @@ -22,19 +22,7 @@ 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. @@ -42,12 +30,7 @@ export enum InstrumentType { * 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} * diff --git a/packages/sdk-metrics/src/Meter.ts b/packages/sdk-metrics/src/Meter.ts index b4edee68682..1d6548427d4 100644 --- a/packages/sdk-metrics/src/Meter.ts +++ b/packages/sdk-metrics/src/Meter.ts @@ -27,10 +27,7 @@ import { BatchObservableCallback, Observable, } from '@opentelemetry/api'; -import { - createInstrumentDescriptor, - InstrumentType, -} from './InstrumentDescriptor'; +import { createInstrumentDescriptor } from './InstrumentDescriptor'; import { CounterInstrument, GaugeInstrument, @@ -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. diff --git a/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts b/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts index 9eb296fb27f..5218911176d 100644 --- a/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts +++ b/packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts @@ -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'; diff --git a/packages/sdk-metrics/src/aggregator/Histogram.ts b/packages/sdk-metrics/src/aggregator/Histogram.ts index 85f46098e99..fa088ae8881 100644 --- a/packages/sdk-metrics/src/aggregator/Histogram.ts +++ b/packages/sdk-metrics/src/aggregator/Histogram.ts @@ -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'; diff --git a/packages/sdk-metrics/src/export/AggregationSelector.ts b/packages/sdk-metrics/src/export/AggregationSelector.ts index 96d10daca4a..020fd6160f6 100644 --- a/packages/sdk-metrics/src/export/AggregationSelector.ts +++ b/packages/sdk-metrics/src/export/AggregationSelector.ts @@ -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'; /** diff --git a/packages/sdk-metrics/src/export/CardinalitySelector.ts b/packages/sdk-metrics/src/export/CardinalitySelector.ts index a274898b9a2..3be04c1e636 100644 --- a/packages/sdk-metrics/src/export/CardinalitySelector.ts +++ b/packages/sdk-metrics/src/export/CardinalitySelector.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { InstrumentType } from '../InstrumentDescriptor'; +import { InstrumentType } from './MetricData'; + /** * Cardinality Limit selector based on metric instrument types. */ diff --git a/packages/sdk-metrics/src/export/ConsoleMetricExporter.ts b/packages/sdk-metrics/src/export/ConsoleMetricExporter.ts index 56254836b30..7168849bf32 100644 --- a/packages/sdk-metrics/src/export/ConsoleMetricExporter.ts +++ b/packages/sdk-metrics/src/export/ConsoleMetricExporter.ts @@ -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, diff --git a/packages/sdk-metrics/src/export/InMemoryMetricExporter.ts b/packages/sdk-metrics/src/export/InMemoryMetricExporter.ts index 2a80973bb95..60e9cf2ecf3 100644 --- a/packages/sdk-metrics/src/export/InMemoryMetricExporter.ts +++ b/packages/sdk-metrics/src/export/InMemoryMetricExporter.ts @@ -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'; /** diff --git a/packages/sdk-metrics/src/export/MetricData.ts b/packages/sdk-metrics/src/export/MetricData.ts index 4f39db05059..f5ebe1f864e 100644 --- a/packages/sdk-metrics/src/export/MetricData.ts +++ b/packages/sdk-metrics/src/export/MetricData.ts @@ -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; diff --git a/packages/sdk-metrics/src/export/MetricExporter.ts b/packages/sdk-metrics/src/export/MetricExporter.ts index 38ca30ce67b..fab578d32ec 100644 --- a/packages/sdk-metrics/src/export/MetricExporter.ts +++ b/packages/sdk-metrics/src/export/MetricExporter.ts @@ -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'; /** diff --git a/packages/sdk-metrics/src/export/MetricReader.ts b/packages/sdk-metrics/src/export/MetricReader.ts index abf4c8bd03f..c70b4d17eab 100644 --- a/packages/sdk-metrics/src/export/MetricReader.ts +++ b/packages/sdk-metrics/src/export/MetricReader.ts @@ -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, diff --git a/packages/sdk-metrics/src/index.ts b/packages/sdk-metrics/src/index.ts index 4f359214bc8..d18832c64bf 100644 --- a/packages/sdk-metrics/src/index.ts +++ b/packages/sdk-metrics/src/index.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import { MetricDescriptor } from './export/MetricData'; - export { Sum, LastValue, @@ -36,6 +34,7 @@ export { SumMetricData, GaugeMetricData, HistogramMetricData, + InstrumentType, ExponentialHistogramMetricData, ResourceMetrics, ScopeMetrics, @@ -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'; diff --git a/packages/sdk-metrics/src/state/MeterProviderSharedState.ts b/packages/sdk-metrics/src/state/MeterProviderSharedState.ts index 2e8bc57796d..116bb121626 100644 --- a/packages/sdk-metrics/src/state/MeterProviderSharedState.ts +++ b/packages/sdk-metrics/src/state/MeterProviderSharedState.ts @@ -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. diff --git a/packages/sdk-metrics/src/state/MetricCollector.ts b/packages/sdk-metrics/src/state/MetricCollector.ts index 3b52a3e4d56..1a3fd23360f 100644 --- a/packages/sdk-metrics/src/state/MetricCollector.ts +++ b/packages/sdk-metrics/src/state/MetricCollector.ts @@ -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'; diff --git a/packages/sdk-metrics/src/view/Aggregation.ts b/packages/sdk-metrics/src/view/Aggregation.ts index f3894489b17..90e0dced784 100644 --- a/packages/sdk-metrics/src/view/Aggregation.ts +++ b/packages/sdk-metrics/src/view/Aggregation.ts @@ -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. diff --git a/packages/sdk-metrics/src/view/InstrumentSelector.ts b/packages/sdk-metrics/src/view/InstrumentSelector.ts index 9b8006267f7..1a1fd52967d 100644 --- a/packages/sdk-metrics/src/view/InstrumentSelector.ts +++ b/packages/sdk-metrics/src/view/InstrumentSelector.ts @@ -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; diff --git a/packages/sdk-metrics/src/view/View.ts b/packages/sdk-metrics/src/view/View.ts index 822279b4c94..8844a842078 100644 --- a/packages/sdk-metrics/src/view/View.ts +++ b/packages/sdk-metrics/src/view/View.ts @@ -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 = { /** diff --git a/packages/sdk-metrics/test/InstrumentDescriptor.test.ts b/packages/sdk-metrics/test/InstrumentDescriptor.test.ts index b33a3e8f3a6..6ad9039d3e7 100644 --- a/packages/sdk-metrics/test/InstrumentDescriptor.test.ts +++ b/packages/sdk-metrics/test/InstrumentDescriptor.test.ts @@ -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'; diff --git a/packages/sdk-metrics/test/util.ts b/packages/sdk-metrics/test/util.ts index 52d89e51692..5786ba424d1 100644 --- a/packages/sdk-metrics/test/util.ts +++ b/packages/sdk-metrics/test/util.ts @@ -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, diff --git a/packages/sdk-metrics/test/view/Aggregation.test.ts b/packages/sdk-metrics/test/view/Aggregation.test.ts index a2b25b77f81..7fbb3e70661 100644 --- a/packages/sdk-metrics/test/view/Aggregation.test.ts +++ b/packages/sdk-metrics/test/view/Aggregation.test.ts @@ -15,6 +15,7 @@ */ import * as assert from 'assert'; +import { InstrumentType } from '../../src'; import { Aggregator, DropAggregator, @@ -22,10 +23,7 @@ import { LastValueAggregator, SumAggregator, } from '../../src/aggregator'; -import { - InstrumentDescriptor, - InstrumentType, -} from '../../src/InstrumentDescriptor'; +import { InstrumentDescriptor } from '../../src/InstrumentDescriptor'; import { DefaultAggregation, ExplicitBucketHistogramAggregation,