/* * 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 api from '@opentelemetry/api'; import { AggregationTemporality } from './AggregationTemporality'; import { MetricProducer } from './MetricProducer'; import { CollectionResult, InstrumentType } from './MetricData'; import { callWithTimeout, FlatMap } from '../utils'; import { CollectionOptions, ForceFlushOptions, ShutdownOptions, } from '../types'; import { AggregationSelector, AggregationTemporalitySelector, DEFAULT_AGGREGATION_SELECTOR, DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR, } from './AggregationSelector'; import { AggregationOption } from '../view/AggregationOption'; import { CardinalitySelector } from './CardinalitySelector'; export interface MetricReaderOptions { /** * Aggregation selector based on metric instrument types. If no views are * configured for a metric instrument, a per-metric-reader aggregation is * selected with this selector. * *
NOTE: the provided function MUST be pure */ aggregationSelector?: AggregationSelector; /** * Aggregation temporality selector based on metric instrument types. If * not configured, cumulative is used for all instruments. * *
NOTE: the provided function MUST be pure */ aggregationTemporalitySelector?: AggregationTemporalitySelector; /** * Cardinality selector based on metric instrument types. If not configured, * a default value is used. * *
NOTE: the provided function MUST be pure */ cardinalitySelector?: CardinalitySelector; /** * **Note, this option is experimental**. Additional MetricProducers to use as a source of * aggregated metric data in addition to the SDK's metric data. The resource returned by * these MetricProducers is ignored; the SDK's resource will be used instead. * @experimental */ metricProducers?: MetricProducer[]; } /** * Reads metrics from the SDK. Implementations MUST follow the Metric Reader Specification as well as the requirements * listed in this interface. Consider extending {@link MetricReader} to get a specification-compliant base implementation * of this interface */ export interface IMetricReader { /** * Set the {@link MetricProducer} used by this instance. **This should only be called once by the * SDK and should be considered internal.** * *
NOTE: implementations MUST throw when called more than once * * @param metricProducer */ setMetricProducer(metricProducer: MetricProducer): void; /** * Select the {@link AggregationOption} for the given {@link InstrumentType} for this * reader. * *
NOTE: implementations MUST be pure */ selectAggregation(instrumentType: InstrumentType): AggregationOption; /** * Select the {@link AggregationTemporality} for the given * {@link InstrumentType} for this reader. * *
NOTE: implementations MUST be pure */ selectAggregationTemporality( instrumentType: InstrumentType ): AggregationTemporality; /** * Select the cardinality limit for the given {@link InstrumentType} for this * reader. * *
NOTE: implementations MUST be pure
*/
selectCardinalityLimit(instrumentType: InstrumentType): number;
/**
* Collect all metrics from the associated {@link MetricProducer}
*/
collect(options?: CollectionOptions): Promise NOTE: this operation MAY continue even after the promise rejects due to a timeout.
* @param options options with timeout.
*/
shutdown(options?: ShutdownOptions): Promise NOTE: this operation MAY continue even after the promise rejects due to a timeout.
* @param options options with timeout.
*/
forceFlush(options?: ForceFlushOptions): Promise For push exporters, this should shut down any intervals and close any open connections.
* @protected
*/
protected abstract onShutdown(): Promise In all scenarios metrics should be collected via {@link collect()}.
* For push exporters, this should collect and report metrics.
* @protected
*/
protected abstract onForceFlush(): Promise