From fd2f57c56884c5950463086b45133e6336e8e0b0 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 11 Dec 2024 11:42:33 -0800 Subject: [PATCH] refactor(sdk-metrics) Swap workaround types for @otel/api types The internal `Gauge` and the unnamed `MetricAdvice` types were introduced in the 1.0 series when the metrics package depended on an older version of the api package that didn't come with those types, so the interfaces were essentially vendored into the package for internal use. Now with the 2.0 release on the horrizon, we can bump the required version of @otel/api and is now safe to unvendor these types in favor of the official ones. This is not expected to have any impact on consumers as the types are intended to be compatible for the positions they were used in. However, the minimum requirement for the `@opentelemetry/api` peer dependency has been raised to 1.9.0. Fixes #5223 Fixes #5224 --- CHANGELOG_NEXT.md | 2 ++ package-lock.json | 2 +- packages/sdk-metrics/package.json | 2 +- .../sdk-metrics/src/InstrumentDescriptor.ts | 20 +++++++++---------- packages/sdk-metrics/src/Instruments.ts | 2 +- packages/sdk-metrics/src/Meter.ts | 2 +- packages/sdk-metrics/src/types.ts | 12 ----------- 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 06717c2ebe2..60a15df6c29 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -4,6 +4,7 @@ ### :boom: Breaking Change +* 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 * feat(sdk-metrics)!: remove MeterProvider.addMetricReader() in favor of constructor option [#4419](https://github.com/open-telemetry/opentelemetry-js/pull/4419) @pichlermarc @@ -23,6 +24,7 @@ ### :house: (Internal) +* 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 * refactor(sdk-trace-base): rename `BasicTracerProvider.activeSpanProcessor` private property. [#5211](https://github.com/open-telemetry/opentelemetry-js/pull/5211) @david-luna diff --git a/package-lock.json b/package-lock.json index cc662cb348f..6fd4196ad09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28665,7 +28665,7 @@ "node": ">=18" }, "peerDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.10.0" + "@opentelemetry/api": ">=1.9.0 <1.10.0" } }, "packages/template": { diff --git a/packages/sdk-metrics/package.json b/packages/sdk-metrics/package.json index d6550a19926..5934858f808 100644 --- a/packages/sdk-metrics/package.json +++ b/packages/sdk-metrics/package.json @@ -79,7 +79,7 @@ "webpack-merge": "5.10.0" }, "peerDependencies": { - "@opentelemetry/api": ">=1.3.0 <1.10.0" + "@opentelemetry/api": ">=1.9.0 <1.10.0" }, "dependencies": { "@opentelemetry/core": "1.29.0", diff --git a/packages/sdk-metrics/src/InstrumentDescriptor.ts b/packages/sdk-metrics/src/InstrumentDescriptor.ts index ef09dda8bb5..39c9cffd927 100644 --- a/packages/sdk-metrics/src/InstrumentDescriptor.ts +++ b/packages/sdk-metrics/src/InstrumentDescriptor.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { MetricOptions, ValueType, diag } from '@opentelemetry/api'; +import { + MetricAdvice, + MetricOptions, + ValueType, + diag, +} from '@opentelemetry/api'; import { View } from './view/View'; import { equalsCaseInsensitive } from './utils'; @@ -44,18 +49,11 @@ export interface InstrumentDescriptor { readonly type: InstrumentType; readonly valueType: ValueType; /** - * @experimental + * See {@link MetricAdvice} * - * This is intentionally not using the API's type as it's only available from @opentelemetry/api 1.7.0 and up. - * In SDK 2.0 we'll be able to bump the minimum API version and remove this workaround. + * @experimental */ - readonly advice: { - /** - * Hint the explicit bucket boundaries for SDK if the metric has been - * aggregated with a HistogramAggregator. - */ - explicitBucketBoundaries?: number[]; - }; + readonly advice: MetricAdvice; } export function createInstrumentDescriptor( diff --git a/packages/sdk-metrics/src/Instruments.ts b/packages/sdk-metrics/src/Instruments.ts index 7e27a56454c..6d60792effe 100644 --- a/packages/sdk-metrics/src/Instruments.ts +++ b/packages/sdk-metrics/src/Instruments.ts @@ -22,6 +22,7 @@ import { ValueType, UpDownCounter, Counter, + Gauge, Histogram, Observable, ObservableCallback, @@ -36,7 +37,6 @@ import { AsyncWritableMetricStorage, WritableMetricStorage, } from './state/WritableMetricStorage'; -import { Gauge } from './types'; export class SyncInstrument { constructor( diff --git a/packages/sdk-metrics/src/Meter.ts b/packages/sdk-metrics/src/Meter.ts index cf0e25e56c1..b4edee68682 100644 --- a/packages/sdk-metrics/src/Meter.ts +++ b/packages/sdk-metrics/src/Meter.ts @@ -17,6 +17,7 @@ import { Meter as IMeter, MetricOptions, + Gauge, Histogram, Counter, UpDownCounter, @@ -40,7 +41,6 @@ import { UpDownCounterInstrument, } from './Instruments'; import { MeterSharedState } from './state/MeterSharedState'; -import { Gauge } from './types'; /** * This class implements the {@link IMeter} interface. diff --git a/packages/sdk-metrics/src/types.ts b/packages/sdk-metrics/src/types.ts index 2ad1cefcfd6..89af1eea333 100644 --- a/packages/sdk-metrics/src/types.ts +++ b/packages/sdk-metrics/src/types.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Context, Attributes } from '@opentelemetry/api'; export type CommonReaderOptions = { timeoutMillis?: number; @@ -24,14 +23,3 @@ export type CollectionOptions = CommonReaderOptions; export type ShutdownOptions = CommonReaderOptions; export type ForceFlushOptions = CommonReaderOptions; - -/** - * This is intentionally not using the API's type as it's only available from @opentelemetry/api 1.9.0 and up. - * In SDK 2.0 we'll be able to bump the minimum API version and remove this workaround. - */ -export interface Gauge { - /** - * Records a measurement. Value of the measurement must not be negative. - */ - record(value: number, attributes?: AttributesTypes, context?: Context): void; -}