diff --git a/api/README.md b/api/README.md index 0f91bb0bca1..c5f02e37f6f 100644 --- a/api/README.md +++ b/api/README.md @@ -10,7 +10,7 @@ This package provides everything needed to interact with the OpenTelemetry API, ## Quick Start -To get started you need to install the SDK and plugins, create a TracerProvider and/or MeterProvider, and register it with the API. +To get started you need to install the SDK and plugins, create a TracerProvider, and register it with the API. ### Install Dependencies @@ -23,11 +23,6 @@ $ npm install \ @opentelemetry/tracing \ @opentelemetry/exporter-jaeger \ # add exporters as needed @opentelemetry/plugin-http # add plugins as needed - -$ # Install metrics dependencies -$ npm install \ - @opentelemetry/metrics \ - @opentelemetry/exporter-prometheus # add exporters as needed ``` > Note: this example is for node.js. See [examples/tracer-web](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/tracer-web) for a browser example. @@ -74,27 +69,6 @@ tracerProvider.addSpanProcessor( tracerProvider.register(); ``` -#### Metrics - -```javascript -const api = require("@opentelemetry/api"); -const { MeterProvider } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); - -const meterProvider = new MeterProvider({ - // The Prometheus exporter runs an HTTP server which - // the Prometheus backend scrapes to collect metrics. - exporter: new PrometheusExporter({ startServer: true }), - interval: 1000, -}); - -/** - * Registering the provider with the API allows it to be discovered - * and used by instrumentation libraries. - */ -api.metrics.setGlobalMeterProvider(meterProvider); -``` - ## Version Compatibility Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same `node_modules` structure, the OpenTelemetry API takes advantage of a variable on the `global` object to store the global API. When an API method in the API package is called, it checks if this `global` API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API. @@ -122,7 +96,6 @@ tracerProvider.register({ If you are writing an instrumentation library, or prefer to call the API methods directly rather than using the `register` method on the Tracer/Meter Provider, OpenTelemetry provides direct access to the underlying API methods through the `@opentelemetry/api` package. API entry points are defined as global singleton objects `trace`, `metrics`, `propagation`, and `context` which contain methods used to initialize SDK implementations and acquire resources from the API. - [Trace API Documentation][trace-api-docs] -- [Metrics API Documentation][metrics-api-docs] - [Propagation API Documentation][propagation-api-docs] - [Context API Documentation][context-api-docs] @@ -136,13 +109,6 @@ api.trace.getTracerProvider(); /* returns a tracer from the registered global tracer provider (no-op if a working provider has not been initialized) */ api.trace.getTracer(name, version); -/* Initialize MeterProvider */ -api.metrics.setGlobalMeterProvider(meterProvider); -/* returns meterProvider (no-op if a working provider has not been initialized) */ -api.metrics.getMeterProvider(); -/* returns a meter from the registered global meter provider (no-op if a working provider has not been initialized) */ -api.metrics.getMeter(name, version); - /* Initialize Propagator */ api.propagation.setGlobalPropagator(httpTraceContextPropagator); diff --git a/api/package.json b/api/package.json index 66159e9049b..eb0fc0db377 100644 --- a/api/package.json +++ b/api/package.json @@ -30,7 +30,6 @@ "browser", "tracing", "profiling", - "metrics", "stats", "monitoring" ], diff --git a/api/src/api/global-utils.ts b/api/src/api/global-utils.ts index 5d6ad7de3e0..0ab9d663e5d 100644 --- a/api/src/api/global-utils.ts +++ b/api/src/api/global-utils.ts @@ -16,16 +16,13 @@ import { ContextManager } from '@opentelemetry/context-base'; import { TextMapPropagator } from '../context/propagation/TextMapPropagator'; -import { MeterProvider } from '../metrics/MeterProvider'; import { TracerProvider } from '../trace/tracer_provider'; import { _globalThis } from '../platform'; export const GLOBAL_CONTEXT_MANAGER_API_KEY = Symbol.for( 'io.opentelemetry.js.api.context' ); -export const GLOBAL_METRICS_API_KEY = Symbol.for( - 'io.opentelemetry.js.api.metrics' -); + export const GLOBAL_PROPAGATION_API_KEY = Symbol.for( 'io.opentelemetry.js.api.propagation' ); @@ -34,7 +31,6 @@ export const GLOBAL_TRACE_API_KEY = Symbol.for('io.opentelemetry.js.api.trace'); type Get = (version: number) => T; type OtelGlobal = Partial<{ [GLOBAL_CONTEXT_MANAGER_API_KEY]: Get; - [GLOBAL_METRICS_API_KEY]: Get; [GLOBAL_PROPAGATION_API_KEY]: Get; [GLOBAL_TRACE_API_KEY]: Get; }>; diff --git a/api/src/api/metrics.ts b/api/src/api/metrics.ts deleted file mode 100644 index f06b09fa367..00000000000 --- a/api/src/api/metrics.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Meter } from '../metrics/Meter'; -import { MeterProvider } from '../metrics/MeterProvider'; -import { NOOP_METER_PROVIDER } from '../metrics/NoopMeterProvider'; -import { - API_BACKWARDS_COMPATIBILITY_VERSION, - GLOBAL_METRICS_API_KEY, - makeGetter, - _global, -} from './global-utils'; - -/** - * Singleton object which represents the entry point to the OpenTelemetry Metrics API - */ -export class MetricsAPI { - private static _instance?: MetricsAPI; - - /** Empty private constructor prevents end users from constructing a new instance of the API */ - private constructor() {} - - /** Get the singleton instance of the Metrics API */ - public static getInstance(): MetricsAPI { - if (!this._instance) { - this._instance = new MetricsAPI(); - } - - return this._instance; - } - - /** - * Set the current global meter. Returns the initialized global meter provider. - */ - public setGlobalMeterProvider(provider: MeterProvider): MeterProvider { - if (_global[GLOBAL_METRICS_API_KEY]) { - // global meter provider has already been set - return this.getMeterProvider(); - } - - _global[GLOBAL_METRICS_API_KEY] = makeGetter( - API_BACKWARDS_COMPATIBILITY_VERSION, - provider, - NOOP_METER_PROVIDER - ); - - return provider; - } - - /** - * Returns the global meter provider. - */ - public getMeterProvider(): MeterProvider { - return ( - _global[GLOBAL_METRICS_API_KEY]?.(API_BACKWARDS_COMPATIBILITY_VERSION) ?? - NOOP_METER_PROVIDER - ); - } - - /** - * Returns a meter from the global meter provider. - */ - public getMeter(name: string, version?: string): Meter { - return this.getMeterProvider().getMeter(name, version); - } - - /** Remove the global meter provider */ - public disable() { - delete _global[GLOBAL_METRICS_API_KEY]; - } -} diff --git a/api/src/index.ts b/api/src/index.ts index c19be4333a8..7c5bbd76f56 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -22,15 +22,6 @@ export * from './context/propagation/TextMapPropagator'; export * from './context/propagation/NoopTextMapPropagator'; export * from './baggage/Baggage'; export * from './baggage/EntryValue'; -export * from './metrics/BatchObserverResult'; -export * from './metrics/BoundInstrument'; -export * from './metrics/Meter'; -export * from './metrics/MeterProvider'; -export * from './metrics/Metric'; -export * from './metrics/NoopMeter'; -export * from './metrics/NoopMeterProvider'; -export * from './metrics/Observation'; -export * from './metrics/ObserverResult'; export * from './trace/attributes'; export * from './trace/Event'; export * from './trace/link_context'; @@ -78,17 +69,12 @@ import { TraceAPI } from './api/trace'; /** Entrypoint for trace API */ export const trace = TraceAPI.getInstance(); -import { MetricsAPI } from './api/metrics'; -/** Entrypoint for metrics API */ -export const metrics = MetricsAPI.getInstance(); - import { PropagationAPI } from './api/propagation'; /** Entrypoint for propagation API */ export const propagation = PropagationAPI.getInstance(); export default { trace, - metrics, context, propagation, }; diff --git a/api/src/metrics/BatchObserverResult.ts b/api/src/metrics/BatchObserverResult.ts deleted file mode 100644 index bae99eb8664..00000000000 --- a/api/src/metrics/BatchObserverResult.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Labels } from './Metric'; -import { Observation } from './Observation'; - -/** - * Interface that is being used in callback function for Observer Metric - * for batch - */ -export interface BatchObserverResult { - /** - * Used to observe (update) observations for certain labels - * @param labels - * @param observations - */ - observe(labels: Labels, observations: Observation[]): void; -} diff --git a/api/src/metrics/BoundInstrument.ts b/api/src/metrics/BoundInstrument.ts deleted file mode 100644 index 0d5554771e6..00000000000 --- a/api/src/metrics/BoundInstrument.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** An Instrument for Counter Metric. */ -export interface BoundCounter { - /** - * Adds the given value to the current value. Values cannot be negative. - * @param value the value to add. - */ - add(value: number): void; -} - -/** ValueRecorder to report instantaneous measurement of a value. */ -export interface BoundValueRecorder { - /** - * Records the given value to this value recorder. - * @param value to record. - */ - record(value: number): void; -} - -/** An Instrument for Base Observer */ -export interface BoundBaseObserver { - update(value: number): void; -} diff --git a/api/src/metrics/Meter.ts b/api/src/metrics/Meter.ts deleted file mode 100644 index 27428f2554d..00000000000 --- a/api/src/metrics/Meter.ts +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { BatchObserverResult } from './BatchObserverResult'; -import { - MetricOptions, - Counter, - ValueRecorder, - ValueObserver, - BatchObserverOptions, - UpDownCounter, - SumObserver, - UpDownSumObserver, -} from './Metric'; -import { ObserverResult } from './ObserverResult'; - -/** - * An interface to allow the recording metrics. - * - * {@link Metric}s are used for recording pre-defined aggregation (`Counter`), - * or raw values (`ValueRecorder`) in which the aggregation and labels - * for the exported metric are deferred. - */ -export interface Meter { - /** - * Creates and returns a new `ValueRecorder`. - * @param name the name of the metric. - * @param [options] the metric options. - */ - createValueRecorder(name: string, options?: MetricOptions): ValueRecorder; - - /** - * Creates a new `Counter` metric. Generally, this kind of metric when the - * value is a quantity, the sum is of primary interest, and the event count - * and value distribution are not of primary interest. - * @param name the name of the metric. - * @param [options] the metric options. - */ - createCounter(name: string, options?: MetricOptions): Counter; - - /** - * Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous - * instrument and very similar to Counter except that Add(increment) - * supports negative increments. It is generally useful for capturing changes - * in an amount of resources used, or any quantity that rises and falls - * during a request. - * Example uses for UpDownCounter: - *
    - *
  1. count the number of active requests.
  2. - *
  3. count memory in use by instrumenting new and delete.
  4. - *
  5. count queue size by instrumenting enqueue and dequeue.
  6. - *
  7. count semaphore up and down operations.
  8. - *
- * - * @param name the name of the metric. - * @param [options] the metric options. - */ - createUpDownCounter(name: string, options?: MetricOptions): UpDownCounter; - - /** - * Creates a new `ValueObserver` metric. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the observer callback - */ - createValueObserver( - name: string, - options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): ValueObserver; - - /** - * Creates a new `SumObserver` metric. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the observer callback - */ - createSumObserver( - name: string, - options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): SumObserver; - - /** - * Creates a new `UpDownSumObserver` metric. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the observer callback - */ - createUpDownSumObserver( - name: string, - options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): UpDownSumObserver; - - /** - * Creates a new `BatchObserver`, can be used to update many metrics - * at the same time and when operations needs to be async - * @param callback the batch observer callback - * @param [options] the batch observer options. - */ - createBatchObserver( - callback: (batchObserverResult: BatchObserverResult) => void, - options?: BatchObserverOptions - ): void; -} diff --git a/api/src/metrics/MeterProvider.ts b/api/src/metrics/MeterProvider.ts deleted file mode 100644 index 981218ad596..00000000000 --- a/api/src/metrics/MeterProvider.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Meter } from './Meter'; - -/** - * A registry for creating named {@link Meter}s. - */ -export interface MeterProvider { - /** - * Returns a Meter, creating one if one with the given name and version is - * not already created. - * - * @param name The name of the meter or instrumentation library. - * @param version The version of the meter or instrumentation library. - * @returns Meter A Meter with the given name and version - */ - getMeter(name: string, version?: string): Meter; -} diff --git a/api/src/metrics/Metric.ts b/api/src/metrics/Metric.ts deleted file mode 100644 index 75e7a78d397..00000000000 --- a/api/src/metrics/Metric.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - BoundBaseObserver, - BoundCounter, - BoundValueRecorder, -} from './BoundInstrument'; -import { Logger } from '../common/Logger'; - -/** - * Options needed for metric creation - */ -export interface MetricOptions { - /** The name of the component that reports the Metric. */ - component?: string; - - /** - * The description of the Metric. - * @default '' - */ - description?: string; - - /** - * The unit of the Metric values. - * @default '1' - */ - unit?: string; - - /** The map of constant labels for the Metric. */ - constantLabels?: Map; - - /** - * Indicates the metric is a verbose metric that is disabled by default - * @default false - */ - disabled?: boolean; - - /** - * Indicates the type of the recorded value. - * @default {@link ValueType.DOUBLE} - */ - valueType?: ValueType; - - /** - * User provided logger. - */ - logger?: Logger; - - /** - * Boundaries optional for histogram - */ - boundaries?: number[]; -} - -export interface BatchObserverOptions { - /** - * Indicates how long the batch metric should wait to update before cancel - */ - maxTimeoutUpdateMS?: number; - - /** - * User provided logger. - */ - logger?: Logger; -} - -/** The Type of value. It describes how the data is reported. */ -export enum ValueType { - INT, - DOUBLE, -} - -/** - * Metric represents a base class for different types of metric - * pre aggregations. - */ -export interface Metric { - /** - * Clears all bound instruments from the Metric. - */ - clear(): void; -} - -/** - * UnboundMetric represents a base class for different types of metric - * pre aggregations without label value bound yet. - */ -export interface UnboundMetric extends Metric { - /** - * Returns a Instrument associated with specified Labels. - * It is recommended to keep a reference to the Instrument instead of always - * calling this method for every operations. - * @param labels key-values pairs that are associated with a specific metric - * that you want to record. - */ - bind(labels: Labels): T; - - /** - * Removes the Instrument from the metric, if it is present. - * @param labels key-values pairs that are associated with a specific metric. - */ - unbind(labels: Labels): void; -} - -/** - * Counter is the most common synchronous instrument. This instrument supports - * an `Add(increment)` function for reporting a sum, and is restricted to - * non-negative increments. The default aggregation is Sum, as for any additive - * instrument. - * - * Example uses for Counter: - *
    - *
  1. count the number of bytes received.
  2. - *
  3. count the number of requests completed.
  4. - *
  5. count the number of accounts created.
  6. - *
  7. count the number of checkpoints run.
  8. - *
  9. count the number of 5xx errors.
  10. - *
      - */ -export interface Counter extends UnboundMetric { - /** - * Adds the given value to the current value. Values cannot be negative. - */ - add(value: number, labels?: Labels): void; -} - -export interface UpDownCounter extends UnboundMetric { - /** - * Adds the given value to the current value. Values can be negative. - */ - add(value: number, labels?: Labels): void; -} - -export interface ValueRecorder extends UnboundMetric { - /** - * Records the given value to this value recorder. - */ - record(value: number, labels?: Labels): void; -} - -/** Base interface for the Observer metrics. */ -export interface BaseObserver extends UnboundMetric { - observation: ( - value: number - ) => { - value: number; - observer: BaseObserver; - }; -} - -/** Base interface for the ValueObserver metrics. */ -export type ValueObserver = BaseObserver; - -/** Base interface for the UpDownSumObserver metrics. */ -export type UpDownSumObserver = BaseObserver; - -/** Base interface for the SumObserver metrics. */ -export type SumObserver = BaseObserver; - -/** - * key-value pairs passed by the user. - */ -export type Labels = { [key: string]: string }; diff --git a/api/src/metrics/NoopMeter.ts b/api/src/metrics/NoopMeter.ts deleted file mode 100644 index 192bf19bec7..00000000000 --- a/api/src/metrics/NoopMeter.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { BatchObserverResult } from './BatchObserverResult'; -import { Meter } from './Meter'; -import { - MetricOptions, - UnboundMetric, - Labels, - Counter, - ValueRecorder, - ValueObserver, - UpDownCounter, - BaseObserver, - UpDownSumObserver, -} from './Metric'; -import { - BoundValueRecorder, - BoundCounter, - BoundBaseObserver, -} from './BoundInstrument'; -import { Baggage } from '../baggage/Baggage'; -import { SpanContext } from '../trace/span_context'; -import { ObserverResult } from './ObserverResult'; - -/** - * NoopMeter is a noop implementation of the {@link Meter} interface. It reuses - * constant NoopMetrics for all of its methods. - */ -export class NoopMeter implements Meter { - constructor() {} - - /** - * Returns constant noop value recorder. - * @param name the name of the metric. - * @param [options] the metric options. - */ - createValueRecorder(_name: string, _options?: MetricOptions): ValueRecorder { - return NOOP_VALUE_RECORDER_METRIC; - } - - /** - * Returns a constant noop counter. - * @param name the name of the metric. - * @param [options] the metric options. - */ - createCounter(_name: string, _options?: MetricOptions): Counter { - return NOOP_COUNTER_METRIC; - } - - /** - * Returns a constant noop UpDownCounter. - * @param name the name of the metric. - * @param [options] the metric options. - */ - createUpDownCounter(_name: string, _options?: MetricOptions): UpDownCounter { - return NOOP_COUNTER_METRIC; - } - - /** - * Returns constant noop value observer. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the value observer callback - */ - createValueObserver( - _name: string, - _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): ValueObserver { - return NOOP_VALUE_OBSERVER_METRIC; - } - - /** - * Returns constant noop sum observer. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the sum observer callback - */ - createSumObserver( - _name: string, - _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): ValueObserver { - return NOOP_SUM_OBSERVER_METRIC; - } - - /** - * Returns constant noop up down sum observer. - * @param name the name of the metric. - * @param [options] the metric options. - * @param [callback] the up down sum observer callback - */ - createUpDownSumObserver( - _name: string, - _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): UpDownSumObserver { - return NOOP_UP_DOWN_SUM_OBSERVER_METRIC; - } - - /** - * Returns constant noop batch observer. - * @param name the name of the metric. - * @param callback the batch observer callback - */ - createBatchObserver( - _callback: (batchObserverResult: BatchObserverResult) => void - ): NoopBatchObserver { - return NOOP_BATCH_OBSERVER; - } -} - -export class NoopMetric implements UnboundMetric { - private readonly _instrument: T; - - constructor(instrument: T) { - this._instrument = instrument; - } - - /** - * Returns a Bound Instrument associated with specified Labels. - * It is recommended to keep a reference to the Bound Instrument instead of - * always calling this method for every operations. - * @param labels key-values pairs that are associated with a specific metric - * that you want to record. - */ - bind(_labels: Labels): T { - return this._instrument; - } - - /** - * Removes the Binding from the metric, if it is present. - * @param labels key-values pairs that are associated with a specific metric. - */ - unbind(_labels: Labels): void { - return; - } - - /** - * Clears all timeseries from the Metric. - */ - clear(): void { - return; - } -} - -export class NoopCounterMetric - extends NoopMetric - implements Counter { - add(value: number, labels: Labels) { - this.bind(labels).add(value); - } -} - -export class NoopValueRecorderMetric - extends NoopMetric - implements ValueRecorder { - record(value: number, labels: Labels) { - this.bind(labels).record(value); - } -} - -export class NoopBaseObserverMetric - extends NoopMetric - implements BaseObserver { - observation() { - return { - observer: this as BaseObserver, - value: 0, - }; - } -} - -export class NoopBatchObserver {} - -export class NoopBoundCounter implements BoundCounter { - add(_value: number): void { - return; - } -} - -export class NoopBoundValueRecorder implements BoundValueRecorder { - record(_value: number, _baggage?: Baggage, _spanContext?: SpanContext): void { - return; - } -} - -export class NoopBoundBaseObserver implements BoundBaseObserver { - update(_value: number) {} -} - -export const NOOP_METER = new NoopMeter(); -export const NOOP_BOUND_COUNTER = new NoopBoundCounter(); -export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER); - -export const NOOP_BOUND_VALUE_RECORDER = new NoopBoundValueRecorder(); -export const NOOP_VALUE_RECORDER_METRIC = new NoopValueRecorderMetric( - NOOP_BOUND_VALUE_RECORDER -); - -export const NOOP_BOUND_BASE_OBSERVER = new NoopBoundBaseObserver(); -export const NOOP_VALUE_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER -); - -export const NOOP_UP_DOWN_SUM_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER -); - -export const NOOP_SUM_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER -); - -export const NOOP_BATCH_OBSERVER = new NoopBatchObserver(); diff --git a/api/src/metrics/NoopMeterProvider.ts b/api/src/metrics/NoopMeterProvider.ts deleted file mode 100644 index 13e73c0e2fd..00000000000 --- a/api/src/metrics/NoopMeterProvider.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Meter } from './Meter'; -import { MeterProvider } from './MeterProvider'; -import { NOOP_METER } from './NoopMeter'; - -/** - * An implementation of the {@link MeterProvider} which returns an impotent Meter - * for all calls to `getMeter` - */ -export class NoopMeterProvider implements MeterProvider { - getMeter(_name?: string, _version?: string): Meter { - return NOOP_METER; - } -} - -export const NOOP_METER_PROVIDER = new NoopMeterProvider(); diff --git a/api/src/metrics/Observation.ts b/api/src/metrics/Observation.ts deleted file mode 100644 index d36f48fb717..00000000000 --- a/api/src/metrics/Observation.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { BaseObserver } from './Metric'; - -/** - * Interface for updating value of certain value observer - */ -export interface Observation { - observer: BaseObserver; - value: number; -} diff --git a/api/src/metrics/ObserverResult.ts b/api/src/metrics/ObserverResult.ts deleted file mode 100644 index 7792483ad1a..00000000000 --- a/api/src/metrics/ObserverResult.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Labels } from './Metric'; - -/** - * Interface that is being used in callback function for Observer Metric - */ -export interface ObserverResult { - observe(value: number, labels: Labels): void; -} diff --git a/api/test/api/api.test.ts b/api/test/api/api.test.ts index cc02a460f8f..bb15fb02e9b 100644 --- a/api/test/api/api.test.ts +++ b/api/test/api/api.test.ts @@ -25,7 +25,6 @@ import api, { context, trace, propagation, - metrics, TextMapPropagator, Context, TextMapSetter, @@ -54,7 +53,6 @@ describe('API', () => { context.disable(); trace.disable(); propagation.disable(); - metrics.disable(); }); it('should use the global tracer provider', () => { diff --git a/api/test/api/global.test.ts b/api/test/api/global.test.ts index 7d9ea5b9caa..5a489650715 100644 --- a/api/test/api/global.test.ts +++ b/api/test/api/global.test.ts @@ -42,7 +42,6 @@ describe('Global Utils', () => { api1.context.disable(); api1.propagation.disable(); api1.trace.disable(); - api1.metrics.disable(); }); it('should change the global context manager', () => { diff --git a/api/test/noop-implementations/noop-meter.test.ts b/api/test/noop-implementations/noop-meter.test.ts deleted file mode 100644 index cbfe044a9f7..00000000000 --- a/api/test/noop-implementations/noop-meter.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as assert from 'assert'; -import { - NoopMeterProvider, - NOOP_BOUND_COUNTER, - NOOP_BOUND_VALUE_RECORDER, - NOOP_COUNTER_METRIC, - NOOP_VALUE_RECORDER_METRIC, -} from '../../src'; - -describe('NoopMeter', () => { - it('should not crash', () => { - const meter = new NoopMeterProvider().getMeter('test-noop'); - const counter = meter.createCounter('some-name'); - const labels = {}; - - // ensure NoopMetric does not crash. - counter.bind(labels).add(1); - counter.unbind(labels); - - // ensure the correct noop const is returned - assert.strictEqual(counter, NOOP_COUNTER_METRIC); - assert.strictEqual(counter.bind(labels), NOOP_BOUND_COUNTER); - counter.clear(); - - const valueRecorder = meter.createValueRecorder('some-name'); - valueRecorder.bind(labels).record(1); - - // ensure the correct noop const is returned - assert.strictEqual(valueRecorder, NOOP_VALUE_RECORDER_METRIC); - assert.strictEqual(valueRecorder.bind(labels), NOOP_BOUND_VALUE_RECORDER); - - const options = { - component: 'tests', - description: 'the testing package', - }; - - const valueRecorderWithOptions = meter.createValueRecorder( - 'some-name', - options - ); - assert.strictEqual(valueRecorderWithOptions, NOOP_VALUE_RECORDER_METRIC); - const counterWithOptions = meter.createCounter('some-name', options); - assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC); - }); -}); diff --git a/api/tsconfig.json b/api/tsconfig.json index e772bb4c729..705bf6a93aa 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -11,6 +11,9 @@ { "path": "backwards-compatability/node8" }, + { + "path": "packages/opentelemetry-api-metrics" + }, { "path": "packages/opentelemetry-api" },