Socket
Socket
Sign inDemoInstall

@opentelemetry/sdk-metrics

Package Overview
Dependencies
4
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.32.0 to 0.33.0

build/esm/export/AggregationSelector.d.ts

1

build/esm/aggregator/types.d.ts

@@ -87,2 +87,3 @@ import { HrTime } from '@opentelemetry/api';

* @param descriptor the metric instrument descriptor.
* @param aggregationTemporality the temporality of the resulting {@link MetricData}
* @param accumulationByAttributes the array of attributes and accumulation pairs.

@@ -89,0 +90,0 @@ * @param endTime the end time of the metric data.

2

build/esm/exemplar/ExemplarFilter.d.ts

@@ -15,3 +15,3 @@ import { MetricAttributes } from '@opentelemetry/api-metrics';

* @param attributes The complete set of MetricAttributes of the measurement
* @param context The Context of the measurement
* @param ctx The Context of the measurement
*/

@@ -18,0 +18,0 @@ shouldSample(value: number, timestamp: HrTime, attributes: MetricAttributes, ctx: Context): boolean;

@@ -1,2 +0,1 @@

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

@@ -9,3 +8,2 @@ * AggregationTemporality indicates the way additive quantities are expressed.

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*/
export interface BaseMetricData {
interface BaseMetricData {
readonly descriptor: InstrumentDescriptor;

@@ -121,2 +121,3 @@ readonly aggregationTemporality: AggregationTemporality;

}
export {};
//# sourceMappingURL=MetricData.d.ts.map

@@ -5,2 +5,3 @@ import { AggregationTemporality } from './AggregationTemporality';

import { InstrumentType } from '../InstrumentDescriptor';
import { Aggregation } from '../view/Aggregation';
/**

@@ -16,2 +17,3 @@ * An interface that allows different metric services to export recorded data

* @param metrics the metric data to be exported.
* @param resultCallback callback for when the export has completed
*/

@@ -28,4 +30,9 @@ export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;

*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality?(instrumentType: InstrumentType): AggregationTemporality;
/**
* Select the {@link Aggregation} for the given
* {@link InstrumentType} for this exporter.
*/
selectAggregation?(instrumentType: InstrumentType): Aggregation;
/**
* Returns a promise which resolves when the last exportation is completed.

@@ -32,0 +39,0 @@ * Further calls to {@link PushMetricExporter.export} may not export the

@@ -6,2 +6,17 @@ import { AggregationTemporality } from './AggregationTemporality';

import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';
import { Aggregation } from '../view/Aggregation';
import { AggregationSelector, AggregationTemporalitySelector } from './AggregationSelector';
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.
*/
aggregationSelector?: AggregationSelector;
/**
* Aggregation temporality selector based on metric instrument types. If
* not configured, cumulative is used for all instruments.
*/
aggregationTemporalitySelector?: AggregationTemporalitySelector;
}
/**

@@ -14,2 +29,5 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

private _metricProducer?;
private readonly _aggregationTemporalitySelector;
private readonly _aggregationSelector;
constructor(options?: MetricReaderOptions);
/**

@@ -22,6 +40,11 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
selectAggregation(instrumentType: InstrumentType): Aggregation;
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -28,0 +51,0 @@ * Handle once the SDK has initialized this {@link MetricReader}

@@ -54,2 +54,3 @@ /*

import { callWithTimeout } from '../utils';
import { DEFAULT_AGGREGATION_SELECTOR, DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR } from './AggregationSelector';
/**

@@ -60,6 +61,9 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

var MetricReader = /** @class */ (function () {
function MetricReader() {
function MetricReader(options) {
var _a, _b;
// Tracks the shutdown state.
// TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.
this._shutdown = false;
this._aggregationSelector = (_a = options === null || options === void 0 ? void 0 : options.aggregationSelector) !== null && _a !== void 0 ? _a : DEFAULT_AGGREGATION_SELECTOR;
this._aggregationTemporalitySelector = (_b = options === null || options === void 0 ? void 0 : options.aggregationTemporalitySelector) !== null && _b !== void 0 ? _b : DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR;
}

@@ -79,2 +83,16 @@ /**

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
MetricReader.prototype.selectAggregation = function (instrumentType) {
return this._aggregationSelector(instrumentType);
};
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
MetricReader.prototype.selectAggregationTemporality = function (instrumentType) {
return this._aggregationTemporalitySelector(instrumentType);
};
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -81,0 +99,0 @@ * Overriding this method is optional.

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';
export declare type PeriodicExportingMetricReaderOptions = {
/**
* The backing exporter for the metric reader.
*/
exporter: PushMetricExporter;
/**
* An internal milliseconds for the metric reader to initiate metric
* collection.
*/
exportIntervalMillis?: number;
/**
* Milliseconds for the async observable callback to timeout.
*/
exportTimeoutMillis?: number;

@@ -12,3 +20,3 @@ };

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/

@@ -25,7 +33,3 @@ export declare class PeriodicExportingMetricReader extends MetricReader {

protected onShutdown(): Promise<void>;
/**
* @inheritdoc
*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
}
//# sourceMappingURL=PeriodicExportingMetricReader.d.ts.map

@@ -98,3 +98,3 @@ /*

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/

@@ -104,4 +104,7 @@ var PeriodicExportingMetricReader = /** @class */ (function (_super) {

function PeriodicExportingMetricReader(options) {
var _a, _b;
var _this = _super.call(this) || this;
var _a, _b, _c, _d;
var _this = _super.call(this, {
aggregationSelector: (_a = options.exporter.selectAggregation) === null || _a === void 0 ? void 0 : _a.bind(options.exporter),
aggregationTemporalitySelector: (_b = options.exporter.selectAggregationTemporality) === null || _b === void 0 ? void 0 : _b.bind(options.exporter)
}) || this;
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -118,4 +121,4 @@ throw Error('exportIntervalMillis must be greater than 0');

}
_this._exportInterval = (_a = options.exportIntervalMillis) !== null && _a !== void 0 ? _a : 60000;
_this._exportTimeout = (_b = options.exportTimeoutMillis) !== null && _b !== void 0 ? _b : 30000;
_this._exportInterval = (_c = options.exportIntervalMillis) !== null && _c !== void 0 ? _c : 60000;
_this._exportTimeout = (_d = options.exportTimeoutMillis) !== null && _d !== void 0 ? _d : 30000;
_this._exporter = options.exporter;

@@ -207,8 +210,2 @@ return _this;

};
/**
* @inheritdoc
*/
PeriodicExportingMetricReader.prototype.selectAggregationTemporality = function (instrumentType) {
return this._exporter.selectAggregationTemporality(instrumentType);
};
return PeriodicExportingMetricReader;

@@ -215,0 +212,0 @@ }(MetricReader));

@@ -1,17 +0,15 @@

export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
export * from './export/MetricProducer';
export * from './export/MetricReader';
export * from './export/PeriodicExportingMetricReader';
export * from './export/InMemoryMetricExporter';
export * from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { Sum, LastValue, Histogram, } from './aggregator/types';
export { AggregationSelector, AggregationTemporalitySelector, } from './export/AggregationSelector';
export { AggregationTemporality, } from './export/AggregationTemporality';
export { DataPoint, DataPointType, SumMetricData, GaugeMetricData, HistogramMetricData, ResourceMetrics, ScopeMetrics, MetricData, CollectionResult, } from './export/MetricData';
export { PushMetricExporter, } from './export/MetricExporter';
export { MetricReader, MetricReaderOptions } from './export/MetricReader';
export { PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, } from './export/PeriodicExportingMetricReader';
export { InMemoryMetricExporter, } from './export/InMemoryMetricExporter';
export { ConsoleMetricExporter, } from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType, } from './InstrumentDescriptor';
export { MeterProvider, MeterProviderOptions, } from './MeterProvider';
export { DefaultAggregation, ExplicitBucketHistogramAggregation, DropAggregation, HistogramAggregation, LastValueAggregation, SumAggregation, Aggregation } from './view/Aggregation';
export { View, ViewOptions, } from './view/View';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
export * from './view/View';
//# sourceMappingURL=index.d.ts.map

@@ -16,17 +16,13 @@ /*

*/
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
export * from './export/MetricProducer';
export * from './export/MetricReader';
export * from './export/PeriodicExportingMetricReader';
export * from './export/InMemoryMetricExporter';
export * from './export/ConsoleMetricExporter';
export { InstrumentType } from './InstrumentDescriptor';
export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { AggregationTemporality, } from './export/AggregationTemporality';
export { DataPointType, } from './export/MetricData';
export { MetricReader } from './export/MetricReader';
export { PeriodicExportingMetricReader, } from './export/PeriodicExportingMetricReader';
export { InMemoryMetricExporter, } from './export/InMemoryMetricExporter';
export { ConsoleMetricExporter, } from './export/ConsoleMetricExporter';
export { InstrumentType, } from './InstrumentDescriptor';
export { MeterProvider, } from './MeterProvider';
export { DefaultAggregation, ExplicitBucketHistogramAggregation, DropAggregation, HistogramAggregation, LastValueAggregation, SumAggregation, Aggregation } from './view/Aggregation';
export { View, } from './view/View';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
export * from './view/View';
//# sourceMappingURL=index.js.map

@@ -102,3 +102,3 @@ /*

api.diag.warn('A shutdown MeterProvider cannot provide a Meter');
return metrics.NOOP_METER;
return metrics.createNoopMeter();
}

@@ -105,0 +105,0 @@ return this._sharedState

import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { Aggregation, InstrumentType } from '..';
import { ViewRegistry } from '../view/ViewRegistry';
import { MeterSharedState } from './MeterSharedState';
import { MetricCollector } from './MetricCollector';
import { MetricCollector, MetricCollectorHandle } from './MetricCollector';
/**

@@ -16,3 +17,4 @@ * An internal record for shared meter provider states.

getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
selectAggregations(instrumentType: InstrumentType): [MetricCollectorHandle, Aggregation][];
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

@@ -16,2 +16,13 @@ /*

*/
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { instrumentationScopeId } from '../utils';

@@ -39,2 +50,20 @@ import { ViewRegistry } from '../view/ViewRegistry';

};
MeterProviderSharedState.prototype.selectAggregations = function (instrumentType) {
var e_1, _a;
var result = [];
try {
for (var _b = __values(this.metricCollectors), _c = _b.next(); !_c.done; _c = _b.next()) {
var collector = _c.value;
result.push([collector, collector.selectAggregation(instrumentType)]);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return result;
};
return MeterProviderSharedState;

@@ -41,0 +70,0 @@ }());

@@ -7,8 +7,11 @@ import { HrTime } from '@opentelemetry/api';

import { Meter } from '../Meter';
import { Maybe } from '../utils';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MetricStorageRegistry } from './MetricStorageRegistry';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';
import { Accumulation } from '../aggregator/types';
/**

@@ -20,14 +23,16 @@ * An internal record for shared meter provider states.

private _instrumentationScope;
private _metricStorageRegistry;
metricStorageRegistry: MetricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationScope: InstrumentationScope);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>[];
registerMetricStorage(descriptor: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>> | MultiMetricStorage;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<Maybe<Accumulation>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
private _registerMetricStorage;
}

@@ -34,0 +39,0 @@ interface ScopeMetricsResult {

@@ -52,2 +52,18 @@ /*

};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { createInstrumentDescriptorWithView } from '../InstrumentDescriptor';

@@ -61,2 +77,3 @@ import { Meter } from '../Meter';

import { SyncMetricStorage } from './SyncMetricStorage';
import { AttributesProcessor } from '../view/AttributesProcessor';
/**

@@ -69,3 +86,3 @@ * An internal record for shared meter provider states.

this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry();
this.metricStorageRegistry = new MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry();

@@ -75,12 +92,3 @@ this.meter = new Meter(this);

MeterSharedState.prototype.registerMetricStorage = function (descriptor) {
var _this = this;
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
var storages = views
.map(function (view) {
var viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
var aggregator = view.aggregation.createAggregator(viewDescriptor);
var storage = new SyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return _this._metricStorageRegistry.register(storage);
})
.filter(isNotNullish);
var storages = this._registerMetricStorage(descriptor, SyncMetricStorage);
if (storages.length === 1) {

@@ -92,12 +100,3 @@ return storages[0];

MeterSharedState.prototype.registerAsyncMetricStorage = function (descriptor) {
var _this = this;
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
var storages = views
.map(function (view) {
var viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
var aggregator = view.aggregation.createAggregator(viewDescriptor);
var viewStorage = new AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return _this._metricStorageRegistry.register(viewStorage);
})
.filter(isNotNullish);
var storages = this._registerMetricStorage(descriptor, AsyncMetricStorage);
return storages;

@@ -108,2 +107,3 @@ };

* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.

@@ -120,3 +120,3 @@ */

errors = _a.sent();
metricDataList = Array.from(this._metricStorageRegistry.getStorages())
metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
.map(function (metricStorage) {

@@ -137,2 +137,35 @@ return metricStorage.collect(collector, _this._meterProviderSharedState.metricCollectors, collectionTime);

};
MeterSharedState.prototype._registerMetricStorage = function (descriptor, MetricStorageType) {
var _this = this;
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
var storages = views
.map(function (view) {
var viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
var compatibleStorage = _this.metricStorageRegistry.findOrUpdateCompatibleStorage(viewDescriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
var aggregator = view.aggregation.createAggregator(viewDescriptor);
var viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
_this.metricStorageRegistry.register(viewStorage);
return viewStorage;
});
// Fallback to the per-collector aggregations if no view is configured for the instrument.
if (storages.length === 0) {
var perCollectorAggregations = this._meterProviderSharedState.selectAggregations(descriptor.type);
var collectorStorages = perCollectorAggregations.map(function (_a) {
var _b = __read(_a, 2), collector = _b[0], aggregation = _b[1];
var compatibleStorage = _this.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(collector, descriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
var aggregator = aggregation.createAggregator(descriptor);
var storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop());
_this.metricStorageRegistry.registerForCollector(collector, storage);
return storage;
});
storages = storages.concat(collectorStorages);
}
return storages;
};
return MeterSharedState;

@@ -139,0 +172,0 @@ }());

@@ -1,2 +0,2 @@

import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { AggregationTemporalitySelector } from '../export/AggregationSelector';
import { CollectionResult } from '../export/MetricData';

@@ -26,3 +26,4 @@ import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';

shutdown(options?: ShutdownOptions): Promise<void>;
selectAggregationTemporality(instrumentType: InstrumentType): import("../export/AggregationTemporality").AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): import("..").AggregationTemporality;
selectAggregation(instrumentType: InstrumentType): import("..").Aggregation;
}

@@ -29,0 +30,0 @@ /**

@@ -121,2 +121,5 @@ /*

};
MetricCollector.prototype.selectAggregation = function (instrumentType) {
return this._metricReader.selectAggregation(instrumentType);
};
return MetricCollector;

@@ -123,0 +126,0 @@ }());

@@ -21,5 +21,5 @@ import { HrTime } from '@opentelemetry/api';

abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;
getInstrumentDescriptor(): Readonly<InstrumentDescriptor>;
updateDescription(description: string): void;
}
//# sourceMappingURL=MetricStorage.d.ts.map
import { MetricStorage } from './MetricStorage';
import { Maybe } from '../utils';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { MetricCollectorHandle } from './MetricCollector';
/**

@@ -7,7 +8,13 @@ * Internal class for storing {@link MetricStorage}

export declare class MetricStorageRegistry {
private readonly _metricStorageRegistry;
private readonly _sharedRegistry;
private readonly _perCollectorRegistry;
static create(): MetricStorageRegistry;
getStorages(): MetricStorage[];
register<T extends MetricStorage>(storage: T): Maybe<T>;
getStorages(collector: MetricCollectorHandle): MetricStorage[];
register(storage: MetricStorage): void;
registerForCollector(collector: MetricCollectorHandle, storage: MetricStorage): void;
findOrUpdateCompatibleStorage<T extends MetricStorage>(expectedDescriptor: InstrumentDescriptor): T | null;
findOrUpdateCompatibleCollectorStorage<T extends MetricStorage>(collector: MetricCollectorHandle, expectedDescriptor: InstrumentDescriptor): T | null;
private _registerStorage;
private _findOrUpdateCompatibleStorage;
}
//# sourceMappingURL=MetricStorageRegistry.d.ts.map

@@ -35,3 +35,4 @@ /*

function MetricStorageRegistry() {
this._metricStorageRegistry = new Map();
this._sharedRegistry = new Map();
this._perCollectorRegistry = new Map();
}

@@ -41,8 +42,8 @@ MetricStorageRegistry.create = function () {

};
MetricStorageRegistry.prototype.getStorages = function () {
var e_1, _a;
MetricStorageRegistry.prototype.getStorages = function (collector) {
var e_1, _a, e_2, _b;
var storages = [];
try {
for (var _b = __values(this._metricStorageRegistry.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
var metricStorages = _c.value;
for (var _c = __values(this._sharedRegistry.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
var metricStorages = _d.value;
storages = storages.concat(metricStorages);

@@ -54,17 +55,68 @@ }

try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
var perCollectorStorages = this._perCollectorRegistry.get(collector);
if (perCollectorStorages != null) {
try {
for (var _e = __values(perCollectorStorages.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
var metricStorages = _f.value;
storages = storages.concat(metricStorages);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
}
return storages;
};
MetricStorageRegistry.prototype.register = function (storage) {
var e_2, _a;
var expectedDescriptor = storage.getInstrumentDescriptor();
var existingStorages = this._metricStorageRegistry.get(expectedDescriptor.name);
// Add storage if it does not exist.
if (existingStorages === undefined) {
this._metricStorageRegistry.set(expectedDescriptor.name, [storage]);
return storage;
this._registerStorage(storage, this._sharedRegistry);
};
MetricStorageRegistry.prototype.registerForCollector = function (collector, storage) {
var storageMap = this._perCollectorRegistry.get(collector);
if (storageMap == null) {
storageMap = new Map();
this._perCollectorRegistry.set(collector, storageMap);
}
this._registerStorage(storage, storageMap);
};
MetricStorageRegistry.prototype.findOrUpdateCompatibleStorage = function (expectedDescriptor) {
var storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
};
MetricStorageRegistry.prototype.findOrUpdateCompatibleCollectorStorage = function (collector, expectedDescriptor) {
var storageMap = this._perCollectorRegistry.get(collector);
if (storageMap === undefined) {
return null;
}
var storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
};
MetricStorageRegistry.prototype._registerStorage = function (storage, storageMap) {
var descriptor = storage.getInstrumentDescriptor();
var storages = storageMap.get(descriptor.name);
if (storages === undefined) {
storageMap.set(descriptor.name, [storage]);
return;
}
storages.push(storage);
};
MetricStorageRegistry.prototype._findOrUpdateCompatibleStorage = function (expectedDescriptor, existingStorages) {
var e_3, _a;
var compatibleStorage = null;

@@ -93,3 +145,3 @@ try {

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -99,10 +151,5 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_3) throw e_3.error; }
}
if (compatibleStorage != null) {
return compatibleStorage;
}
// None of the storages were compatible, add the current one to the list.
existingStorages.push(storage);
return storage;
return compatibleStorage;
};

@@ -109,0 +156,0 @@ return MetricStorageRegistry;

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -24,4 +24,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -28,0 +26,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -48,3 +48,3 @@ /*

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -62,4 +62,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -66,0 +64,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -1,2 +0,2 @@

export declare const VERSION = "0.32.0";
export declare const VERSION = "0.33.0";
//# sourceMappingURL=version.d.ts.map

@@ -17,3 +17,3 @@ /*

// this is autogenerated file, see scripts/version-update.js
export var VERSION = '0.32.0';
export var VERSION = '0.33.0';
//# sourceMappingURL=version.js.map

@@ -5,3 +5,3 @@ export interface Predicate {

/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -8,0 +8,0 @@ export declare class PatternPredicate implements Predicate {

@@ -18,6 +18,6 @@ /*

// escape ^ $ \ . + ? ( ) [ ] { } |
// do not need to escape * as we are interpret it as wildcard
// do not need to escape * as we interpret it as wildcard
var ESCAPE = /[\^$\\.+?()[\]{}|]/g;
/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -24,0 +24,0 @@ var PatternPredicate = /** @class */ (function () {

@@ -5,3 +5,2 @@ import { InstrumentationScope } from '@opentelemetry/core';

export declare class ViewRegistry {
private static DEFAULT_VIEW;
private _registeredViews;

@@ -8,0 +7,0 @@ addView(view: View): void;

@@ -16,3 +16,2 @@ /*

*/
import { View } from './View';
var ViewRegistry = /** @class */ (function () {

@@ -32,5 +31,2 @@ function ViewRegistry() {

});
if (views.length === 0) {
return [ViewRegistry.DEFAULT_VIEW];
}
return views;

@@ -47,5 +43,2 @@ };

};
ViewRegistry.DEFAULT_VIEW = new View({
instrumentName: '*'
});
return ViewRegistry;

@@ -52,0 +45,0 @@ }());

@@ -87,2 +87,3 @@ import { HrTime } from '@opentelemetry/api';

* @param descriptor the metric instrument descriptor.
* @param aggregationTemporality the temporality of the resulting {@link MetricData}
* @param accumulationByAttributes the array of attributes and accumulation pairs.

@@ -89,0 +90,0 @@ * @param endTime the end time of the metric data.

@@ -15,3 +15,3 @@ import { MetricAttributes } from '@opentelemetry/api-metrics';

* @param attributes The complete set of MetricAttributes of the measurement
* @param context The Context of the measurement
* @param ctx The Context of the measurement
*/

@@ -18,0 +18,0 @@ shouldSample(value: number, timestamp: HrTime, attributes: MetricAttributes, ctx: Context): boolean;

@@ -1,2 +0,1 @@

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

@@ -9,3 +8,2 @@ * AggregationTemporality indicates the way additive quantities are expressed.

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*/
export interface BaseMetricData {
interface BaseMetricData {
readonly descriptor: InstrumentDescriptor;

@@ -121,2 +121,3 @@ readonly aggregationTemporality: AggregationTemporality;

}
export {};
//# sourceMappingURL=MetricData.d.ts.map

@@ -5,2 +5,3 @@ import { AggregationTemporality } from './AggregationTemporality';

import { InstrumentType } from '../InstrumentDescriptor';
import { Aggregation } from '../view/Aggregation';
/**

@@ -16,2 +17,3 @@ * An interface that allows different metric services to export recorded data

* @param metrics the metric data to be exported.
* @param resultCallback callback for when the export has completed
*/

@@ -28,4 +30,9 @@ export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;

*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality?(instrumentType: InstrumentType): AggregationTemporality;
/**
* Select the {@link Aggregation} for the given
* {@link InstrumentType} for this exporter.
*/
selectAggregation?(instrumentType: InstrumentType): Aggregation;
/**
* Returns a promise which resolves when the last exportation is completed.

@@ -32,0 +39,0 @@ * Further calls to {@link PushMetricExporter.export} may not export the

@@ -6,2 +6,17 @@ import { AggregationTemporality } from './AggregationTemporality';

import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';
import { Aggregation } from '../view/Aggregation';
import { AggregationSelector, AggregationTemporalitySelector } from './AggregationSelector';
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.
*/
aggregationSelector?: AggregationSelector;
/**
* Aggregation temporality selector based on metric instrument types. If
* not configured, cumulative is used for all instruments.
*/
aggregationTemporalitySelector?: AggregationTemporalitySelector;
}
/**

@@ -14,2 +29,5 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

private _metricProducer?;
private readonly _aggregationTemporalitySelector;
private readonly _aggregationSelector;
constructor(options?: MetricReaderOptions);
/**

@@ -22,6 +40,11 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
selectAggregation(instrumentType: InstrumentType): Aggregation;
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -28,0 +51,0 @@ * Handle once the SDK has initialized this {@link MetricReader}

@@ -18,2 +18,3 @@ /*

import { callWithTimeout } from '../utils';
import { DEFAULT_AGGREGATION_SELECTOR, DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR } from './AggregationSelector';
/**

@@ -24,6 +25,9 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

export class MetricReader {
constructor() {
constructor(options) {
var _a, _b;
// Tracks the shutdown state.
// TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.
this._shutdown = false;
this._aggregationSelector = (_a = options === null || options === void 0 ? void 0 : options.aggregationSelector) !== null && _a !== void 0 ? _a : DEFAULT_AGGREGATION_SELECTOR;
this._aggregationTemporalitySelector = (_b = options === null || options === void 0 ? void 0 : options.aggregationTemporalitySelector) !== null && _b !== void 0 ? _b : DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR;
}

@@ -43,2 +47,16 @@ /**

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
selectAggregation(instrumentType) {
return this._aggregationSelector(instrumentType);
}
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
selectAggregationTemporality(instrumentType) {
return this._aggregationTemporalitySelector(instrumentType);
}
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -45,0 +63,0 @@ * Overriding this method is optional.

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';
export declare type PeriodicExportingMetricReaderOptions = {
/**
* The backing exporter for the metric reader.
*/
exporter: PushMetricExporter;
/**
* An internal milliseconds for the metric reader to initiate metric
* collection.
*/
exportIntervalMillis?: number;
/**
* Milliseconds for the async observable callback to timeout.
*/
exportTimeoutMillis?: number;

@@ -12,3 +20,3 @@ };

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/

@@ -25,7 +33,3 @@ export declare class PeriodicExportingMetricReader extends MetricReader {

protected onShutdown(): Promise<void>;
/**
* @inheritdoc
*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
}
//# sourceMappingURL=PeriodicExportingMetricReader.d.ts.map

@@ -22,8 +22,11 @@ /*

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/
export class PeriodicExportingMetricReader extends MetricReader {
constructor(options) {
var _a, _b;
super();
var _a, _b, _c, _d;
super({
aggregationSelector: (_a = options.exporter.selectAggregation) === null || _a === void 0 ? void 0 : _a.bind(options.exporter),
aggregationTemporalitySelector: (_b = options.exporter.selectAggregationTemporality) === null || _b === void 0 ? void 0 : _b.bind(options.exporter)
});
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -40,4 +43,4 @@ throw Error('exportIntervalMillis must be greater than 0');

}
this._exportInterval = (_a = options.exportIntervalMillis) !== null && _a !== void 0 ? _a : 60000;
this._exportTimeout = (_b = options.exportTimeoutMillis) !== null && _b !== void 0 ? _b : 30000;
this._exportInterval = (_c = options.exportIntervalMillis) !== null && _c !== void 0 ? _c : 60000;
this._exportTimeout = (_d = options.exportTimeoutMillis) !== null && _d !== void 0 ? _d : 30000;
this._exporter = options.exporter;

@@ -87,9 +90,3 @@ }

}
/**
* @inheritdoc
*/
selectAggregationTemporality(instrumentType) {
return this._exporter.selectAggregationTemporality(instrumentType);
}
}
//# sourceMappingURL=PeriodicExportingMetricReader.js.map

@@ -1,17 +0,15 @@

export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
export * from './export/MetricProducer';
export * from './export/MetricReader';
export * from './export/PeriodicExportingMetricReader';
export * from './export/InMemoryMetricExporter';
export * from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { Sum, LastValue, Histogram, } from './aggregator/types';
export { AggregationSelector, AggregationTemporalitySelector, } from './export/AggregationSelector';
export { AggregationTemporality, } from './export/AggregationTemporality';
export { DataPoint, DataPointType, SumMetricData, GaugeMetricData, HistogramMetricData, ResourceMetrics, ScopeMetrics, MetricData, CollectionResult, } from './export/MetricData';
export { PushMetricExporter, } from './export/MetricExporter';
export { MetricReader, MetricReaderOptions } from './export/MetricReader';
export { PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, } from './export/PeriodicExportingMetricReader';
export { InMemoryMetricExporter, } from './export/InMemoryMetricExporter';
export { ConsoleMetricExporter, } from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType, } from './InstrumentDescriptor';
export { MeterProvider, MeterProviderOptions, } from './MeterProvider';
export { DefaultAggregation, ExplicitBucketHistogramAggregation, DropAggregation, HistogramAggregation, LastValueAggregation, SumAggregation, Aggregation } from './view/Aggregation';
export { View, ViewOptions, } from './view/View';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
export * from './view/View';
//# sourceMappingURL=index.d.ts.map

@@ -16,17 +16,13 @@ /*

*/
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
export * from './export/MetricProducer';
export * from './export/MetricReader';
export * from './export/PeriodicExportingMetricReader';
export * from './export/InMemoryMetricExporter';
export * from './export/ConsoleMetricExporter';
export { InstrumentType } from './InstrumentDescriptor';
export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { AggregationTemporality, } from './export/AggregationTemporality';
export { DataPointType, } from './export/MetricData';
export { MetricReader } from './export/MetricReader';
export { PeriodicExportingMetricReader, } from './export/PeriodicExportingMetricReader';
export { InMemoryMetricExporter, } from './export/InMemoryMetricExporter';
export { ConsoleMetricExporter, } from './export/ConsoleMetricExporter';
export { InstrumentType, } from './InstrumentDescriptor';
export { MeterProvider, } from './MeterProvider';
export { DefaultAggregation, ExplicitBucketHistogramAggregation, DropAggregation, HistogramAggregation, LastValueAggregation, SumAggregation, Aggregation } from './view/Aggregation';
export { View, } from './view/View';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
export * from './view/View';
//# sourceMappingURL=index.js.map

@@ -42,3 +42,3 @@ /*

api.diag.warn('A shutdown MeterProvider cannot provide a Meter');
return metrics.NOOP_METER;
return metrics.createNoopMeter();
}

@@ -45,0 +45,0 @@ return this._sharedState

import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { Aggregation, InstrumentType } from '..';
import { ViewRegistry } from '../view/ViewRegistry';
import { MeterSharedState } from './MeterSharedState';
import { MetricCollector } from './MetricCollector';
import { MetricCollector, MetricCollectorHandle } from './MetricCollector';
/**

@@ -16,3 +17,4 @@ * An internal record for shared meter provider states.

getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
selectAggregations(instrumentType: InstrumentType): [MetricCollectorHandle, Aggregation][];
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

@@ -38,3 +38,10 @@ /*

}
selectAggregations(instrumentType) {
const result = [];
for (const collector of this.metricCollectors) {
result.push([collector, collector.selectAggregation(instrumentType)]);
}
return result;
}
}
//# sourceMappingURL=MeterProviderSharedState.js.map

@@ -7,8 +7,11 @@ import { HrTime } from '@opentelemetry/api';

import { Meter } from '../Meter';
import { Maybe } from '../utils';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MetricStorageRegistry } from './MetricStorageRegistry';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';
import { Accumulation } from '../aggregator/types';
/**

@@ -20,14 +23,16 @@ * An internal record for shared meter provider states.

private _instrumentationScope;
private _metricStorageRegistry;
metricStorageRegistry: MetricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationScope: InstrumentationScope);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>[];
registerMetricStorage(descriptor: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>> | MultiMetricStorage;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<Maybe<Accumulation>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
private _registerMetricStorage;
}

@@ -34,0 +39,0 @@ interface ScopeMetricsResult {

@@ -24,2 +24,3 @@ /*

import { SyncMetricStorage } from './SyncMetricStorage';
import { AttributesProcessor } from '../view/AttributesProcessor';
/**

@@ -32,3 +33,3 @@ * An internal record for shared meter provider states.

this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry();
this.metricStorageRegistry = new MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry();

@@ -38,11 +39,3 @@ this.meter = new Meter(this);

registerMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views
.map(view => {
const viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const storage = new SyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(storage);
})
.filter(isNotNullish);
const storages = this._registerMetricStorage(descriptor, SyncMetricStorage);
if (storages.length === 1) {

@@ -54,11 +47,3 @@ return storages[0];

registerAsyncMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views
.map(view => {
const viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(viewStorage);
})
.filter(isNotNullish);
const storages = this._registerMetricStorage(descriptor, AsyncMetricStorage);
return storages;

@@ -69,2 +54,3 @@ }

* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.

@@ -78,3 +64,3 @@ */

const errors = await this.observableRegistry.observe(collectionTime, options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this._metricStorageRegistry.getStorages())
const metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
.map(metricStorage => {

@@ -92,3 +78,34 @@ return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, collectionTime);

}
_registerMetricStorage(descriptor, MetricStorageType) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
let storages = views
.map(view => {
const viewDescriptor = createInstrumentDescriptorWithView(view, descriptor);
const compatibleStorage = this.metricStorageRegistry.findOrUpdateCompatibleStorage(viewDescriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
this.metricStorageRegistry.register(viewStorage);
return viewStorage;
});
// Fallback to the per-collector aggregations if no view is configured for the instrument.
if (storages.length === 0) {
const perCollectorAggregations = this._meterProviderSharedState.selectAggregations(descriptor.type);
const collectorStorages = perCollectorAggregations.map(([collector, aggregation]) => {
const compatibleStorage = this.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(collector, descriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
const aggregator = aggregation.createAggregator(descriptor);
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop());
this.metricStorageRegistry.registerForCollector(collector, storage);
return storage;
});
storages = storages.concat(collectorStorages);
}
return storages;
}
}
//# sourceMappingURL=MeterSharedState.js.map

@@ -1,2 +0,2 @@

import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { AggregationTemporalitySelector } from '../export/AggregationSelector';
import { CollectionResult } from '../export/MetricData';

@@ -26,3 +26,4 @@ import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';

shutdown(options?: ShutdownOptions): Promise<void>;
selectAggregationTemporality(instrumentType: InstrumentType): import("../export/AggregationTemporality").AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): import("..").AggregationTemporality;
selectAggregation(instrumentType: InstrumentType): import("..").Aggregation;
}

@@ -29,0 +30,0 @@ /**

@@ -56,3 +56,6 @@ /*

}
selectAggregation(instrumentType) {
return this._metricReader.selectAggregation(instrumentType);
}
}
//# sourceMappingURL=MetricCollector.js.map

@@ -21,5 +21,5 @@ import { HrTime } from '@opentelemetry/api';

abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;
getInstrumentDescriptor(): Readonly<InstrumentDescriptor>;
updateDescription(description: string): void;
}
//# sourceMappingURL=MetricStorage.d.ts.map
import { MetricStorage } from './MetricStorage';
import { Maybe } from '../utils';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { MetricCollectorHandle } from './MetricCollector';
/**

@@ -7,7 +8,13 @@ * Internal class for storing {@link MetricStorage}

export declare class MetricStorageRegistry {
private readonly _metricStorageRegistry;
private readonly _sharedRegistry;
private readonly _perCollectorRegistry;
static create(): MetricStorageRegistry;
getStorages(): MetricStorage[];
register<T extends MetricStorage>(storage: T): Maybe<T>;
getStorages(collector: MetricCollectorHandle): MetricStorage[];
register(storage: MetricStorage): void;
registerForCollector(collector: MetricCollectorHandle, storage: MetricStorage): void;
findOrUpdateCompatibleStorage<T extends MetricStorage>(expectedDescriptor: InstrumentDescriptor): T | null;
findOrUpdateCompatibleCollectorStorage<T extends MetricStorage>(collector: MetricCollectorHandle, expectedDescriptor: InstrumentDescriptor): T | null;
private _registerStorage;
private _findOrUpdateCompatibleStorage;
}
//# sourceMappingURL=MetricStorageRegistry.d.ts.map

@@ -24,3 +24,4 @@ /*

constructor() {
this._metricStorageRegistry = new Map();
this._sharedRegistry = new Map();
this._perCollectorRegistry = new Map();
}

@@ -30,17 +31,58 @@ static create() {

}
getStorages() {
getStorages(collector) {
let storages = [];
for (const metricStorages of this._metricStorageRegistry.values()) {
for (const metricStorages of this._sharedRegistry.values()) {
storages = storages.concat(metricStorages);
}
const perCollectorStorages = this._perCollectorRegistry.get(collector);
if (perCollectorStorages != null) {
for (const metricStorages of perCollectorStorages.values()) {
storages = storages.concat(metricStorages);
}
}
return storages;
}
register(storage) {
const expectedDescriptor = storage.getInstrumentDescriptor();
const existingStorages = this._metricStorageRegistry.get(expectedDescriptor.name);
// Add storage if it does not exist.
if (existingStorages === undefined) {
this._metricStorageRegistry.set(expectedDescriptor.name, [storage]);
return storage;
this._registerStorage(storage, this._sharedRegistry);
}
registerForCollector(collector, storage) {
let storageMap = this._perCollectorRegistry.get(collector);
if (storageMap == null) {
storageMap = new Map();
this._perCollectorRegistry.set(collector, storageMap);
}
this._registerStorage(storage, storageMap);
}
findOrUpdateCompatibleStorage(expectedDescriptor) {
const storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
}
findOrUpdateCompatibleCollectorStorage(collector, expectedDescriptor) {
const storageMap = this._perCollectorRegistry.get(collector);
if (storageMap === undefined) {
return null;
}
const storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
}
_registerStorage(storage, storageMap) {
const descriptor = storage.getInstrumentDescriptor();
const storages = storageMap.get(descriptor.name);
if (storages === undefined) {
storageMap.set(descriptor.name, [storage]);
return;
}
storages.push(storage);
}
_findOrUpdateCompatibleStorage(expectedDescriptor, existingStorages) {
let compatibleStorage = null;

@@ -66,10 +108,5 @@ for (const existingStorage of existingStorages) {

}
if (compatibleStorage != null) {
return compatibleStorage;
}
// None of the storages were compatible, add the current one to the list.
existingStorages.push(storage);
return storage;
return compatibleStorage;
}
}
//# sourceMappingURL=MetricStorageRegistry.js.map

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -24,4 +24,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -28,0 +26,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -21,3 +21,3 @@ /*

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -35,4 +35,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -39,0 +37,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -1,2 +0,2 @@

export declare const VERSION = "0.32.0";
export declare const VERSION = "0.33.0";
//# sourceMappingURL=version.d.ts.map

@@ -17,3 +17,3 @@ /*

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '0.32.0';
export const VERSION = '0.33.0';
//# sourceMappingURL=version.js.map

@@ -5,3 +5,3 @@ export interface Predicate {

/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -8,0 +8,0 @@ export declare class PatternPredicate implements Predicate {

@@ -18,6 +18,6 @@ /*

// escape ^ $ \ . + ? ( ) [ ] { } |
// do not need to escape * as we are interpret it as wildcard
// do not need to escape * as we interpret it as wildcard
const ESCAPE = /[\^$\\.+?()[\]{}|]/g;
/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -24,0 +24,0 @@ export class PatternPredicate {

@@ -5,3 +5,2 @@ import { InstrumentationScope } from '@opentelemetry/core';

export declare class ViewRegistry {
private static DEFAULT_VIEW;
private _registeredViews;

@@ -8,0 +7,0 @@ addView(view: View): void;

@@ -16,3 +16,2 @@ /*

*/
import { View } from './View';
export class ViewRegistry {

@@ -31,5 +30,2 @@ constructor() {

});
if (views.length === 0) {
return [ViewRegistry.DEFAULT_VIEW];
}
return views;

@@ -47,5 +43,2 @@ }

}
ViewRegistry.DEFAULT_VIEW = new View({
instrumentName: '*'
});
//# sourceMappingURL=ViewRegistry.js.map

@@ -87,2 +87,3 @@ import { HrTime } from '@opentelemetry/api';

* @param descriptor the metric instrument descriptor.
* @param aggregationTemporality the temporality of the resulting {@link MetricData}
* @param accumulationByAttributes the array of attributes and accumulation pairs.

@@ -89,0 +90,0 @@ * @param endTime the end time of the metric data.

@@ -15,3 +15,3 @@ import { MetricAttributes } from '@opentelemetry/api-metrics';

* @param attributes The complete set of MetricAttributes of the measurement
* @param context The Context of the measurement
* @param ctx The Context of the measurement
*/

@@ -18,0 +18,0 @@ shouldSample(value: number, timestamp: HrTime, attributes: MetricAttributes, ctx: Context): boolean;

@@ -1,2 +0,1 @@

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

@@ -9,3 +8,2 @@ * AggregationTemporality indicates the way additive quantities are expressed.

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*/
export interface BaseMetricData {
interface BaseMetricData {
readonly descriptor: InstrumentDescriptor;

@@ -121,2 +121,3 @@ readonly aggregationTemporality: AggregationTemporality;

}
export {};
//# sourceMappingURL=MetricData.d.ts.map

@@ -5,2 +5,3 @@ import { AggregationTemporality } from './AggregationTemporality';

import { InstrumentType } from '../InstrumentDescriptor';
import { Aggregation } from '../view/Aggregation';
/**

@@ -16,2 +17,3 @@ * An interface that allows different metric services to export recorded data

* @param metrics the metric data to be exported.
* @param resultCallback callback for when the export has completed
*/

@@ -28,4 +30,9 @@ export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;

*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality?(instrumentType: InstrumentType): AggregationTemporality;
/**
* Select the {@link Aggregation} for the given
* {@link InstrumentType} for this exporter.
*/
selectAggregation?(instrumentType: InstrumentType): Aggregation;
/**
* Returns a promise which resolves when the last exportation is completed.

@@ -32,0 +39,0 @@ * Further calls to {@link PushMetricExporter.export} may not export the

@@ -6,2 +6,17 @@ import { AggregationTemporality } from './AggregationTemporality';

import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';
import { Aggregation } from '../view/Aggregation';
import { AggregationSelector, AggregationTemporalitySelector } from './AggregationSelector';
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.
*/
aggregationSelector?: AggregationSelector;
/**
* Aggregation temporality selector based on metric instrument types. If
* not configured, cumulative is used for all instruments.
*/
aggregationTemporalitySelector?: AggregationTemporalitySelector;
}
/**

@@ -14,2 +29,5 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

private _metricProducer?;
private readonly _aggregationTemporalitySelector;
private readonly _aggregationSelector;
constructor(options?: MetricReaderOptions);
/**

@@ -22,6 +40,11 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
selectAggregation(instrumentType: InstrumentType): Aggregation;
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -28,0 +51,0 @@ * Handle once the SDK has initialized this {@link MetricReader}

@@ -21,2 +21,3 @@ "use strict";

const utils_1 = require("../utils");
const AggregationSelector_1 = require("./AggregationSelector");
/**

@@ -27,6 +28,9 @@ * A registered reader of metrics that, when linked to a {@link MetricProducer}, offers global

class MetricReader {
constructor() {
constructor(options) {
var _a, _b;
// Tracks the shutdown state.
// TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.
this._shutdown = false;
this._aggregationSelector = (_a = options === null || options === void 0 ? void 0 : options.aggregationSelector) !== null && _a !== void 0 ? _a : AggregationSelector_1.DEFAULT_AGGREGATION_SELECTOR;
this._aggregationTemporalitySelector = (_b = options === null || options === void 0 ? void 0 : options.aggregationTemporalitySelector) !== null && _b !== void 0 ? _b : AggregationSelector_1.DEFAULT_AGGREGATION_TEMPORALITY_SELECTOR;
}

@@ -46,2 +50,16 @@ /**

/**
* Select the {@link Aggregation} for the given {@link InstrumentType} for this
* reader.
*/
selectAggregation(instrumentType) {
return this._aggregationSelector(instrumentType);
}
/**
* Select the {@link AggregationTemporality} for the given
* {@link InstrumentType} for this reader.
*/
selectAggregationTemporality(instrumentType) {
return this._aggregationTemporalitySelector(instrumentType);
}
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -48,0 +66,0 @@ * Overriding this method is optional.

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';
export declare type PeriodicExportingMetricReaderOptions = {
/**
* The backing exporter for the metric reader.
*/
exporter: PushMetricExporter;
/**
* An internal milliseconds for the metric reader to initiate metric
* collection.
*/
exportIntervalMillis?: number;
/**
* Milliseconds for the async observable callback to timeout.
*/
exportTimeoutMillis?: number;

@@ -12,3 +20,3 @@ };

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/

@@ -25,7 +33,3 @@ export declare class PeriodicExportingMetricReader extends MetricReader {

protected onShutdown(): Promise<void>;
/**
* @inheritdoc
*/
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
}
//# sourceMappingURL=PeriodicExportingMetricReader.d.ts.map

@@ -25,8 +25,11 @@ "use strict";

* {@link MetricReader} which collects metrics based on a user-configurable time interval, and passes the metrics to
* the configured {@link MetricExporter}
* the configured {@link PushMetricExporter}
*/
class PeriodicExportingMetricReader extends MetricReader_1.MetricReader {
constructor(options) {
var _a, _b;
super();
var _a, _b, _c, _d;
super({
aggregationSelector: (_a = options.exporter.selectAggregation) === null || _a === void 0 ? void 0 : _a.bind(options.exporter),
aggregationTemporalitySelector: (_b = options.exporter.selectAggregationTemporality) === null || _b === void 0 ? void 0 : _b.bind(options.exporter)
});
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -43,4 +46,4 @@ throw Error('exportIntervalMillis must be greater than 0');

}
this._exportInterval = (_a = options.exportIntervalMillis) !== null && _a !== void 0 ? _a : 60000;
this._exportTimeout = (_b = options.exportTimeoutMillis) !== null && _b !== void 0 ? _b : 30000;
this._exportInterval = (_c = options.exportIntervalMillis) !== null && _c !== void 0 ? _c : 60000;
this._exportTimeout = (_d = options.exportTimeoutMillis) !== null && _d !== void 0 ? _d : 30000;
this._exporter = options.exporter;

@@ -90,10 +93,4 @@ }

}
/**
* @inheritdoc
*/
selectAggregationTemporality(instrumentType) {
return this._exporter.selectAggregationTemporality(instrumentType);
}
}
exports.PeriodicExportingMetricReader = PeriodicExportingMetricReader;
//# sourceMappingURL=PeriodicExportingMetricReader.js.map

@@ -1,17 +0,15 @@

export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
export * from './export/MetricProducer';
export * from './export/MetricReader';
export * from './export/PeriodicExportingMetricReader';
export * from './export/InMemoryMetricExporter';
export * from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { Sum, LastValue, Histogram, } from './aggregator/types';
export { AggregationSelector, AggregationTemporalitySelector, } from './export/AggregationSelector';
export { AggregationTemporality, } from './export/AggregationTemporality';
export { DataPoint, DataPointType, SumMetricData, GaugeMetricData, HistogramMetricData, ResourceMetrics, ScopeMetrics, MetricData, CollectionResult, } from './export/MetricData';
export { PushMetricExporter, } from './export/MetricExporter';
export { MetricReader, MetricReaderOptions } from './export/MetricReader';
export { PeriodicExportingMetricReader, PeriodicExportingMetricReaderOptions, } from './export/PeriodicExportingMetricReader';
export { InMemoryMetricExporter, } from './export/InMemoryMetricExporter';
export { ConsoleMetricExporter, } from './export/ConsoleMetricExporter';
export { InstrumentDescriptor, InstrumentType, } from './InstrumentDescriptor';
export { MeterProvider, MeterProviderOptions, } from './MeterProvider';
export { DefaultAggregation, ExplicitBucketHistogramAggregation, DropAggregation, HistogramAggregation, LastValueAggregation, SumAggregation, Aggregation } from './view/Aggregation';
export { View, ViewOptions, } from './view/View';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
export * from './view/View';
//# sourceMappingURL=index.d.ts.map

@@ -17,31 +17,32 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutError = exports.InstrumentType = void 0;
__exportStar(require("./export/AggregationTemporality"), exports);
__exportStar(require("./export/MetricData"), exports);
__exportStar(require("./export/MetricExporter"), exports);
__exportStar(require("./export/MetricProducer"), exports);
__exportStar(require("./export/MetricReader"), exports);
__exportStar(require("./export/PeriodicExportingMetricReader"), exports);
__exportStar(require("./export/InMemoryMetricExporter"), exports);
__exportStar(require("./export/ConsoleMetricExporter"), exports);
exports.TimeoutError = exports.View = exports.Aggregation = exports.SumAggregation = exports.LastValueAggregation = exports.HistogramAggregation = exports.DropAggregation = exports.ExplicitBucketHistogramAggregation = exports.DefaultAggregation = exports.MeterProvider = exports.InstrumentType = exports.ConsoleMetricExporter = exports.InMemoryMetricExporter = exports.PeriodicExportingMetricReader = exports.MetricReader = exports.DataPointType = exports.AggregationTemporality = void 0;
var AggregationTemporality_1 = require("./export/AggregationTemporality");
Object.defineProperty(exports, "AggregationTemporality", { enumerable: true, get: function () { return AggregationTemporality_1.AggregationTemporality; } });
var MetricData_1 = require("./export/MetricData");
Object.defineProperty(exports, "DataPointType", { enumerable: true, get: function () { return MetricData_1.DataPointType; } });
var MetricReader_1 = require("./export/MetricReader");
Object.defineProperty(exports, "MetricReader", { enumerable: true, get: function () { return MetricReader_1.MetricReader; } });
var PeriodicExportingMetricReader_1 = require("./export/PeriodicExportingMetricReader");
Object.defineProperty(exports, "PeriodicExportingMetricReader", { enumerable: true, get: function () { return PeriodicExportingMetricReader_1.PeriodicExportingMetricReader; } });
var InMemoryMetricExporter_1 = require("./export/InMemoryMetricExporter");
Object.defineProperty(exports, "InMemoryMetricExporter", { enumerable: true, get: function () { return InMemoryMetricExporter_1.InMemoryMetricExporter; } });
var ConsoleMetricExporter_1 = require("./export/ConsoleMetricExporter");
Object.defineProperty(exports, "ConsoleMetricExporter", { enumerable: true, get: function () { return ConsoleMetricExporter_1.ConsoleMetricExporter; } });
var InstrumentDescriptor_1 = require("./InstrumentDescriptor");
Object.defineProperty(exports, "InstrumentType", { enumerable: true, get: function () { return InstrumentDescriptor_1.InstrumentType; } });
__exportStar(require("./Meter"), exports);
__exportStar(require("./MeterProvider"), exports);
__exportStar(require("./ObservableResult"), exports);
var MeterProvider_1 = require("./MeterProvider");
Object.defineProperty(exports, "MeterProvider", { enumerable: true, get: function () { return MeterProvider_1.MeterProvider; } });
var Aggregation_1 = require("./view/Aggregation");
Object.defineProperty(exports, "DefaultAggregation", { enumerable: true, get: function () { return Aggregation_1.DefaultAggregation; } });
Object.defineProperty(exports, "ExplicitBucketHistogramAggregation", { enumerable: true, get: function () { return Aggregation_1.ExplicitBucketHistogramAggregation; } });
Object.defineProperty(exports, "DropAggregation", { enumerable: true, get: function () { return Aggregation_1.DropAggregation; } });
Object.defineProperty(exports, "HistogramAggregation", { enumerable: true, get: function () { return Aggregation_1.HistogramAggregation; } });
Object.defineProperty(exports, "LastValueAggregation", { enumerable: true, get: function () { return Aggregation_1.LastValueAggregation; } });
Object.defineProperty(exports, "SumAggregation", { enumerable: true, get: function () { return Aggregation_1.SumAggregation; } });
Object.defineProperty(exports, "Aggregation", { enumerable: true, get: function () { return Aggregation_1.Aggregation; } });
var View_1 = require("./view/View");
Object.defineProperty(exports, "View", { enumerable: true, get: function () { return View_1.View; } });
var utils_1 = require("./utils");
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return utils_1.TimeoutError; } });
__exportStar(require("./view/Aggregation"), exports);
__exportStar(require("./view/View"), exports);
//# sourceMappingURL=index.js.map

@@ -45,3 +45,3 @@ "use strict";

api.diag.warn('A shutdown MeterProvider cannot provide a Meter');
return metrics.NOOP_METER;
return metrics.createNoopMeter();
}

@@ -48,0 +48,0 @@ return this._sharedState

import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { Aggregation, InstrumentType } from '..';
import { ViewRegistry } from '../view/ViewRegistry';
import { MeterSharedState } from './MeterSharedState';
import { MetricCollector } from './MetricCollector';
import { MetricCollector, MetricCollectorHandle } from './MetricCollector';
/**

@@ -16,3 +17,4 @@ * An internal record for shared meter provider states.

getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
selectAggregations(instrumentType: InstrumentType): [MetricCollectorHandle, Aggregation][];
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

@@ -41,4 +41,11 @@ "use strict";

}
selectAggregations(instrumentType) {
const result = [];
for (const collector of this.metricCollectors) {
result.push([collector, collector.selectAggregation(instrumentType)]);
}
return result;
}
}
exports.MeterProviderSharedState = MeterProviderSharedState;
//# sourceMappingURL=MeterProviderSharedState.js.map

@@ -7,8 +7,11 @@ import { HrTime } from '@opentelemetry/api';

import { Meter } from '../Meter';
import { Maybe } from '../utils';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MetricStorageRegistry } from './MetricStorageRegistry';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';
import { Accumulation } from '../aggregator/types';
/**

@@ -20,14 +23,16 @@ * An internal record for shared meter provider states.

private _instrumentationScope;
private _metricStorageRegistry;
metricStorageRegistry: MetricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationScope: InstrumentationScope);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<import("../utils").Maybe<import("../aggregator/types").Accumulation>>[];
registerMetricStorage(descriptor: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>> | MultiMetricStorage;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor): AsyncMetricStorage<Maybe<Accumulation>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
private _registerMetricStorage;
}

@@ -34,0 +39,0 @@ interface ScopeMetricsResult {

@@ -27,2 +27,3 @@ "use strict";

const SyncMetricStorage_1 = require("./SyncMetricStorage");
const AttributesProcessor_1 = require("../view/AttributesProcessor");
/**

@@ -35,3 +36,3 @@ * An internal record for shared meter provider states.

this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry_1.MetricStorageRegistry();
this.metricStorageRegistry = new MetricStorageRegistry_1.MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry_1.ObservableRegistry();

@@ -41,11 +42,3 @@ this.meter = new Meter_1.Meter(this);

registerMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views
.map(view => {
const viewDescriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptorWithView)(view, descriptor);
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const storage = new SyncMetricStorage_1.SyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(storage);
})
.filter(utils_1.isNotNullish);
const storages = this._registerMetricStorage(descriptor, SyncMetricStorage_1.SyncMetricStorage);
if (storages.length === 1) {

@@ -57,11 +50,3 @@ return storages[0];

registerAsyncMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views
.map(view => {
const viewDescriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptorWithView)(view, descriptor);
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new AsyncMetricStorage_1.AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(viewStorage);
})
.filter(utils_1.isNotNullish);
const storages = this._registerMetricStorage(descriptor, AsyncMetricStorage_1.AsyncMetricStorage);
return storages;

@@ -72,2 +57,3 @@ }

* @param collectionTime the HrTime at which the collection was initiated.
* @param options options for collection.
* @returns the list of metric data collected.

@@ -81,3 +67,3 @@ */

const errors = await this.observableRegistry.observe(collectionTime, options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this._metricStorageRegistry.getStorages())
const metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
.map(metricStorage => {

@@ -95,4 +81,35 @@ return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, collectionTime);

}
_registerMetricStorage(descriptor, MetricStorageType) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
let storages = views
.map(view => {
const viewDescriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptorWithView)(view, descriptor);
const compatibleStorage = this.metricStorageRegistry.findOrUpdateCompatibleStorage(viewDescriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
this.metricStorageRegistry.register(viewStorage);
return viewStorage;
});
// Fallback to the per-collector aggregations if no view is configured for the instrument.
if (storages.length === 0) {
const perCollectorAggregations = this._meterProviderSharedState.selectAggregations(descriptor.type);
const collectorStorages = perCollectorAggregations.map(([collector, aggregation]) => {
const compatibleStorage = this.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(collector, descriptor);
if (compatibleStorage != null) {
return compatibleStorage;
}
const aggregator = aggregation.createAggregator(descriptor);
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor_1.AttributesProcessor.Noop());
this.metricStorageRegistry.registerForCollector(collector, storage);
return storage;
});
storages = storages.concat(collectorStorages);
}
return storages;
}
}
exports.MeterSharedState = MeterSharedState;
//# sourceMappingURL=MeterSharedState.js.map

@@ -1,2 +0,2 @@

import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { AggregationTemporalitySelector } from '../export/AggregationSelector';
import { CollectionResult } from '../export/MetricData';

@@ -26,3 +26,4 @@ import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';

shutdown(options?: ShutdownOptions): Promise<void>;
selectAggregationTemporality(instrumentType: InstrumentType): import("../export/AggregationTemporality").AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): import("..").AggregationTemporality;
selectAggregation(instrumentType: InstrumentType): import("..").Aggregation;
}

@@ -29,0 +30,0 @@ /**

@@ -59,4 +59,7 @@ "use strict";

}
selectAggregation(instrumentType) {
return this._metricReader.selectAggregation(instrumentType);
}
}
exports.MetricCollector = MetricCollector;
//# sourceMappingURL=MetricCollector.js.map

@@ -21,5 +21,5 @@ import { HrTime } from '@opentelemetry/api';

abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;
getInstrumentDescriptor(): Readonly<InstrumentDescriptor>;
updateDescription(description: string): void;
}
//# sourceMappingURL=MetricStorage.d.ts.map
import { MetricStorage } from './MetricStorage';
import { Maybe } from '../utils';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { MetricCollectorHandle } from './MetricCollector';
/**

@@ -7,7 +8,13 @@ * Internal class for storing {@link MetricStorage}

export declare class MetricStorageRegistry {
private readonly _metricStorageRegistry;
private readonly _sharedRegistry;
private readonly _perCollectorRegistry;
static create(): MetricStorageRegistry;
getStorages(): MetricStorage[];
register<T extends MetricStorage>(storage: T): Maybe<T>;
getStorages(collector: MetricCollectorHandle): MetricStorage[];
register(storage: MetricStorage): void;
registerForCollector(collector: MetricCollectorHandle, storage: MetricStorage): void;
findOrUpdateCompatibleStorage<T extends MetricStorage>(expectedDescriptor: InstrumentDescriptor): T | null;
findOrUpdateCompatibleCollectorStorage<T extends MetricStorage>(collector: MetricCollectorHandle, expectedDescriptor: InstrumentDescriptor): T | null;
private _registerStorage;
private _findOrUpdateCompatibleStorage;
}
//# sourceMappingURL=MetricStorageRegistry.d.ts.map

@@ -27,3 +27,4 @@ "use strict";

constructor() {
this._metricStorageRegistry = new Map();
this._sharedRegistry = new Map();
this._perCollectorRegistry = new Map();
}

@@ -33,17 +34,58 @@ static create() {

}
getStorages() {
getStorages(collector) {
let storages = [];
for (const metricStorages of this._metricStorageRegistry.values()) {
for (const metricStorages of this._sharedRegistry.values()) {
storages = storages.concat(metricStorages);
}
const perCollectorStorages = this._perCollectorRegistry.get(collector);
if (perCollectorStorages != null) {
for (const metricStorages of perCollectorStorages.values()) {
storages = storages.concat(metricStorages);
}
}
return storages;
}
register(storage) {
const expectedDescriptor = storage.getInstrumentDescriptor();
const existingStorages = this._metricStorageRegistry.get(expectedDescriptor.name);
// Add storage if it does not exist.
if (existingStorages === undefined) {
this._metricStorageRegistry.set(expectedDescriptor.name, [storage]);
return storage;
this._registerStorage(storage, this._sharedRegistry);
}
registerForCollector(collector, storage) {
let storageMap = this._perCollectorRegistry.get(collector);
if (storageMap == null) {
storageMap = new Map();
this._perCollectorRegistry.set(collector, storageMap);
}
this._registerStorage(storage, storageMap);
}
findOrUpdateCompatibleStorage(expectedDescriptor) {
const storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
}
findOrUpdateCompatibleCollectorStorage(collector, expectedDescriptor) {
const storageMap = this._perCollectorRegistry.get(collector);
if (storageMap === undefined) {
return null;
}
const storages = this._sharedRegistry.get(expectedDescriptor.name);
if (storages === undefined) {
return null;
}
// If the descriptor is compatible, the type of their metric storage
// (either SyncMetricStorage or AsyncMetricStorage) must be compatible.
return this._findOrUpdateCompatibleStorage(expectedDescriptor, storages);
}
_registerStorage(storage, storageMap) {
const descriptor = storage.getInstrumentDescriptor();
const storages = storageMap.get(descriptor.name);
if (storages === undefined) {
storageMap.set(descriptor.name, [storage]);
return;
}
storages.push(storage);
}
_findOrUpdateCompatibleStorage(expectedDescriptor, existingStorages) {
let compatibleStorage = null;

@@ -69,8 +111,3 @@ for (const existingStorage of existingStorages) {

}
if (compatibleStorage != null) {
return compatibleStorage;
}
// None of the storages were compatible, add the current one to the list.
existingStorages.push(storage);
return storage;
return compatibleStorage;
}

@@ -77,0 +114,0 @@ }

@@ -11,3 +11,3 @@ import { HrTime } from '@opentelemetry/api';

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -24,4 +24,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -28,0 +26,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -24,3 +24,3 @@ "use strict";

*
* Provides unique reporting for each collectors. Allows synchronous collection
* Provides unique reporting for each collector. Allows synchronous collection
* of metrics and reports given temporality values.

@@ -38,4 +38,2 @@ */

* @param collectors The registered collectors.
* @param resource The resource to attach these metrics against.
* @param instrumentationScope The instrumentation scope that generated these metrics.
* @param instrumentDescriptor The instrumentation descriptor that these metrics generated with.

@@ -42,0 +40,0 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

@@ -1,2 +0,2 @@

export declare const VERSION = "0.32.0";
export declare const VERSION = "0.33.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.32.0';
exports.VERSION = '0.33.0';
//# sourceMappingURL=version.js.map

@@ -5,3 +5,3 @@ export interface Predicate {

/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -8,0 +8,0 @@ export declare class PatternPredicate implements Predicate {

@@ -21,6 +21,6 @@ "use strict";

// escape ^ $ \ . + ? ( ) [ ] { } |
// do not need to escape * as we are interpret it as wildcard
// do not need to escape * as we interpret it as wildcard
const ESCAPE = /[\^$\\.+?()[\]{}|]/g;
/**
* Wildcard pattern predicate, support patterns like `*`, `foo*`, `*bar`.
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/

@@ -27,0 +27,0 @@ class PatternPredicate {

@@ -5,3 +5,2 @@ import { InstrumentationScope } from '@opentelemetry/core';

export declare class ViewRegistry {
private static DEFAULT_VIEW;
private _registeredViews;

@@ -8,0 +7,0 @@ addView(view: View): void;

@@ -19,3 +19,2 @@ "use strict";

exports.ViewRegistry = void 0;
const View_1 = require("./View");
class ViewRegistry {

@@ -34,5 +33,2 @@ constructor() {

});
if (views.length === 0) {
return [ViewRegistry.DEFAULT_VIEW];
}
return views;

@@ -51,5 +47,2 @@ }

exports.ViewRegistry = ViewRegistry;
ViewRegistry.DEFAULT_VIEW = new View_1.View({
instrumentName: '*'
});
//# sourceMappingURL=ViewRegistry.js.map
{
"name": "@opentelemetry/sdk-metrics",
"version": "0.32.0",
"version": "0.33.0",
"description": "Work in progress OpenTelemetry metrics SDK",

@@ -80,9 +80,9 @@ "main": "build/src/index.js",

"dependencies": {
"@opentelemetry/api-metrics": "0.32.0",
"@opentelemetry/core": "1.6.0",
"@opentelemetry/resources": "1.6.0",
"@opentelemetry/api-metrics": "0.33.0",
"@opentelemetry/core": "1.7.0",
"@opentelemetry/resources": "1.7.0",
"lodash.merge": "4.6.2"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-sdk-metrics",
"gitHead": "a5abee69119cc41d9d34f6beb5c1826eef1ac0dd"
"gitHead": "ad88c3d9aa0100fe259b93f4b660e84417b757ac"
}

@@ -6,2 +6,4 @@ # OpenTelemetry Metrics SDK

**Note: This is an experimental package under active development. New releases may include breaking changes.**
OpenTelemetry metrics module contains the foundation for all metrics SDKs of [opentelemetry-js](https://github.com/open-telemetry/opentelemetry-js).

@@ -8,0 +10,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc