Socket
Socket
Sign inDemoInstall

@opentelemetry/sdk-metrics-base

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/sdk-metrics-base - npm Package Compare versions

Comparing version 0.28.0 to 0.29.0

build/esm/state/ObservableRegistry.d.ts

3

build/esm/aggregator/Drop.d.ts
import { HrTime } from '@opentelemetry/api';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -12,4 +13,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

diff(_previous: undefined, _current: undefined): undefined;
toMetricData(_descriptor: InstrumentDescriptor, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
toMetricData(_descriptor: InstrumentDescriptor, _aggregationTemporality: AggregationTemporality, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=Drop.d.ts.map

@@ -31,3 +31,3 @@ /*

};
DropAggregator.prototype.toMetricData = function (_descriptor, _accumulationByAttributes, _startTime, _endTime) {
DropAggregator.prototype.toMetricData = function (_descriptor, _aggregationTemporality, _accumulationByAttributes, _startTime, _endTime) {
return undefined;

@@ -34,0 +34,0 @@ };

@@ -6,2 +6,3 @@ import { Accumulation, AccumulationRecord, Aggregator, AggregatorKind, Histogram } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class HistogramAccumulation implements Accumulation {

@@ -36,4 +37,4 @@ private readonly _boundaries;

diff(previous: HistogramAccumulation, current: HistogramAccumulation): HistogramAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
}
//# sourceMappingURL=Histogram.d.ts.map

@@ -129,5 +129,6 @@ /*

};
HistogramAggregator.prototype.toMetricData = function (descriptor, accumulationByAttributes, startTime, endTime) {
HistogramAggregator.prototype.toMetricData = function (descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor: descriptor,
aggregationTemporality: aggregationTemporality,
dataPointType: DataPointType.HISTOGRAM,

@@ -134,0 +135,0 @@ dataPoints: accumulationByAttributes.map(function (_a) {

@@ -6,2 +6,3 @@ import { LastValue, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class LastValueAccumulation implements Accumulation {

@@ -31,4 +32,4 @@ private _current;

diff(previous: LastValueAccumulation, current: LastValueAccumulation): LastValueAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=LastValue.d.ts.map

@@ -81,5 +81,6 @@ /*

};
LastValueAggregator.prototype.toMetricData = function (descriptor, accumulationByAttributes, startTime, endTime) {
LastValueAggregator.prototype.toMetricData = function (descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor: descriptor,
aggregationTemporality: aggregationTemporality,
dataPointType: DataPointType.SINGULAR,

@@ -86,0 +87,0 @@ dataPoints: accumulationByAttributes.map(function (_a) {

@@ -6,2 +6,3 @@ import { Sum, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class SumAccumulation implements Accumulation {

@@ -25,4 +26,4 @@ private _current;

diff(previous: SumAccumulation, current: SumAccumulation): SumAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=Sum.d.ts.map

@@ -68,5 +68,6 @@ /*

};
SumAggregator.prototype.toMetricData = function (descriptor, accumulationByAttributes, startTime, endTime) {
SumAggregator.prototype.toMetricData = function (descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor: descriptor,
aggregationTemporality: aggregationTemporality,
dataPointType: DataPointType.SINGULAR,

@@ -73,0 +74,0 @@ dataPoints: accumulationByAttributes.map(function (_a) {

import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -88,4 +89,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

*/
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=types.d.ts.map

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

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

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

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map
import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Histogram } from '../aggregator/types';
import { AggregationTemporality } from './AggregationTemporality';
/**

@@ -12,2 +13,3 @@ * Basic metric data fields.

readonly descriptor: InstrumentDescriptor;
readonly aggregationTemporality: AggregationTemporality;
/**

@@ -37,4 +39,4 @@ * DataPointType of the metric instrument.

export declare type MetricData = SingularMetricData | HistogramMetricData;
export interface InstrumentationLibraryMetrics {
instrumentationLibrary: InstrumentationLibrary;
export interface ScopeMetrics {
scope: InstrumentationScope;
metrics: MetricData[];

@@ -44,4 +46,8 @@ }

resource: Resource;
instrumentationLibraryMetrics: InstrumentationLibraryMetrics[];
scopeMetrics: ScopeMetrics[];
}
export interface CollectionResult {
resourceMetrics: ResourceMetrics;
errors: unknown[];
}
/**

@@ -48,0 +54,0 @@ * The aggregated point data type.

import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { ExportResult } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
export interface PushMetricExporter {
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
forceFlush(): Promise<void>;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
shutdown(): Promise<void>;

@@ -12,4 +13,6 @@ }

protected _shutdown: boolean;
private _aggregationTemporality;
constructor(aggregationTemporality?: AggregationTemporality);
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality;
forceFlush(): Promise<void>;

@@ -16,0 +19,0 @@ shutdown(): Promise<void>;

@@ -55,4 +55,5 @@ /*

var ConsoleMetricExporter = /** @class */ (function () {
function ConsoleMetricExporter() {
function ConsoleMetricExporter(aggregationTemporality) {
this._shutdown = true;
this._aggregationTemporality = aggregationTemporality !== null && aggregationTemporality !== void 0 ? aggregationTemporality : AggregationTemporality.CUMULATIVE;
}

@@ -65,4 +66,4 @@ ConsoleMetricExporter.prototype.export = function (metrics, resultCallback) {

};
ConsoleMetricExporter.prototype.getPreferredAggregationTemporality = function () {
return AggregationTemporality.CUMULATIVE;
ConsoleMetricExporter.prototype.selectAggregationTemporality = function (_instrumentType) {
return this._aggregationTemporality;
};

@@ -69,0 +70,0 @@ // nothing to do

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

import { ResourceMetrics } from './MetricData';
import { CollectionResult } from './MetricData';
export interface MetricCollectOptions {
timeoutMillis?: number;
}
/**

@@ -6,4 +9,4 @@ * This is a public interface that represent an export state of a MetricReader.

export interface MetricProducer {
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
}
//# sourceMappingURL=MetricProducer.d.ts.map
import { AggregationTemporality } from './AggregationTemporality';
import { MetricProducer } from './MetricProducer';
import { ResourceMetrics } from './MetricData';
import { Maybe } from '../utils';
import { CollectionResult } from './MetricData';
import { InstrumentType } from '../InstrumentDescriptor';
import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';

@@ -11,6 +11,4 @@ /**

export declare abstract class MetricReader {
private readonly _preferredAggregationTemporality;
private _shutdown;
private _metricProducer?;
constructor(_preferredAggregationTemporality?: AggregationTemporality);
/**

@@ -23,5 +21,5 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
* Get the default {@link AggregationTemporality} for the given {@link InstrumentType}
*/
getPreferredAggregationTemporality(): AggregationTemporality;
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -50,3 +48,3 @@ * Handle once the SDK has initialized this {@link MetricReader}

*/
collect(options?: CollectionOptions): Promise<Maybe<ResourceMetrics>>;
collect(options?: CollectionOptions): Promise<CollectionResult>;
/**

@@ -53,0 +51,0 @@ * Shuts down the metric reader, the promise will reject after the optional timeout or resolve after completion.

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

import * as api from '@opentelemetry/api';
import { AggregationTemporality } from './AggregationTemporality';
import { callWithTimeout } from '../utils';

@@ -62,5 +61,3 @@ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#metricreader

var MetricReader = /** @class */ (function () {
function MetricReader(_preferredAggregationTemporality) {
if (_preferredAggregationTemporality === void 0) { _preferredAggregationTemporality = AggregationTemporality.CUMULATIVE; }
this._preferredAggregationTemporality = _preferredAggregationTemporality;
function MetricReader() {
// Tracks the shutdown state.

@@ -83,8 +80,2 @@ // TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
*/
MetricReader.prototype.getPreferredAggregationTemporality = function () {
return this._preferredAggregationTemporality;
};
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -102,18 +93,12 @@ * Overriding this method is optional.

return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this._metricProducer === undefined) {
throw new Error('MetricReader is not bound to a MetricProducer');
}
// Subsequent invocations to collect are not allowed. SDKs SHOULD return some failure for these calls.
if (this._shutdown) {
api.diag.warn('Collection is not allowed after shutdown');
return [2 /*return*/, undefined];
}
if (!((options === null || options === void 0 ? void 0 : options.timeoutMillis) == null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._metricProducer.collect()];
case 1: return [2 /*return*/, _a.sent()];
case 2: return [4 /*yield*/, callWithTimeout(this._metricProducer.collect(), options.timeoutMillis)];
case 3: return [2 /*return*/, _a.sent()];
if (this._metricProducer === undefined) {
throw new Error('MetricReader is not bound to a MetricProducer');
}
// Subsequent invocations to collect are not allowed. SDKs SHOULD return some failure for these calls.
if (this._shutdown) {
throw new Error('MetricReader is shutdown');
}
return [2 /*return*/, this._metricProducer.collect({
timeoutMillis: options === null || options === void 0 ? void 0 : options.timeoutMillis,
})];
});

@@ -120,0 +105,0 @@ });

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';

@@ -22,3 +24,4 @@ export declare type PeriodicExportingMetricReaderOptions = {

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

@@ -67,2 +67,27 @@ /*

};
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;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import * as api from '@opentelemetry/api';

@@ -80,3 +105,3 @@ import { ExportResultCode, globalErrorHandler } from '@opentelemetry/core';

var _a, _b;
var _this = _super.call(this, options.exporter.getPreferredAggregationTemporality()) || this;
var _this = _super.call(this) || this;
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -100,14 +125,15 @@ throw Error('exportIntervalMillis must be greater than 0');

return __awaiter(this, void 0, void 0, function () {
var metrics;
var _a, resourceMetrics, errors;
var _b;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this.collect({})];
case 1:
metrics = _a.sent();
if (metrics === undefined) {
return [2 /*return*/];
_a = _c.sent(), resourceMetrics = _a.resourceMetrics, errors = _a.errors;
if (errors.length > 0) {
(_b = api.diag).error.apply(_b, __spreadArray(['PeriodicExportingMetricReader: metrics collection errors'], __read(errors), false));
}
return [2 /*return*/, new Promise(function (resolve, reject) {
_this._exporter.export(metrics, function (result) {
_this._exporter.export(resourceMetrics, function (result) {
var _a;

@@ -180,2 +206,5 @@ if (result.code !== ExportResultCode.SUCCESS) {

};
PeriodicExportingMetricReader.prototype.selectAggregationTemporality = function (instrumentType) {
return this._exporter.selectAggregationTemporality(instrumentType);
};
return PeriodicExportingMetricReader;

@@ -182,0 +211,0 @@ }(MetricReader));

@@ -1,5 +0,4 @@

export { Histogram } from './aggregator/types';
export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export { MeterProvider, MeterProviderOptions } from './MeterProvider';
export * from './export/MetricExporter';

@@ -15,4 +14,2 @@ export * from './export/MetricProducer';

export * from './view/Aggregation';
export { FilteringAttributesProcessor } from './view/AttributesProcessor';
export * from './aggregator/types';
//# sourceMappingURL=index.d.ts.map

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

export * from './export/MetricData';
export { MeterProvider } from './MeterProvider';
export * from './export/MetricExporter';

@@ -30,4 +29,2 @@ export * from './export/MetricProducer';

export * from './view/Aggregation';
export { FilteringAttributesProcessor } from './view/AttributesProcessor';
export * from './aggregator/types';
//# sourceMappingURL=index.js.map

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

description: (_a = options === null || options === void 0 ? void 0 : options.description) !== null && _a !== void 0 ? _a : '',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '1',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '',
valueType: (_c = options === null || options === void 0 ? void 0 : options.valueType) !== null && _c !== void 0 ? _c : ValueType.DOUBLE,

@@ -38,0 +38,0 @@ };

import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { InstrumentDescriptor } from './InstrumentDescriptor';
import { WritableMetricStorage } from './state/WritableMetricStorage';
import { ObservableRegistry } from './state/ObservableRegistry';
import { AsyncWritableMetricStorage, WritableMetricStorage } from './state/WritableMetricStorage';
export declare class SyncInstrument {
private _writableMetricStorage;
private _descriptor;
protected _descriptor: InstrumentDescriptor;
constructor(_writableMetricStorage: WritableMetricStorage, _descriptor: InstrumentDescriptor);
getName(): string;
protected _record(value: number, attributes?: metrics.MetricAttributes, context?: api.Context): void;

@@ -39,2 +40,25 @@ }

}
export declare class ObservableInstrument implements metrics.Observable {
private _observableRegistry;
/** @internal */
_metricStorages: AsyncWritableMetricStorage[];
/** @internal */
_descriptor: InstrumentDescriptor;
constructor(descriptor: InstrumentDescriptor, metricStorages: AsyncWritableMetricStorage[], _observableRegistry: ObservableRegistry);
/**
* @see {metrics.Observable.addCallback}
*/
addCallback(callback: ObservableCallback): void;
/**
* @see {metrics.Observable.removeCallback}
*/
removeCallback(callback: ObservableCallback): void;
}
export declare class ObservableCounterInstrument extends ObservableInstrument implements metrics.ObservableCounter {
}
export declare class ObservableGaugeInstrument extends ObservableInstrument implements metrics.ObservableGauge {
}
export declare class ObservableUpDownCounterInstrument extends ObservableInstrument implements metrics.ObservableUpDownCounter {
}
export declare function isObservableInstrument(it: unknown): it is ObservableInstrument;
//# sourceMappingURL=Instruments.d.ts.map

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

}
SyncInstrument.prototype.getName = function () {
return this._descriptor.name;
};
SyncInstrument.prototype._record = function (value, attributes, context) {

@@ -84,3 +81,3 @@ if (attributes === void 0) { attributes = {}; }

if (value < 0) {
api.diag.warn("negative value provided to counter " + this.getName() + ": " + value);
api.diag.warn("negative value provided to counter " + this._descriptor.name + ": " + value);
return;

@@ -110,2 +107,50 @@ }

export { HistogramInstrument };
var ObservableInstrument = /** @class */ (function () {
function ObservableInstrument(descriptor, metricStorages, _observableRegistry) {
this._observableRegistry = _observableRegistry;
this._descriptor = descriptor;
this._metricStorages = metricStorages;
}
/**
* @see {metrics.Observable.addCallback}
*/
ObservableInstrument.prototype.addCallback = function (callback) {
this._observableRegistry.addCallback(callback, this);
};
/**
* @see {metrics.Observable.removeCallback}
*/
ObservableInstrument.prototype.removeCallback = function (callback) {
this._observableRegistry.removeCallback(callback, this);
};
return ObservableInstrument;
}());
export { ObservableInstrument };
var ObservableCounterInstrument = /** @class */ (function (_super) {
__extends(ObservableCounterInstrument, _super);
function ObservableCounterInstrument() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ObservableCounterInstrument;
}(ObservableInstrument));
export { ObservableCounterInstrument };
var ObservableGaugeInstrument = /** @class */ (function (_super) {
__extends(ObservableGaugeInstrument, _super);
function ObservableGaugeInstrument() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ObservableGaugeInstrument;
}(ObservableInstrument));
export { ObservableGaugeInstrument };
var ObservableUpDownCounterInstrument = /** @class */ (function (_super) {
__extends(ObservableUpDownCounterInstrument, _super);
function ObservableUpDownCounterInstrument() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ObservableUpDownCounterInstrument;
}(ObservableInstrument));
export { ObservableUpDownCounterInstrument };
export function isObservableInstrument(it) {
return it instanceof ObservableInstrument;
}
//# sourceMappingURL=Instruments.js.map

@@ -12,24 +12,32 @@ import * as metrics from '@opentelemetry/api-metrics';

*/
createHistogram(name: string, options?: metrics.HistogramOptions): metrics.Histogram;
createHistogram(name: string, options?: metrics.MetricOptions): metrics.Histogram;
/**
* Create a {@link metrics.Counter} instrument.
*/
createCounter(name: string, options?: metrics.CounterOptions): metrics.Counter;
createCounter(name: string, options?: metrics.MetricOptions): metrics.Counter;
/**
* Create a {@link metrics.UpDownCounter} instrument.
*/
createUpDownCounter(name: string, options?: metrics.UpDownCounterOptions): metrics.UpDownCounter;
createUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.UpDownCounter;
/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
createObservableGauge(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableGaugeOptions): void;
createObservableGauge(name: string, options?: metrics.MetricOptions): metrics.ObservableGauge;
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
createObservableCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableCounterOptions): void;
createObservableCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableCounter;
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
createObservableUpDownCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableUpDownCounterOptions): void;
createObservableUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableUpDownCounter;
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
addBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
removeBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
}
//# sourceMappingURL=Meter.d.ts.map

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

import { createInstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
import { CounterInstrument, HistogramInstrument, UpDownCounterInstrument } from './Instruments';
import { CounterInstrument, HistogramInstrument, ObservableCounterInstrument, ObservableGaugeInstrument, ObservableUpDownCounterInstrument, UpDownCounterInstrument, } from './Instruments';
/**

@@ -51,22 +51,37 @@ * This class implements the {@link metrics.Meter} interface.

/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
Meter.prototype.createObservableGauge = function (name, callback, options) {
Meter.prototype.createObservableGauge = function (name, options) {
var descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_GAUGE, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
var storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableGaugeInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
};
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
Meter.prototype.createObservableCounter = function (name, callback, options) {
Meter.prototype.createObservableCounter = function (name, options) {
var descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
var storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
};
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
Meter.prototype.createObservableUpDownCounter = function (name, callback, options) {
Meter.prototype.createObservableUpDownCounter = function (name, options) {
var descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_UP_DOWN_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
var storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableUpDownCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
};
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
Meter.prototype.addBatchObservableCallback = function (callback, observables) {
this._meterSharedState.observableRegistry.addBatchCallback(callback, observables);
};
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
Meter.prototype.removeBatchObservableCallback = function (callback, observables) {
this._meterSharedState.observableRegistry.removeBatchCallback(callback, observables);
};
return Meter;

@@ -73,0 +88,0 @@ }());

import * as metrics from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './state/HashMap';
import { ObservableInstrument } from './Instruments';
import { InstrumentDescriptor } from '.';
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
export declare class ObservableResult implements metrics.ObservableResult {
export declare class ObservableResultImpl implements metrics.ObservableResult {
private _descriptor;
/**
* @internal
*/
buffer: AttributeHashMap<number>;
_buffer: AttributeHashMap<number>;
constructor(_descriptor: InstrumentDescriptor);
/**

@@ -16,2 +20,15 @@ * Observe a measurement of the value associated with the given attributes.

}
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
export declare class BatchObservableResultImpl implements metrics.BatchObservableResult {
/**
* @internal
*/
_buffer: Map<ObservableInstrument, AttributeHashMap<number>>;
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(metric: metrics.Observable, value: number, attributes?: metrics.MetricAttributes): void;
}
//# sourceMappingURL=ObservableResult.d.ts.map

@@ -16,12 +16,16 @@ /*

*/
import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './state/HashMap';
import { isObservableInstrument } from './Instruments';
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
var ObservableResult = /** @class */ (function () {
function ObservableResult() {
var ObservableResultImpl = /** @class */ (function () {
function ObservableResultImpl(_descriptor) {
this._descriptor = _descriptor;
/**
* @internal
*/
this.buffer = new AttributeHashMap();
this._buffer = new AttributeHashMap();
}

@@ -31,9 +35,45 @@ /**

*/
ObservableResult.prototype.observe = function (value, attributes) {
ObservableResultImpl.prototype.observe = function (value, attributes) {
if (attributes === void 0) { attributes = {}; }
this.buffer.set(attributes, value);
if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn("INT value type cannot accept a floating-point value for " + this._descriptor.name + ", ignoring the fractional digits.");
value = Math.trunc(value);
}
this._buffer.set(attributes, value);
};
return ObservableResult;
return ObservableResultImpl;
}());
export { ObservableResult };
export { ObservableResultImpl };
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
var BatchObservableResultImpl = /** @class */ (function () {
function BatchObservableResultImpl() {
/**
* @internal
*/
this._buffer = new Map();
}
/**
* Observe a measurement of the value associated with the given attributes.
*/
BatchObservableResultImpl.prototype.observe = function (metric, value, attributes) {
if (attributes === void 0) { attributes = {}; }
if (!isObservableInstrument(metric)) {
return;
}
var map = this._buffer.get(metric);
if (map == null) {
map = new AttributeHashMap();
this._buffer.set(metric, map);
}
if (metric._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn("INT value type cannot accept a floating-point value for " + metric._descriptor.name + ", ignoring the fractional digits.");
value = Math.trunc(value);
}
map.set(attributes, value);
};
return BatchObservableResultImpl;
}());
export { BatchObservableResultImpl };
//# sourceMappingURL=ObservableResult.js.map
import { HrTime } from '@opentelemetry/api';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -11,2 +9,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

import { MetricCollectorHandle } from './MetricCollector';
import { AttributeHashMap } from './HashMap';
import { AsyncWritableMetricStorage } from './WritableMetricStorage';
/**

@@ -17,9 +17,8 @@ * Internal interface.

*/
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage {
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage implements AsyncWritableMetricStorage {
private _attributesProcessor;
private _callback;
private _deltaMetricStorage;
private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, _callback: ObservableCallback);
private _record;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
record(measurements: AttributeHashMap<number>): void;
/**

@@ -32,5 +31,4 @@ * Collects the metrics from this storage. The ObservableCallback is invoked

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor, callback: ObservableCallback): AsyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

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

})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {

@@ -84,7 +48,5 @@ var m = typeof Symbol === "function" && o[Symbol.iterator];

};
import { createInstrumentDescriptorWithView } from '../InstrumentDescriptor';
import { MetricStorage } from './MetricStorage';
import { DeltaMetricProcessor } from './DeltaMetricProcessor';
import { TemporalMetricProcessor } from './TemporalMetricProcessor';
import { ObservableResult } from '../ObservableResult';
import { AttributeHashMap } from './HashMap';

@@ -98,6 +60,5 @@ /**

__extends(AsyncMetricStorage, _super);
function AsyncMetricStorage(_instrumentDescriptor, aggregator, _attributesProcessor, _callback) {
function AsyncMetricStorage(_instrumentDescriptor, aggregator, _attributesProcessor) {
var _this = _super.call(this, _instrumentDescriptor) || this;
_this._attributesProcessor = _attributesProcessor;
_this._callback = _callback;
_this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);

@@ -107,3 +68,3 @@ _this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);

}
AsyncMetricStorage.prototype._record = function (measurements) {
AsyncMetricStorage.prototype.record = function (measurements) {
var _this = this;

@@ -125,25 +86,5 @@ var processed = new AttributeHashMap();

AsyncMetricStorage.prototype.collect = function (collector, collectors, sdkStartTime, collectionTime) {
return __awaiter(this, void 0, void 0, function () {
var observableResult, accumulations;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
observableResult = new ObservableResult();
// TODO: timeout with callback
return [4 /*yield*/, this._callback(observableResult)];
case 1:
// TODO: timeout with callback
_a.sent();
this._record(observableResult.buffer);
accumulations = this._deltaMetricStorage.collect();
return [2 /*return*/, this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime)];
}
});
});
var accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
};
AsyncMetricStorage.create = function (view, instrument, callback) {
instrument = createInstrumentDescriptorWithView(view, instrument);
var aggregator = view.aggregation.createAggregator(instrument);
return new AsyncMetricStorage(instrument, aggregator, view.attributesProcessor, callback);
};
return AsyncMetricStorage;

@@ -150,0 +91,0 @@ }(MetricStorage));

import { HrTime } from '@opentelemetry/api';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';

@@ -17,4 +17,4 @@ import { ViewRegistry } from '../view/ViewRegistry';

constructor(resource: Resource);
getMeterSharedState(instrumentationLibrary: InstrumentationLibrary): MeterSharedState;
getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

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

import { hrTime } from '@opentelemetry/core';
import { instrumentationLibraryId } from '../utils';
import { instrumentationScopeId } from '../utils';
import { ViewRegistry } from '../view/ViewRegistry';

@@ -32,7 +32,7 @@ import { MeterSharedState } from './MeterSharedState';

}
MeterProviderSharedState.prototype.getMeterSharedState = function (instrumentationLibrary) {
var id = instrumentationLibraryId(instrumentationLibrary);
MeterProviderSharedState.prototype.getMeterSharedState = function (instrumentationScope) {
var id = instrumentationScopeId(instrumentationScope);
var meterSharedState = this.meterSharedStates.get(id);
if (meterSharedState == null) {
meterSharedState = new MeterSharedState(this, instrumentationLibrary);
meterSharedState = new MeterSharedState(this, instrumentationScope);
this.meterSharedStates.set(id, meterSharedState);

@@ -39,0 +39,0 @@ }

import { HrTime } from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationLibraryMetrics } from '../export/MetricData';
import { InstrumentationScope } from '@opentelemetry/core';
import { MetricCollectOptions } from '../export/MetricProducer';
import { ScopeMetrics } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Meter } from '../Meter';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';

@@ -16,15 +18,21 @@ /**

private _meterProviderSharedState;
private _instrumentationLibrary;
private _instrumentationScope;
private _metricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationLibrary: InstrumentationLibrary);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("..").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor, callback: metrics.ObservableCallback): void;
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>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Promise<InstrumentationLibraryMetrics>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
errors: unknown[];
}
export {};
//# sourceMappingURL=MeterSharedState.d.ts.map

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

import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';

@@ -64,6 +65,7 @@ /**

var MeterSharedState = /** @class */ (function () {
function MeterSharedState(_meterProviderSharedState, _instrumentationLibrary) {
function MeterSharedState(_meterProviderSharedState, _instrumentationScope) {
this._meterProviderSharedState = _meterProviderSharedState;
this._instrumentationLibrary = _instrumentationLibrary;
this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry();
this.meter = new Meter(this);

@@ -73,3 +75,3 @@ }

var _this = this;
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
var storages = views

@@ -88,11 +90,14 @@ .map(function (view) {

};
MeterSharedState.prototype.registerAsyncMetricStorage = function (descriptor, callback) {
MeterSharedState.prototype.registerAsyncMetricStorage = function (descriptor) {
var _this = this;
var views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
views.forEach(function (view) {
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, callback);
_this._metricStorageRegistry.register(viewStorage);
});
var viewStorage = new AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return _this._metricStorageRegistry.register(viewStorage);
})
.filter(isNotNullish);
return storages;
};

@@ -102,20 +107,24 @@ /**

* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
MeterSharedState.prototype.collect = function (collector, collectionTime) {
MeterSharedState.prototype.collect = function (collector, collectionTime, options) {
return __awaiter(this, void 0, void 0, function () {
var metricDataList;
var errors, metricDataList;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(Array.from(this._metricStorageRegistry.getStorages())
case 0: return [4 /*yield*/, this.observableRegistry.observe(options === null || options === void 0 ? void 0 : options.timeoutMillis)];
case 1:
errors = _a.sent();
metricDataList = Array.from(this._metricStorageRegistry.getStorages())
.map(function (metricStorage) {
return metricStorage.collect(collector, _this._meterProviderSharedState.metricCollectors, _this._meterProviderSharedState.sdkStartTime, collectionTime);
})
.filter(isNotNullish))];
case 1:
metricDataList = _a.sent();
.filter(isNotNullish);
return [2 /*return*/, {
instrumentationLibrary: this._instrumentationLibrary,
metrics: metricDataList.filter(isNotNullish),
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(isNotNullish),
},
errors: errors,
}];

@@ -122,0 +131,0 @@ }

@@ -1,5 +0,6 @@

import { AggregationTemporality } from '../export/AggregationTemporality';
import { ResourceMetrics } from '../export/MetricData';
import { MetricProducer } from '../export/MetricProducer';
import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { CollectionResult } from '../export/MetricData';
import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';
import { MetricReader } from '../export/MetricReader';
import { InstrumentType } from '../InstrumentDescriptor';
import { ForceFlushOptions, ShutdownOptions } from '../types';

@@ -15,5 +16,4 @@ import { MeterProviderSharedState } from './MeterProviderSharedState';

private _metricReader;
readonly aggregatorTemporality: AggregationTemporality;
constructor(_sharedState: MeterProviderSharedState, _metricReader: MetricReader);
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
/**

@@ -27,2 +27,3 @@ * Delegates for MetricReader.forceFlush.

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

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

export interface MetricCollectorHandle {
aggregatorTemporality: AggregationTemporality;
selectAggregationTemporality: AggregationTemporalitySelector;
}
//# sourceMappingURL=MetricCollector.d.ts.map

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

import { hrTime } from '@opentelemetry/core';
import { FlatMap } from '../utils';
/**

@@ -63,7 +64,6 @@ * An internal opaque interface that the MetricReader receives as

this._metricReader = _metricReader;
this.aggregatorTemporality = this._metricReader.getPreferredAggregationTemporality();
}
MetricCollector.prototype.collect = function () {
MetricCollector.prototype.collect = function (options) {
return __awaiter(this, void 0, void 0, function () {
var collectionTime, meterCollectionPromises, instrumentationLibraryMetrics;
var collectionTime, meterCollectionPromises, result;
var _this = this;

@@ -75,9 +75,12 @@ return __generator(this, function (_a) {

meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values())
.map(function (meterSharedState) { return meterSharedState.collect(_this, collectionTime); });
.map(function (meterSharedState) { return meterSharedState.collect(_this, collectionTime, options); });
return [4 /*yield*/, Promise.all(meterCollectionPromises)];
case 1:
instrumentationLibraryMetrics = _a.sent();
result = _a.sent();
return [2 /*return*/, {
resource: this._sharedState.resource,
instrumentationLibraryMetrics: instrumentationLibraryMetrics,
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(function (it) { return it.scopeMetrics; }),
},
errors: FlatMap(result, function (it) { return it.errors; }),
}];

@@ -118,2 +121,5 @@ }

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

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

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

*/
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;

@@ -23,0 +23,0 @@ updateDescription(description: string): void;

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

import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -30,5 +29,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

@@ -31,39 +31,2 @@ /*

})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { createInstrumentDescriptorWithView } from '../InstrumentDescriptor';
import { MetricStorage } from './MetricStorage';

@@ -97,15 +60,5 @@ import { DeltaMetricProcessor } from './DeltaMetricProcessor';

SyncMetricStorage.prototype.collect = function (collector, collectors, sdkStartTime, collectionTime) {
return __awaiter(this, void 0, void 0, function () {
var accumulations;
return __generator(this, function (_a) {
accumulations = this._deltaMetricStorage.collect();
return [2 /*return*/, this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime)];
});
});
var accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
};
SyncMetricStorage.create = function (view, instrument) {
instrument = createInstrumentDescriptorWithView(view, instrument);
var aggregator = view.aggregation.createAggregator(instrument);
return new SyncMetricStorage(instrument, aggregator, view.attributesProcessor);
};
return SyncMetricStorage;

@@ -112,0 +65,0 @@ }(MetricStorage));

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

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

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

@@ -62,3 +62,3 @@ /*

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

@@ -71,3 +71,2 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

TemporalMetricProcessor.prototype.buildMetrics = function (collector, collectors, instrumentDescriptor, currentAccumulations, sdkStartTime, collectionTime) {
var aggregationTemporality = collector.aggregatorTemporality;
// In case it's our first collection, default to start timestamp (see below for explanation).

@@ -78,2 +77,3 @@ var lastCollectionTime = sdkStartTime;

var result = unreportedAccumulations;
var aggregationTemporality;
// Check our last report time.

@@ -84,2 +84,3 @@ if (this._reportHistory.has(collector)) {

lastCollectionTime = last.collectionTime;
aggregationTemporality = last.aggregationTemporality;
// Use aggregation temporality + instrument to determine if we do a merge or a diff of

@@ -89,11 +90,20 @@ // previous. We have the following four scenarios:

// Here we merge with our last record to get a cumulative aggregation.
// 2. Cumulative Aggregation + Cumulative recording - do nothing
// 3. Delta Aggregation + Delta recording - do nothing.
// 4. Delta Aggregation + Cumulative recording (async instrument) - do nothing
// 2. Cumulative Aggregation + Cumulative recording (async instrument).
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Here we merge with our last record to get a cumulative aggregation.
// 3. Delta Aggregation + Delta recording
// Do nothing here.
// 4. Delta Aggregation + Cumulative recording.
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Do nothing here.
if (aggregationTemporality === AggregationTemporality.CUMULATIVE) {
// We need to make sure the current delta recording gets merged into the previous cumulative
// for the next cumulative measurement.
// for the next cumulative recording.
result = TemporalMetricProcessor.merge(last.accumulations, unreportedAccumulations, this._aggregator);
}
}
else {
// Call into user code to select aggregation temporality for the instrument.
aggregationTemporality = collector.selectAggregationTemporality(instrumentDescriptor.type);
}
// Update last reported (cumulative) accumulation.

@@ -103,2 +113,3 @@ this._reportHistory.set(collector, {

collectionTime: collectionTime,
aggregationTemporality: aggregationTemporality,
});

@@ -108,3 +119,3 @@ // Metric data time span is determined as:

// 2. Delta Aggregation time span: (lastCollectionTime, collectionTime]
return this._aggregator.toMetricData(instrumentDescriptor, AttributesMapToAccumulationRecords(result),
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
/* startTime */ aggregationTemporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime,

@@ -111,0 +122,0 @@ /* endTime */ collectionTime);

import { Context } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './HashMap';
/**
* Internal interface.
* Internal interface. Stores measurements and allows synchronous writes of
* measurements.
*
* Stores {@link MetricData} and allows synchronous writes of measurements.
* An interface representing SyncMetricStorage with type parameters removed.
*/

@@ -12,5 +14,12 @@ export interface WritableMetricStorage {

}
export declare class NoopWritableMetricStorage implements WritableMetricStorage {
record(_value: number, _attributes: MetricAttributes, _context: Context): void;
/**
* Internal interface. Stores measurements and allows asynchronous writes of
* measurements.
*
* An interface representing AsyncMetricStorage with type parameters removed.
*/
export interface AsyncWritableMetricStorage {
/** Records a batch of measurements. */
record(measurements: AttributeHashMap<number>): void;
}
//# sourceMappingURL=WritableMetricStorage.d.ts.map

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

*/
var NoopWritableMetricStorage = /** @class */ (function () {
function NoopWritableMetricStorage() {
}
NoopWritableMetricStorage.prototype.record = function (_value, _attributes, _context) { };
return NoopWritableMetricStorage;
}());
export { NoopWritableMetricStorage };
export {};
//# sourceMappingURL=WritableMetricStorage.js.map
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
export declare type Maybe<T> = T | undefined;

@@ -11,6 +11,6 @@ export declare function isNotNullish<T>(item: Maybe<T>): item is T;

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
export declare function instrumentationLibraryId(instrumentationLibrary: InstrumentationLibrary): string;
export declare function instrumentationScopeId(instrumentationScope: InstrumentationScope): string;
/**

@@ -32,2 +32,21 @@ * Error that is thrown on timeouts.

export declare function callWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T>;
export interface PromiseAllSettledFulfillResult<T> {
status: 'fulfilled';
value: T;
}
export interface PromiseAllSettledRejectionResult {
status: 'rejected';
reason: unknown;
}
export declare type PromiseAllSettledResult<T> = PromiseAllSettledFulfillResult<T> | PromiseAllSettledRejectionResult;
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
export declare function PromiseAllSettled<T>(promises: Promise<T>[]): Promise<PromiseAllSettledResult<T>[]>;
export declare function isPromiseAllSettledRejectionResult(it: PromiseAllSettledResult<unknown>): it is PromiseAllSettledRejectionResult;
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
export declare function FlatMap<T, R>(arr: T[], fn: (it: T) => R[]): R[];
export declare function setEquals(lhs: Set<unknown>, rhs: Set<unknown>): boolean;
//# sourceMappingURL=utils.d.ts.map

@@ -31,2 +31,74 @@ /*

})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
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;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
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.");
};
export function isNotNullish(item) {

@@ -52,8 +124,8 @@ return item !== undefined && item !== null;

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
export function instrumentationLibraryId(instrumentationLibrary) {
export function instrumentationScopeId(instrumentationScope) {
var _a, _b;
return instrumentationLibrary.name + ":" + ((_a = instrumentationLibrary.version) !== null && _a !== void 0 ? _a : '') + ":" + ((_b = instrumentationLibrary.schemaUrl) !== null && _b !== void 0 ? _b : '');
return instrumentationScope.name + ":" + ((_a = instrumentationScope.version) !== null && _a !== void 0 ? _a : '') + ":" + ((_b = instrumentationScope.schemaUrl) !== null && _b !== void 0 ? _b : '');
}

@@ -99,2 +171,70 @@ /**

}
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
export function PromiseAllSettled(promises) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2 /*return*/, Promise.all(promises.map(function (p) { return __awaiter(_this, void 0, void 0, function () {
var ret, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, p];
case 1:
ret = _a.sent();
return [2 /*return*/, {
status: 'fulfilled',
value: ret,
}];
case 2:
e_1 = _a.sent();
return [2 /*return*/, {
status: 'rejected',
reason: e_1,
}];
case 3: return [2 /*return*/];
}
});
}); }))];
});
});
}
export function isPromiseAllSettledRejectionResult(it) {
return it.status === 'rejected';
}
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
export function FlatMap(arr, fn) {
var result = [];
arr.forEach(function (it) {
result.push.apply(result, __spreadArray([], __read(fn(it)), false));
});
return result;
}
export function setEquals(lhs, rhs) {
var e_2, _a;
if (lhs.size !== rhs.size) {
return false;
}
try {
for (var lhs_1 = __values(lhs), lhs_1_1 = lhs_1.next(); !lhs_1_1.done; lhs_1_1 = lhs_1.next()) {
var item = lhs_1_1.value;
if (!rhs.has(item)) {
return false;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (lhs_1_1 && !lhs_1_1.done && (_a = lhs_1.return)) _a.call(lhs_1);
}
finally { if (e_2) throw e_2.error; }
}
return true;
}
//# sourceMappingURL=utils.js.map

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

export declare const VERSION = "0.28.0";
export declare const VERSION = "0.29.0";
//# sourceMappingURL=version.d.ts.map

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

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

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

import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -10,3 +10,3 @@ import { InstrumentSelector } from './InstrumentSelector';

addView(view: View, instrumentSelector?: InstrumentSelector, meterSelector?: MeterSelector): void;
findViews(instrument: InstrumentDescriptor, meter: InstrumentationLibrary): View[];
findViews(instrument: InstrumentDescriptor, meter: InstrumentationScope): View[];
private _matchInstrument;

@@ -13,0 +13,0 @@ private _matchMeter;

import { HrTime } from '@opentelemetry/api';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -12,4 +13,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

diff(_previous: undefined, _current: undefined): undefined;
toMetricData(_descriptor: InstrumentDescriptor, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
toMetricData(_descriptor: InstrumentDescriptor, _aggregationTemporality: AggregationTemporality, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=Drop.d.ts.map

@@ -31,3 +31,3 @@ /*

}
toMetricData(_descriptor, _accumulationByAttributes, _startTime, _endTime) {
toMetricData(_descriptor, _aggregationTemporality, _accumulationByAttributes, _startTime, _endTime) {
return undefined;

@@ -34,0 +34,0 @@ }

@@ -6,2 +6,3 @@ import { Accumulation, AccumulationRecord, Aggregator, AggregatorKind, Histogram } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class HistogramAccumulation implements Accumulation {

@@ -36,4 +37,4 @@ private readonly _boundaries;

diff(previous: HistogramAccumulation, current: HistogramAccumulation): HistogramAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
}
//# sourceMappingURL=Histogram.d.ts.map

@@ -110,5 +110,6 @@ /*

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: DataPointType.HISTOGRAM,

@@ -115,0 +116,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

@@ -6,2 +6,3 @@ import { LastValue, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class LastValueAccumulation implements Accumulation {

@@ -31,4 +32,4 @@ private _current;

diff(previous: LastValueAccumulation, current: LastValueAccumulation): LastValueAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=LastValue.d.ts.map

@@ -61,5 +61,6 @@ /*

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: DataPointType.SINGULAR,

@@ -66,0 +67,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

@@ -6,2 +6,3 @@ import { Sum, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class SumAccumulation implements Accumulation {

@@ -25,4 +26,4 @@ private _current;

diff(previous: SumAccumulation, current: SumAccumulation): SumAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=Sum.d.ts.map

@@ -49,5 +49,6 @@ /*

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: DataPointType.SINGULAR,

@@ -54,0 +55,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -88,4 +89,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

*/
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=types.d.ts.map

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

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

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

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map
import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Histogram } from '../aggregator/types';
import { AggregationTemporality } from './AggregationTemporality';
/**

@@ -12,2 +13,3 @@ * Basic metric data fields.

readonly descriptor: InstrumentDescriptor;
readonly aggregationTemporality: AggregationTemporality;
/**

@@ -37,4 +39,4 @@ * DataPointType of the metric instrument.

export declare type MetricData = SingularMetricData | HistogramMetricData;
export interface InstrumentationLibraryMetrics {
instrumentationLibrary: InstrumentationLibrary;
export interface ScopeMetrics {
scope: InstrumentationScope;
metrics: MetricData[];

@@ -44,4 +46,8 @@ }

resource: Resource;
instrumentationLibraryMetrics: InstrumentationLibraryMetrics[];
scopeMetrics: ScopeMetrics[];
}
export interface CollectionResult {
resourceMetrics: ResourceMetrics;
errors: unknown[];
}
/**

@@ -48,0 +54,0 @@ * The aggregated point data type.

import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { ExportResult } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
export interface PushMetricExporter {
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
forceFlush(): Promise<void>;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
shutdown(): Promise<void>;

@@ -12,4 +13,6 @@ }

protected _shutdown: boolean;
private _aggregationTemporality;
constructor(aggregationTemporality?: AggregationTemporality);
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality;
forceFlush(): Promise<void>;

@@ -16,0 +19,0 @@ shutdown(): Promise<void>;

@@ -19,4 +19,5 @@ /*

export class ConsoleMetricExporter {
constructor() {
constructor(aggregationTemporality) {
this._shutdown = true;
this._aggregationTemporality = aggregationTemporality !== null && aggregationTemporality !== void 0 ? aggregationTemporality : AggregationTemporality.CUMULATIVE;
}

@@ -29,4 +30,4 @@ export(metrics, resultCallback) {

}
getPreferredAggregationTemporality() {
return AggregationTemporality.CUMULATIVE;
selectAggregationTemporality(_instrumentType) {
return this._aggregationTemporality;
}

@@ -33,0 +34,0 @@ // nothing to do

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

import { ResourceMetrics } from './MetricData';
import { CollectionResult } from './MetricData';
export interface MetricCollectOptions {
timeoutMillis?: number;
}
/**

@@ -6,4 +9,4 @@ * This is a public interface that represent an export state of a MetricReader.

export interface MetricProducer {
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
}
//# sourceMappingURL=MetricProducer.d.ts.map
import { AggregationTemporality } from './AggregationTemporality';
import { MetricProducer } from './MetricProducer';
import { ResourceMetrics } from './MetricData';
import { Maybe } from '../utils';
import { CollectionResult } from './MetricData';
import { InstrumentType } from '../InstrumentDescriptor';
import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';

@@ -11,6 +11,4 @@ /**

export declare abstract class MetricReader {
private readonly _preferredAggregationTemporality;
private _shutdown;
private _metricProducer?;
constructor(_preferredAggregationTemporality?: AggregationTemporality);
/**

@@ -23,5 +21,5 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
* Get the default {@link AggregationTemporality} for the given {@link InstrumentType}
*/
getPreferredAggregationTemporality(): AggregationTemporality;
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -50,3 +48,3 @@ * Handle once the SDK has initialized this {@link MetricReader}

*/
collect(options?: CollectionOptions): Promise<Maybe<ResourceMetrics>>;
collect(options?: CollectionOptions): Promise<CollectionResult>;
/**

@@ -53,0 +51,0 @@ * Shuts down the metric reader, the promise will reject after the optional timeout or resolve after completion.

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

import * as api from '@opentelemetry/api';
import { AggregationTemporality } from './AggregationTemporality';
import { callWithTimeout } from '../utils';

@@ -26,4 +25,3 @@ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#metricreader

export class MetricReader {
constructor(_preferredAggregationTemporality = AggregationTemporality.CUMULATIVE) {
this._preferredAggregationTemporality = _preferredAggregationTemporality;
constructor() {
// Tracks the shutdown state.

@@ -46,8 +44,2 @@ // TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
*/
getPreferredAggregationTemporality() {
return this._preferredAggregationTemporality;
}
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -68,10 +60,7 @@ * Overriding this method is optional.

if (this._shutdown) {
api.diag.warn('Collection is not allowed after shutdown');
return undefined;
throw new Error('MetricReader is shutdown');
}
// No timeout if timeoutMillis is undefined or null.
if ((options === null || options === void 0 ? void 0 : options.timeoutMillis) == null) {
return await this._metricProducer.collect();
}
return await callWithTimeout(this._metricProducer.collect(), options.timeoutMillis);
return this._metricProducer.collect({
timeoutMillis: options === null || options === void 0 ? void 0 : options.timeoutMillis,
});
}

@@ -78,0 +67,0 @@ /**

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';

@@ -22,3 +24,4 @@ export declare type PeriodicExportingMetricReaderOptions = {

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

@@ -27,3 +27,3 @@ /*

var _a, _b;
super(options.exporter.getPreferredAggregationTemporality());
super();
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -45,8 +45,8 @@ throw Error('exportIntervalMillis must be greater than 0');

async _runOnce() {
const metrics = await this.collect({});
if (metrics === undefined) {
return;
const { resourceMetrics, errors } = await this.collect({});
if (errors.length > 0) {
api.diag.error('PeriodicExportingMetricReader: metrics collection errors', ...errors);
}
return new Promise((resolve, reject) => {
this._exporter.export(metrics, result => {
this._exporter.export(resourceMetrics, result => {
var _a;

@@ -86,3 +86,6 @@ if (result.code !== ExportResultCode.SUCCESS) {

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

@@ -1,5 +0,4 @@

export { Histogram } from './aggregator/types';
export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export { MeterProvider, MeterProviderOptions } from './MeterProvider';
export * from './export/MetricExporter';

@@ -15,4 +14,2 @@ export * from './export/MetricProducer';

export * from './view/Aggregation';
export { FilteringAttributesProcessor } from './view/AttributesProcessor';
export * from './aggregator/types';
//# sourceMappingURL=index.d.ts.map

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

export * from './export/MetricData';
export { MeterProvider } from './MeterProvider';
export * from './export/MetricExporter';

@@ -30,4 +29,2 @@ export * from './export/MetricProducer';

export * from './view/Aggregation';
export { FilteringAttributesProcessor } from './view/AttributesProcessor';
export * from './aggregator/types';
//# sourceMappingURL=index.js.map

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

description: (_a = options === null || options === void 0 ? void 0 : options.description) !== null && _a !== void 0 ? _a : '',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '1',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '',
valueType: (_c = options === null || options === void 0 ? void 0 : options.valueType) !== null && _c !== void 0 ? _c : ValueType.DOUBLE,

@@ -38,0 +38,0 @@ };

import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { InstrumentDescriptor } from './InstrumentDescriptor';
import { WritableMetricStorage } from './state/WritableMetricStorage';
import { ObservableRegistry } from './state/ObservableRegistry';
import { AsyncWritableMetricStorage, WritableMetricStorage } from './state/WritableMetricStorage';
export declare class SyncInstrument {
private _writableMetricStorage;
private _descriptor;
protected _descriptor: InstrumentDescriptor;
constructor(_writableMetricStorage: WritableMetricStorage, _descriptor: InstrumentDescriptor);
getName(): string;
protected _record(value: number, attributes?: metrics.MetricAttributes, context?: api.Context): void;

@@ -39,2 +40,25 @@ }

}
export declare class ObservableInstrument implements metrics.Observable {
private _observableRegistry;
/** @internal */
_metricStorages: AsyncWritableMetricStorage[];
/** @internal */
_descriptor: InstrumentDescriptor;
constructor(descriptor: InstrumentDescriptor, metricStorages: AsyncWritableMetricStorage[], _observableRegistry: ObservableRegistry);
/**
* @see {metrics.Observable.addCallback}
*/
addCallback(callback: ObservableCallback): void;
/**
* @see {metrics.Observable.removeCallback}
*/
removeCallback(callback: ObservableCallback): void;
}
export declare class ObservableCounterInstrument extends ObservableInstrument implements metrics.ObservableCounter {
}
export declare class ObservableGaugeInstrument extends ObservableInstrument implements metrics.ObservableGauge {
}
export declare class ObservableUpDownCounterInstrument extends ObservableInstrument implements metrics.ObservableUpDownCounter {
}
export declare function isObservableInstrument(it: unknown): it is ObservableInstrument;
//# sourceMappingURL=Instruments.d.ts.map

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

}
getName() {
return this._descriptor.name;
}
_record(value, attributes = {}, context = api.context.active()) {

@@ -55,3 +52,3 @@ if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {

if (value < 0) {
api.diag.warn(`negative value provided to counter ${this.getName()}: ${value}`);
api.diag.warn(`negative value provided to counter ${this._descriptor.name}: ${value}`);
return;

@@ -73,2 +70,30 @@ }

}
export class ObservableInstrument {
constructor(descriptor, metricStorages, _observableRegistry) {
this._observableRegistry = _observableRegistry;
this._descriptor = descriptor;
this._metricStorages = metricStorages;
}
/**
* @see {metrics.Observable.addCallback}
*/
addCallback(callback) {
this._observableRegistry.addCallback(callback, this);
}
/**
* @see {metrics.Observable.removeCallback}
*/
removeCallback(callback) {
this._observableRegistry.removeCallback(callback, this);
}
}
export class ObservableCounterInstrument extends ObservableInstrument {
}
export class ObservableGaugeInstrument extends ObservableInstrument {
}
export class ObservableUpDownCounterInstrument extends ObservableInstrument {
}
export function isObservableInstrument(it) {
return it instanceof ObservableInstrument;
}
//# sourceMappingURL=Instruments.js.map

@@ -12,24 +12,32 @@ import * as metrics from '@opentelemetry/api-metrics';

*/
createHistogram(name: string, options?: metrics.HistogramOptions): metrics.Histogram;
createHistogram(name: string, options?: metrics.MetricOptions): metrics.Histogram;
/**
* Create a {@link metrics.Counter} instrument.
*/
createCounter(name: string, options?: metrics.CounterOptions): metrics.Counter;
createCounter(name: string, options?: metrics.MetricOptions): metrics.Counter;
/**
* Create a {@link metrics.UpDownCounter} instrument.
*/
createUpDownCounter(name: string, options?: metrics.UpDownCounterOptions): metrics.UpDownCounter;
createUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.UpDownCounter;
/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
createObservableGauge(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableGaugeOptions): void;
createObservableGauge(name: string, options?: metrics.MetricOptions): metrics.ObservableGauge;
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
createObservableCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableCounterOptions): void;
createObservableCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableCounter;
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
createObservableUpDownCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableUpDownCounterOptions): void;
createObservableUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableUpDownCounter;
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
addBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
removeBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
}
//# sourceMappingURL=Meter.d.ts.map

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

import { createInstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
import { CounterInstrument, HistogramInstrument, UpDownCounterInstrument } from './Instruments';
import { CounterInstrument, HistogramInstrument, ObservableCounterInstrument, ObservableGaugeInstrument, ObservableUpDownCounterInstrument, UpDownCounterInstrument, } from './Instruments';
/**

@@ -51,23 +51,38 @@ * This class implements the {@link metrics.Meter} interface.

/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
createObservableGauge(name, callback, options) {
createObservableGauge(name, options) {
const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_GAUGE, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableGaugeInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
createObservableCounter(name, callback, options) {
createObservableCounter(name, options) {
const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
createObservableUpDownCounter(name, callback, options) {
createObservableUpDownCounter(name, options) {
const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_UP_DOWN_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new ObservableUpDownCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
addBatchObservableCallback(callback, observables) {
this._meterSharedState.observableRegistry.addBatchCallback(callback, observables);
}
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
removeBatchObservableCallback(callback, observables) {
this._meterSharedState.observableRegistry.removeBatchCallback(callback, observables);
}
}
//# sourceMappingURL=Meter.js.map
import * as metrics from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './state/HashMap';
import { ObservableInstrument } from './Instruments';
import { InstrumentDescriptor } from '.';
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
export declare class ObservableResult implements metrics.ObservableResult {
export declare class ObservableResultImpl implements metrics.ObservableResult {
private _descriptor;
/**
* @internal
*/
buffer: AttributeHashMap<number>;
_buffer: AttributeHashMap<number>;
constructor(_descriptor: InstrumentDescriptor);
/**

@@ -16,2 +20,15 @@ * Observe a measurement of the value associated with the given attributes.

}
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
export declare class BatchObservableResultImpl implements metrics.BatchObservableResult {
/**
* @internal
*/
_buffer: Map<ObservableInstrument, AttributeHashMap<number>>;
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(metric: metrics.Observable, value: number, attributes?: metrics.MetricAttributes): void;
}
//# sourceMappingURL=ObservableResult.d.ts.map

@@ -16,12 +16,16 @@ /*

*/
import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './state/HashMap';
import { isObservableInstrument } from './Instruments';
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
export class ObservableResult {
constructor() {
export class ObservableResultImpl {
constructor(_descriptor) {
this._descriptor = _descriptor;
/**
* @internal
*/
this.buffer = new AttributeHashMap();
this._buffer = new AttributeHashMap();
}

@@ -32,5 +36,38 @@ /**

observe(value, attributes = {}) {
this.buffer.set(attributes, value);
if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn(`INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.`);
value = Math.trunc(value);
}
this._buffer.set(attributes, value);
}
}
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
export class BatchObservableResultImpl {
constructor() {
/**
* @internal
*/
this._buffer = new Map();
}
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(metric, value, attributes = {}) {
if (!isObservableInstrument(metric)) {
return;
}
let map = this._buffer.get(metric);
if (map == null) {
map = new AttributeHashMap();
this._buffer.set(metric, map);
}
if (metric._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn(`INT value type cannot accept a floating-point value for ${metric._descriptor.name}, ignoring the fractional digits.`);
value = Math.trunc(value);
}
map.set(attributes, value);
}
}
//# sourceMappingURL=ObservableResult.js.map
import { HrTime } from '@opentelemetry/api';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -11,2 +9,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

import { MetricCollectorHandle } from './MetricCollector';
import { AttributeHashMap } from './HashMap';
import { AsyncWritableMetricStorage } from './WritableMetricStorage';
/**

@@ -17,9 +17,8 @@ * Internal interface.

*/
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage {
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage implements AsyncWritableMetricStorage {
private _attributesProcessor;
private _callback;
private _deltaMetricStorage;
private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, _callback: ObservableCallback);
private _record;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
record(measurements: AttributeHashMap<number>): void;
/**

@@ -32,5 +31,4 @@ * Collects the metrics from this storage. The ObservableCallback is invoked

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor, callback: ObservableCallback): AsyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

@@ -16,7 +16,5 @@ /*

*/
import { createInstrumentDescriptorWithView } from '../InstrumentDescriptor';
import { MetricStorage } from './MetricStorage';
import { DeltaMetricProcessor } from './DeltaMetricProcessor';
import { TemporalMetricProcessor } from './TemporalMetricProcessor';
import { ObservableResult } from '../ObservableResult';
import { AttributeHashMap } from './HashMap';

@@ -29,10 +27,9 @@ /**

export class AsyncMetricStorage extends MetricStorage {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor, _callback) {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor) {
super(_instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._callback = _callback;
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
}
_record(measurements) {
record(measurements) {
const processed = new AttributeHashMap();

@@ -51,16 +48,7 @@ Array.from(measurements.entries()).forEach(([attributes, value]) => {

*/
async collect(collector, collectors, sdkStartTime, collectionTime) {
const observableResult = new ObservableResult();
// TODO: timeout with callback
await this._callback(observableResult);
this._record(observableResult.buffer);
collect(collector, collectors, sdkStartTime, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
}
static create(view, instrument, callback) {
instrument = createInstrumentDescriptorWithView(view, instrument);
const aggregator = view.aggregation.createAggregator(instrument);
return new AsyncMetricStorage(instrument, aggregator, view.attributesProcessor, callback);
}
}
//# sourceMappingURL=AsyncMetricStorage.js.map
import { HrTime } from '@opentelemetry/api';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';

@@ -17,4 +17,4 @@ import { ViewRegistry } from '../view/ViewRegistry';

constructor(resource: Resource);
getMeterSharedState(instrumentationLibrary: InstrumentationLibrary): MeterSharedState;
getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

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

import { hrTime } from '@opentelemetry/core';
import { instrumentationLibraryId } from '../utils';
import { instrumentationScopeId } from '../utils';
import { ViewRegistry } from '../view/ViewRegistry';

@@ -32,7 +32,7 @@ import { MeterSharedState } from './MeterSharedState';

}
getMeterSharedState(instrumentationLibrary) {
const id = instrumentationLibraryId(instrumentationLibrary);
getMeterSharedState(instrumentationScope) {
const id = instrumentationScopeId(instrumentationScope);
let meterSharedState = this.meterSharedStates.get(id);
if (meterSharedState == null) {
meterSharedState = new MeterSharedState(this, instrumentationLibrary);
meterSharedState = new MeterSharedState(this, instrumentationScope);
this.meterSharedStates.set(id, meterSharedState);

@@ -39,0 +39,0 @@ }

import { HrTime } from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationLibraryMetrics } from '../export/MetricData';
import { InstrumentationScope } from '@opentelemetry/core';
import { MetricCollectOptions } from '../export/MetricProducer';
import { ScopeMetrics } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Meter } from '../Meter';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';

@@ -16,15 +18,21 @@ /**

private _meterProviderSharedState;
private _instrumentationLibrary;
private _instrumentationScope;
private _metricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationLibrary: InstrumentationLibrary);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("..").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor, callback: metrics.ObservableCallback): void;
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>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Promise<InstrumentationLibraryMetrics>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
errors: unknown[];
}
export {};
//# sourceMappingURL=MeterSharedState.d.ts.map

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

import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';

@@ -28,10 +29,11 @@ /**

export class MeterSharedState {
constructor(_meterProviderSharedState, _instrumentationLibrary) {
constructor(_meterProviderSharedState, _instrumentationScope) {
this._meterProviderSharedState = _meterProviderSharedState;
this._instrumentationLibrary = _instrumentationLibrary;
this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry();
this.meter = new Meter(this);
}
registerMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views

@@ -50,10 +52,13 @@ .map(view => {

}
registerAsyncMetricStorage(descriptor, callback) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
views.forEach(view => {
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, callback);
this._metricStorageRegistry.register(viewStorage);
});
const viewStorage = new AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(viewStorage);
})
.filter(isNotNullish);
return storages;
}

@@ -63,5 +68,5 @@ /**

* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
async collect(collector, collectionTime) {
async collect(collector, collectionTime, options) {
/**

@@ -71,10 +76,14 @@ * 1. Call all observable callbacks first.

*/
const metricDataList = await Promise.all(Array.from(this._metricStorageRegistry.getStorages())
const errors = await this.observableRegistry.observe(options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this._metricStorageRegistry.getStorages())
.map(metricStorage => {
return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, this._meterProviderSharedState.sdkStartTime, collectionTime);
})
.filter(isNotNullish));
.filter(isNotNullish);
return {
instrumentationLibrary: this._instrumentationLibrary,
metrics: metricDataList.filter(isNotNullish),
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(isNotNullish),
},
errors,
};

@@ -81,0 +90,0 @@ }

@@ -1,5 +0,6 @@

import { AggregationTemporality } from '../export/AggregationTemporality';
import { ResourceMetrics } from '../export/MetricData';
import { MetricProducer } from '../export/MetricProducer';
import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { CollectionResult } from '../export/MetricData';
import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';
import { MetricReader } from '../export/MetricReader';
import { InstrumentType } from '../InstrumentDescriptor';
import { ForceFlushOptions, ShutdownOptions } from '../types';

@@ -15,5 +16,4 @@ import { MeterProviderSharedState } from './MeterProviderSharedState';

private _metricReader;
readonly aggregatorTemporality: AggregationTemporality;
constructor(_sharedState: MeterProviderSharedState, _metricReader: MetricReader);
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
/**

@@ -27,2 +27,3 @@ * Delegates for MetricReader.forceFlush.

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

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

export interface MetricCollectorHandle {
aggregatorTemporality: AggregationTemporality;
selectAggregationTemporality: AggregationTemporalitySelector;
}
//# sourceMappingURL=MetricCollector.d.ts.map

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

import { hrTime } from '@opentelemetry/core';
import { FlatMap } from '../utils';
/**

@@ -27,12 +28,14 @@ * An internal opaque interface that the MetricReader receives as

this._metricReader = _metricReader;
this.aggregatorTemporality = this._metricReader.getPreferredAggregationTemporality();
}
async collect() {
async collect(options) {
const collectionTime = hrTime();
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values())
.map(meterSharedState => meterSharedState.collect(this, collectionTime));
const instrumentationLibraryMetrics = await Promise.all(meterCollectionPromises);
.map(meterSharedState => meterSharedState.collect(this, collectionTime, options));
const result = await Promise.all(meterCollectionPromises);
return {
resource: this._sharedState.resource,
instrumentationLibraryMetrics,
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(it => it.scopeMetrics),
},
errors: FlatMap(result, it => it.errors),
};

@@ -52,3 +55,6 @@ }

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

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

*/
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;

@@ -23,0 +23,0 @@ updateDescription(description: string): void;

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

import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -30,5 +29,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

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

*/
import { createInstrumentDescriptorWithView } from '../InstrumentDescriptor';
import { MetricStorage } from './MetricStorage';

@@ -43,12 +42,7 @@ import { DeltaMetricProcessor } from './DeltaMetricProcessor';

*/
async collect(collector, collectors, sdkStartTime, collectionTime) {
collect(collector, collectors, sdkStartTime, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
}
static create(view, instrument) {
instrument = createInstrumentDescriptorWithView(view, instrument);
const aggregator = view.aggregation.createAggregator(instrument);
return new SyncMetricStorage(instrument, aggregator, view.attributesProcessor);
}
}
//# sourceMappingURL=SyncMetricStorage.js.map

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

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

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

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

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

@@ -44,3 +44,2 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

buildMetrics(collector, collectors, instrumentDescriptor, currentAccumulations, sdkStartTime, collectionTime) {
const aggregationTemporality = collector.aggregatorTemporality;
// In case it's our first collection, default to start timestamp (see below for explanation).

@@ -51,2 +50,3 @@ let lastCollectionTime = sdkStartTime;

let result = unreportedAccumulations;
let aggregationTemporality;
// Check our last report time.

@@ -57,2 +57,3 @@ if (this._reportHistory.has(collector)) {

lastCollectionTime = last.collectionTime;
aggregationTemporality = last.aggregationTemporality;
// Use aggregation temporality + instrument to determine if we do a merge or a diff of

@@ -62,11 +63,20 @@ // previous. We have the following four scenarios:

// Here we merge with our last record to get a cumulative aggregation.
// 2. Cumulative Aggregation + Cumulative recording - do nothing
// 3. Delta Aggregation + Delta recording - do nothing.
// 4. Delta Aggregation + Cumulative recording (async instrument) - do nothing
// 2. Cumulative Aggregation + Cumulative recording (async instrument).
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Here we merge with our last record to get a cumulative aggregation.
// 3. Delta Aggregation + Delta recording
// Do nothing here.
// 4. Delta Aggregation + Cumulative recording.
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Do nothing here.
if (aggregationTemporality === AggregationTemporality.CUMULATIVE) {
// We need to make sure the current delta recording gets merged into the previous cumulative
// for the next cumulative measurement.
// for the next cumulative recording.
result = TemporalMetricProcessor.merge(last.accumulations, unreportedAccumulations, this._aggregator);
}
}
else {
// Call into user code to select aggregation temporality for the instrument.
aggregationTemporality = collector.selectAggregationTemporality(instrumentDescriptor.type);
}
// Update last reported (cumulative) accumulation.

@@ -76,2 +86,3 @@ this._reportHistory.set(collector, {

collectionTime,
aggregationTemporality,
});

@@ -81,3 +92,3 @@ // Metric data time span is determined as:

// 2. Delta Aggregation time span: (lastCollectionTime, collectionTime]
return this._aggregator.toMetricData(instrumentDescriptor, AttributesMapToAccumulationRecords(result),
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
/* startTime */ aggregationTemporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime,

@@ -84,0 +95,0 @@ /* endTime */ collectionTime);

import { Context } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './HashMap';
/**
* Internal interface.
* Internal interface. Stores measurements and allows synchronous writes of
* measurements.
*
* Stores {@link MetricData} and allows synchronous writes of measurements.
* An interface representing SyncMetricStorage with type parameters removed.
*/

@@ -12,5 +14,12 @@ export interface WritableMetricStorage {

}
export declare class NoopWritableMetricStorage implements WritableMetricStorage {
record(_value: number, _attributes: MetricAttributes, _context: Context): void;
/**
* Internal interface. Stores measurements and allows asynchronous writes of
* measurements.
*
* An interface representing AsyncMetricStorage with type parameters removed.
*/
export interface AsyncWritableMetricStorage {
/** Records a batch of measurements. */
record(measurements: AttributeHashMap<number>): void;
}
//# sourceMappingURL=WritableMetricStorage.d.ts.map

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

*/
export class NoopWritableMetricStorage {
record(_value, _attributes, _context) { }
}
export {};
//# sourceMappingURL=WritableMetricStorage.js.map
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
export declare type Maybe<T> = T | undefined;

@@ -11,6 +11,6 @@ export declare function isNotNullish<T>(item: Maybe<T>): item is T;

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
export declare function instrumentationLibraryId(instrumentationLibrary: InstrumentationLibrary): string;
export declare function instrumentationScopeId(instrumentationScope: InstrumentationScope): string;
/**

@@ -32,2 +32,21 @@ * Error that is thrown on timeouts.

export declare function callWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T>;
export interface PromiseAllSettledFulfillResult<T> {
status: 'fulfilled';
value: T;
}
export interface PromiseAllSettledRejectionResult {
status: 'rejected';
reason: unknown;
}
export declare type PromiseAllSettledResult<T> = PromiseAllSettledFulfillResult<T> | PromiseAllSettledRejectionResult;
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
export declare function PromiseAllSettled<T>(promises: Promise<T>[]): Promise<PromiseAllSettledResult<T>[]>;
export declare function isPromiseAllSettledRejectionResult(it: PromiseAllSettledResult<unknown>): it is PromiseAllSettledRejectionResult;
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
export declare function FlatMap<T, R>(arr: T[], fn: (it: T) => R[]): R[];
export declare function setEquals(lhs: Set<unknown>, rhs: Set<unknown>): boolean;
//# sourceMappingURL=utils.d.ts.map

@@ -36,8 +36,8 @@ /*

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
export function instrumentationLibraryId(instrumentationLibrary) {
export function instrumentationScopeId(instrumentationScope) {
var _a, _b;
return `${instrumentationLibrary.name}:${(_a = instrumentationLibrary.version) !== null && _a !== void 0 ? _a : ''}:${(_b = instrumentationLibrary.schemaUrl) !== null && _b !== void 0 ? _b : ''}`;
return `${instrumentationScope.name}:${(_a = instrumentationScope.version) !== null && _a !== void 0 ? _a : ''}:${(_b = instrumentationScope.schemaUrl) !== null && _b !== void 0 ? _b : ''}`;
}

@@ -79,2 +79,46 @@ /**

}
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
export async function PromiseAllSettled(promises) {
return Promise.all(promises.map(async (p) => {
try {
const ret = await p;
return {
status: 'fulfilled',
value: ret,
};
}
catch (e) {
return {
status: 'rejected',
reason: e,
};
}
}));
}
export function isPromiseAllSettledRejectionResult(it) {
return it.status === 'rejected';
}
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
export function FlatMap(arr, fn) {
const result = [];
arr.forEach(it => {
result.push(...fn(it));
});
return result;
}
export function setEquals(lhs, rhs) {
if (lhs.size !== rhs.size) {
return false;
}
for (const item of lhs) {
if (!rhs.has(item)) {
return false;
}
}
return true;
}
//# sourceMappingURL=utils.js.map

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

export declare const VERSION = "0.28.0";
export declare const VERSION = "0.29.0";
//# sourceMappingURL=version.d.ts.map

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

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

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

import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -10,3 +10,3 @@ import { InstrumentSelector } from './InstrumentSelector';

addView(view: View, instrumentSelector?: InstrumentSelector, meterSelector?: MeterSelector): void;
findViews(instrument: InstrumentDescriptor, meter: InstrumentationLibrary): View[];
findViews(instrument: InstrumentDescriptor, meter: InstrumentationScope): View[];
private _matchInstrument;

@@ -13,0 +13,0 @@ private _matchMeter;

import { HrTime } from '@opentelemetry/api';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -12,4 +13,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

diff(_previous: undefined, _current: undefined): undefined;
toMetricData(_descriptor: InstrumentDescriptor, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
toMetricData(_descriptor: InstrumentDescriptor, _aggregationTemporality: AggregationTemporality, _accumulationByAttributes: AccumulationRecord<undefined>[], _startTime: HrTime, _endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=Drop.d.ts.map

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

}
toMetricData(_descriptor, _accumulationByAttributes, _startTime, _endTime) {
toMetricData(_descriptor, _aggregationTemporality, _accumulationByAttributes, _startTime, _endTime) {
return undefined;

@@ -37,0 +37,0 @@ }

@@ -6,2 +6,3 @@ import { Accumulation, AccumulationRecord, Aggregator, AggregatorKind, Histogram } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class HistogramAccumulation implements Accumulation {

@@ -36,4 +37,4 @@ private readonly _boundaries;

diff(previous: HistogramAccumulation, current: HistogramAccumulation): HistogramAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<HistogramMetricData>;
}
//# sourceMappingURL=Histogram.d.ts.map

@@ -114,5 +114,6 @@ "use strict";

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: MetricData_1.DataPointType.HISTOGRAM,

@@ -119,0 +120,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

@@ -6,2 +6,3 @@ import { LastValue, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class LastValueAccumulation implements Accumulation {

@@ -31,4 +32,4 @@ private _current;

diff(previous: LastValueAccumulation, current: LastValueAccumulation): LastValueAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=LastValue.d.ts.map

@@ -65,5 +65,6 @@ "use strict";

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: MetricData_1.DataPointType.SINGULAR,

@@ -70,0 +71,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

@@ -6,2 +6,3 @@ import { Sum, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';

import { Maybe } from '../utils';
import { AggregationTemporality } from '../export/AggregationTemporality';
export declare class SumAccumulation implements Accumulation {

@@ -25,4 +26,4 @@ private _current;

diff(previous: SumAccumulation, current: SumAccumulation): SumAccumulation;
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<SumAccumulation>[], startTime: HrTime, endTime: HrTime): Maybe<SingularMetricData>;
}
//# sourceMappingURL=Sum.d.ts.map

@@ -53,5 +53,6 @@ "use strict";

}
toMetricData(descriptor, accumulationByAttributes, startTime, endTime) {
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, startTime, endTime) {
return {
descriptor,
aggregationTemporality,
dataPointType: MetricData_1.DataPointType.SINGULAR,

@@ -58,0 +59,0 @@ dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {

import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';

@@ -88,4 +89,4 @@ import { InstrumentDescriptor } from '../InstrumentDescriptor';

*/
toMetricData(descriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
toMetricData(descriptor: InstrumentDescriptor, aggregationTemporality: AggregationTemporality, accumulationByAttributes: AccumulationRecord<T>[], startTime: HrTime, endTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=types.d.ts.map

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

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

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

}
export declare type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
//# sourceMappingURL=AggregationTemporality.d.ts.map
import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Histogram } from '../aggregator/types';
import { AggregationTemporality } from './AggregationTemporality';
/**

@@ -12,2 +13,3 @@ * Basic metric data fields.

readonly descriptor: InstrumentDescriptor;
readonly aggregationTemporality: AggregationTemporality;
/**

@@ -37,4 +39,4 @@ * DataPointType of the metric instrument.

export declare type MetricData = SingularMetricData | HistogramMetricData;
export interface InstrumentationLibraryMetrics {
instrumentationLibrary: InstrumentationLibrary;
export interface ScopeMetrics {
scope: InstrumentationScope;
metrics: MetricData[];

@@ -44,4 +46,8 @@ }

resource: Resource;
instrumentationLibraryMetrics: InstrumentationLibraryMetrics[];
scopeMetrics: ScopeMetrics[];
}
export interface CollectionResult {
resourceMetrics: ResourceMetrics;
errors: unknown[];
}
/**

@@ -48,0 +54,0 @@ * The aggregated point data type.

import { AggregationTemporality } from './AggregationTemporality';
import { ResourceMetrics } from './MetricData';
import { ExportResult } from '@opentelemetry/core';
import { InstrumentType } from '../InstrumentDescriptor';
export interface PushMetricExporter {
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
forceFlush(): Promise<void>;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
shutdown(): Promise<void>;

@@ -12,4 +13,6 @@ }

protected _shutdown: boolean;
private _aggregationTemporality;
constructor(aggregationTemporality?: AggregationTemporality);
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
getPreferredAggregationTemporality(): AggregationTemporality;
selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality;
forceFlush(): Promise<void>;

@@ -16,0 +19,0 @@ shutdown(): Promise<void>;

@@ -22,4 +22,5 @@ "use strict";

class ConsoleMetricExporter {
constructor() {
constructor(aggregationTemporality) {
this._shutdown = true;
this._aggregationTemporality = aggregationTemporality !== null && aggregationTemporality !== void 0 ? aggregationTemporality : AggregationTemporality_1.AggregationTemporality.CUMULATIVE;
}

@@ -32,4 +33,4 @@ export(metrics, resultCallback) {

}
getPreferredAggregationTemporality() {
return AggregationTemporality_1.AggregationTemporality.CUMULATIVE;
selectAggregationTemporality(_instrumentType) {
return this._aggregationTemporality;
}

@@ -36,0 +37,0 @@ // nothing to do

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

import { ResourceMetrics } from './MetricData';
import { CollectionResult } from './MetricData';
export interface MetricCollectOptions {
timeoutMillis?: number;
}
/**

@@ -6,4 +9,4 @@ * This is a public interface that represent an export state of a MetricReader.

export interface MetricProducer {
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
}
//# sourceMappingURL=MetricProducer.d.ts.map
import { AggregationTemporality } from './AggregationTemporality';
import { MetricProducer } from './MetricProducer';
import { ResourceMetrics } from './MetricData';
import { Maybe } from '../utils';
import { CollectionResult } from './MetricData';
import { InstrumentType } from '../InstrumentDescriptor';
import { CollectionOptions, ForceFlushOptions, ShutdownOptions } from '../types';

@@ -11,6 +11,4 @@ /**

export declare abstract class MetricReader {
private readonly _preferredAggregationTemporality;
private _shutdown;
private _metricProducer?;
constructor(_preferredAggregationTemporality?: AggregationTemporality);
/**

@@ -23,5 +21,5 @@ * Set the {@link MetricProducer} used by this instance.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
* Get the default {@link AggregationTemporality} for the given {@link InstrumentType}
*/
getPreferredAggregationTemporality(): AggregationTemporality;
abstract selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
/**

@@ -50,3 +48,3 @@ * Handle once the SDK has initialized this {@link MetricReader}

*/
collect(options?: CollectionOptions): Promise<Maybe<ResourceMetrics>>;
collect(options?: CollectionOptions): Promise<CollectionResult>;
/**

@@ -53,0 +51,0 @@ * Shuts down the metric reader, the promise will reject after the optional timeout or resolve after completion.

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

const api = require("@opentelemetry/api");
const AggregationTemporality_1 = require("./AggregationTemporality");
const utils_1 = require("../utils");

@@ -29,4 +28,3 @@ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#metricreader

class MetricReader {
constructor(_preferredAggregationTemporality = AggregationTemporality_1.AggregationTemporality.CUMULATIVE) {
this._preferredAggregationTemporality = _preferredAggregationTemporality;
constructor() {
// Tracks the shutdown state.

@@ -49,8 +47,2 @@ // TODO: use BindOncePromise here once a new version of @opentelemetry/core is available.

/**
* Get the {@link AggregationTemporality} preferred by this {@link MetricReader}
*/
getPreferredAggregationTemporality() {
return this._preferredAggregationTemporality;
}
/**
* Handle once the SDK has initialized this {@link MetricReader}

@@ -71,10 +63,7 @@ * Overriding this method is optional.

if (this._shutdown) {
api.diag.warn('Collection is not allowed after shutdown');
return undefined;
throw new Error('MetricReader is shutdown');
}
// No timeout if timeoutMillis is undefined or null.
if ((options === null || options === void 0 ? void 0 : options.timeoutMillis) == null) {
return await this._metricProducer.collect();
}
return await (0, utils_1.callWithTimeout)(this._metricProducer.collect(), options.timeoutMillis);
return this._metricProducer.collect({
timeoutMillis: options === null || options === void 0 ? void 0 : options.timeoutMillis,
});
}

@@ -81,0 +70,0 @@ /**

import { MetricReader } from './MetricReader';
import { AggregationTemporality } from './AggregationTemporality';
import { InstrumentType } from '../InstrumentDescriptor';
import { PushMetricExporter } from './MetricExporter';

@@ -22,3 +24,4 @@ export declare type PeriodicExportingMetricReaderOptions = {

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

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

var _a, _b;
super(options.exporter.getPreferredAggregationTemporality());
super();
if (options.exportIntervalMillis !== undefined && options.exportIntervalMillis <= 0) {

@@ -48,8 +48,8 @@ throw Error('exportIntervalMillis must be greater than 0');

async _runOnce() {
const metrics = await this.collect({});
if (metrics === undefined) {
return;
const { resourceMetrics, errors } = await this.collect({});
if (errors.length > 0) {
api.diag.error('PeriodicExportingMetricReader: metrics collection errors', ...errors);
}
return new Promise((resolve, reject) => {
this._exporter.export(metrics, result => {
this._exporter.export(resourceMetrics, result => {
var _a;

@@ -89,4 +89,7 @@ if (result.code !== core_1.ExportResultCode.SUCCESS) {

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

@@ -1,5 +0,4 @@

export { Histogram } from './aggregator/types';
export { Sum, LastValue, Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export { MeterProvider, MeterProviderOptions } from './MeterProvider';
export * from './export/MetricExporter';

@@ -15,4 +14,2 @@ export * from './export/MetricProducer';

export * from './view/Aggregation';
export { FilteringAttributesProcessor } from './view/AttributesProcessor';
export * from './aggregator/types';
//# sourceMappingURL=index.d.ts.map

@@ -28,7 +28,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.FilteringAttributesProcessor = exports.TimeoutError = exports.InstrumentType = exports.MeterProvider = void 0;
exports.TimeoutError = exports.InstrumentType = void 0;
__exportStar(require("./export/AggregationTemporality"), exports);
__exportStar(require("./export/MetricData"), exports);
var MeterProvider_1 = require("./MeterProvider");
Object.defineProperty(exports, "MeterProvider", { enumerable: true, get: function () { return MeterProvider_1.MeterProvider; } });
__exportStar(require("./export/MetricExporter"), exports);

@@ -46,5 +44,2 @@ __exportStar(require("./export/MetricProducer"), exports);

__exportStar(require("./view/Aggregation"), exports);
var AttributesProcessor_1 = require("./view/AttributesProcessor");
Object.defineProperty(exports, "FilteringAttributesProcessor", { enumerable: true, get: function () { return AttributesProcessor_1.FilteringAttributesProcessor; } });
__exportStar(require("./aggregator/types"), exports);
//# sourceMappingURL=index.js.map

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

description: (_a = options === null || options === void 0 ? void 0 : options.description) !== null && _a !== void 0 ? _a : '',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '1',
unit: (_b = options === null || options === void 0 ? void 0 : options.unit) !== null && _b !== void 0 ? _b : '',
valueType: (_c = options === null || options === void 0 ? void 0 : options.valueType) !== null && _c !== void 0 ? _c : api_metrics_1.ValueType.DOUBLE,

@@ -41,0 +41,0 @@ };

import * as api from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { InstrumentDescriptor } from './InstrumentDescriptor';
import { WritableMetricStorage } from './state/WritableMetricStorage';
import { ObservableRegistry } from './state/ObservableRegistry';
import { AsyncWritableMetricStorage, WritableMetricStorage } from './state/WritableMetricStorage';
export declare class SyncInstrument {
private _writableMetricStorage;
private _descriptor;
protected _descriptor: InstrumentDescriptor;
constructor(_writableMetricStorage: WritableMetricStorage, _descriptor: InstrumentDescriptor);
getName(): string;
protected _record(value: number, attributes?: metrics.MetricAttributes, context?: api.Context): void;

@@ -39,2 +40,25 @@ }

}
export declare class ObservableInstrument implements metrics.Observable {
private _observableRegistry;
/** @internal */
_metricStorages: AsyncWritableMetricStorage[];
/** @internal */
_descriptor: InstrumentDescriptor;
constructor(descriptor: InstrumentDescriptor, metricStorages: AsyncWritableMetricStorage[], _observableRegistry: ObservableRegistry);
/**
* @see {metrics.Observable.addCallback}
*/
addCallback(callback: ObservableCallback): void;
/**
* @see {metrics.Observable.removeCallback}
*/
removeCallback(callback: ObservableCallback): void;
}
export declare class ObservableCounterInstrument extends ObservableInstrument implements metrics.ObservableCounter {
}
export declare class ObservableGaugeInstrument extends ObservableInstrument implements metrics.ObservableGauge {
}
export declare class ObservableUpDownCounterInstrument extends ObservableInstrument implements metrics.ObservableUpDownCounter {
}
export declare function isObservableInstrument(it: unknown): it is ObservableInstrument;
//# sourceMappingURL=Instruments.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.HistogramInstrument = exports.CounterInstrument = exports.UpDownCounterInstrument = exports.SyncInstrument = void 0;
exports.isObservableInstrument = exports.ObservableUpDownCounterInstrument = exports.ObservableGaugeInstrument = exports.ObservableCounterInstrument = exports.ObservableInstrument = exports.HistogramInstrument = exports.CounterInstrument = exports.UpDownCounterInstrument = exports.SyncInstrument = void 0;
const api = require("@opentelemetry/api");

@@ -27,5 +27,2 @@ const metrics = require("@opentelemetry/api-metrics");

}
getName() {
return this._descriptor.name;
}
_record(value, attributes = {}, context = api.context.active()) {

@@ -61,3 +58,3 @@ if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {

if (value < 0) {
api.diag.warn(`negative value provided to counter ${this.getName()}: ${value}`);
api.diag.warn(`negative value provided to counter ${this._descriptor.name}: ${value}`);
return;

@@ -81,2 +78,35 @@ }

exports.HistogramInstrument = HistogramInstrument;
class ObservableInstrument {
constructor(descriptor, metricStorages, _observableRegistry) {
this._observableRegistry = _observableRegistry;
this._descriptor = descriptor;
this._metricStorages = metricStorages;
}
/**
* @see {metrics.Observable.addCallback}
*/
addCallback(callback) {
this._observableRegistry.addCallback(callback, this);
}
/**
* @see {metrics.Observable.removeCallback}
*/
removeCallback(callback) {
this._observableRegistry.removeCallback(callback, this);
}
}
exports.ObservableInstrument = ObservableInstrument;
class ObservableCounterInstrument extends ObservableInstrument {
}
exports.ObservableCounterInstrument = ObservableCounterInstrument;
class ObservableGaugeInstrument extends ObservableInstrument {
}
exports.ObservableGaugeInstrument = ObservableGaugeInstrument;
class ObservableUpDownCounterInstrument extends ObservableInstrument {
}
exports.ObservableUpDownCounterInstrument = ObservableUpDownCounterInstrument;
function isObservableInstrument(it) {
return it instanceof ObservableInstrument;
}
exports.isObservableInstrument = isObservableInstrument;
//# sourceMappingURL=Instruments.js.map

@@ -12,24 +12,32 @@ import * as metrics from '@opentelemetry/api-metrics';

*/
createHistogram(name: string, options?: metrics.HistogramOptions): metrics.Histogram;
createHistogram(name: string, options?: metrics.MetricOptions): metrics.Histogram;
/**
* Create a {@link metrics.Counter} instrument.
*/
createCounter(name: string, options?: metrics.CounterOptions): metrics.Counter;
createCounter(name: string, options?: metrics.MetricOptions): metrics.Counter;
/**
* Create a {@link metrics.UpDownCounter} instrument.
*/
createUpDownCounter(name: string, options?: metrics.UpDownCounterOptions): metrics.UpDownCounter;
createUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.UpDownCounter;
/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
createObservableGauge(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableGaugeOptions): void;
createObservableGauge(name: string, options?: metrics.MetricOptions): metrics.ObservableGauge;
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
createObservableCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableCounterOptions): void;
createObservableCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableCounter;
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
createObservableUpDownCounter(name: string, callback: metrics.ObservableCallback, options?: metrics.ObservableUpDownCounterOptions): void;
createObservableUpDownCounter(name: string, options?: metrics.MetricOptions): metrics.ObservableUpDownCounter;
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
addBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
removeBatchObservableCallback(callback: metrics.BatchObservableCallback, observables: metrics.Observable[]): void;
}
//# sourceMappingURL=Meter.d.ts.map

@@ -53,24 +53,39 @@ "use strict";

/**
* Create a ObservableGauge instrument.
* Create a {@link metrics.ObservableGauge} instrument.
*/
createObservableGauge(name, callback, options) {
createObservableGauge(name, options) {
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name, InstrumentDescriptor_1.InstrumentType.OBSERVABLE_GAUGE, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new Instruments_1.ObservableGaugeInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* Create a ObservableCounter instrument.
* Create a {@link metrics.ObservableCounter} instrument.
*/
createObservableCounter(name, callback, options) {
createObservableCounter(name, options) {
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name, InstrumentDescriptor_1.InstrumentType.OBSERVABLE_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new Instruments_1.ObservableCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* Create a ObservableUpDownCounter instrument.
* Create a {@link metrics.ObservableUpDownCounter} instrument.
*/
createObservableUpDownCounter(name, callback, options) {
createObservableUpDownCounter(name, options) {
const descriptor = (0, InstrumentDescriptor_1.createInstrumentDescriptor)(name, InstrumentDescriptor_1.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER, options);
this._meterSharedState.registerAsyncMetricStorage(descriptor, callback);
const storages = this._meterSharedState.registerAsyncMetricStorage(descriptor);
return new Instruments_1.ObservableUpDownCounterInstrument(descriptor, storages, this._meterSharedState.observableRegistry);
}
/**
* @see {@link metrics.Meter.addBatchObservableCallback}
*/
addBatchObservableCallback(callback, observables) {
this._meterSharedState.observableRegistry.addBatchCallback(callback, observables);
}
/**
* @see {@link metrics.Meter.removeBatchObservableCallback}
*/
removeBatchObservableCallback(callback, observables) {
this._meterSharedState.observableRegistry.removeBatchCallback(callback, observables);
}
}
exports.Meter = Meter;
//# sourceMappingURL=Meter.js.map
import * as metrics from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './state/HashMap';
import { ObservableInstrument } from './Instruments';
import { InstrumentDescriptor } from '.';
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
export declare class ObservableResult implements metrics.ObservableResult {
export declare class ObservableResultImpl implements metrics.ObservableResult {
private _descriptor;
/**
* @internal
*/
buffer: AttributeHashMap<number>;
_buffer: AttributeHashMap<number>;
constructor(_descriptor: InstrumentDescriptor);
/**

@@ -16,2 +20,15 @@ * Observe a measurement of the value associated with the given attributes.

}
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
export declare class BatchObservableResultImpl implements metrics.BatchObservableResult {
/**
* @internal
*/
_buffer: Map<ObservableInstrument, AttributeHashMap<number>>;
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(metric: metrics.Observable, value: number, attributes?: metrics.MetricAttributes): void;
}
//# sourceMappingURL=ObservableResult.d.ts.map

@@ -18,13 +18,17 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ObservableResult = void 0;
exports.BatchObservableResultImpl = exports.ObservableResultImpl = void 0;
const api = require("@opentelemetry/api");
const metrics = require("@opentelemetry/api-metrics");
const HashMap_1 = require("./state/HashMap");
const Instruments_1 = require("./Instruments");
/**
* The class implements {@link metrics.observableResult} interface.
* The class implements {@link metrics.ObservableResult} interface.
*/
class ObservableResult {
constructor() {
class ObservableResultImpl {
constructor(_descriptor) {
this._descriptor = _descriptor;
/**
* @internal
*/
this.buffer = new HashMap_1.AttributeHashMap();
this._buffer = new HashMap_1.AttributeHashMap();
}

@@ -35,6 +39,40 @@ /**

observe(value, attributes = {}) {
this.buffer.set(attributes, value);
if (this._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn(`INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.`);
value = Math.trunc(value);
}
this._buffer.set(attributes, value);
}
}
exports.ObservableResult = ObservableResult;
exports.ObservableResultImpl = ObservableResultImpl;
/**
* The class implements {@link metrics.BatchObservableCallback} interface.
*/
class BatchObservableResultImpl {
constructor() {
/**
* @internal
*/
this._buffer = new Map();
}
/**
* Observe a measurement of the value associated with the given attributes.
*/
observe(metric, value, attributes = {}) {
if (!(0, Instruments_1.isObservableInstrument)(metric)) {
return;
}
let map = this._buffer.get(metric);
if (map == null) {
map = new HashMap_1.AttributeHashMap();
this._buffer.set(metric, map);
}
if (metric._descriptor.valueType === metrics.ValueType.INT && !Number.isInteger(value)) {
api.diag.warn(`INT value type cannot accept a floating-point value for ${metric._descriptor.name}, ignoring the fractional digits.`);
value = Math.trunc(value);
}
map.set(attributes, value);
}
}
exports.BatchObservableResultImpl = BatchObservableResultImpl;
//# sourceMappingURL=ObservableResult.js.map
import { HrTime } from '@opentelemetry/api';
import { ObservableCallback } from '@opentelemetry/api-metrics';
import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -11,2 +9,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

import { MetricCollectorHandle } from './MetricCollector';
import { AttributeHashMap } from './HashMap';
import { AsyncWritableMetricStorage } from './WritableMetricStorage';
/**

@@ -17,9 +17,8 @@ * Internal interface.

*/
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage {
export declare class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage implements AsyncWritableMetricStorage {
private _attributesProcessor;
private _callback;
private _deltaMetricStorage;
private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, _callback: ObservableCallback);
private _record;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
record(measurements: AttributeHashMap<number>): void;
/**

@@ -32,5 +31,4 @@ * Collects the metrics from this storage. The ObservableCallback is invoked

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor, callback: ObservableCallback): AsyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

@@ -19,7 +19,5 @@ "use strict";

exports.AsyncMetricStorage = void 0;
const InstrumentDescriptor_1 = require("../InstrumentDescriptor");
const MetricStorage_1 = require("./MetricStorage");
const DeltaMetricProcessor_1 = require("./DeltaMetricProcessor");
const TemporalMetricProcessor_1 = require("./TemporalMetricProcessor");
const ObservableResult_1 = require("../ObservableResult");
const HashMap_1 = require("./HashMap");

@@ -32,10 +30,9 @@ /**

class AsyncMetricStorage extends MetricStorage_1.MetricStorage {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor, _callback) {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor) {
super(_instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._callback = _callback;
this._deltaMetricStorage = new DeltaMetricProcessor_1.DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator);
}
_record(measurements) {
record(measurements) {
const processed = new HashMap_1.AttributeHashMap();

@@ -54,17 +51,8 @@ Array.from(measurements.entries()).forEach(([attributes, value]) => {

*/
async collect(collector, collectors, sdkStartTime, collectionTime) {
const observableResult = new ObservableResult_1.ObservableResult();
// TODO: timeout with callback
await this._callback(observableResult);
this._record(observableResult.buffer);
collect(collector, collectors, sdkStartTime, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
}
static create(view, instrument, callback) {
instrument = (0, InstrumentDescriptor_1.createInstrumentDescriptorWithView)(view, instrument);
const aggregator = view.aggregation.createAggregator(instrument);
return new AsyncMetricStorage(instrument, aggregator, view.attributesProcessor, callback);
}
}
exports.AsyncMetricStorage = AsyncMetricStorage;
//# sourceMappingURL=AsyncMetricStorage.js.map
import { HrTime } from '@opentelemetry/api';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';

@@ -17,4 +17,4 @@ import { ViewRegistry } from '../view/ViewRegistry';

constructor(resource: Resource);
getMeterSharedState(instrumentationLibrary: InstrumentationLibrary): MeterSharedState;
getMeterSharedState(instrumentationScope: InstrumentationScope): MeterSharedState;
}
//# sourceMappingURL=MeterProviderSharedState.d.ts.map

@@ -34,7 +34,7 @@ "use strict";

}
getMeterSharedState(instrumentationLibrary) {
const id = (0, utils_1.instrumentationLibraryId)(instrumentationLibrary);
getMeterSharedState(instrumentationScope) {
const id = (0, utils_1.instrumentationScopeId)(instrumentationScope);
let meterSharedState = this.meterSharedStates.get(id);
if (meterSharedState == null) {
meterSharedState = new MeterSharedState_1.MeterSharedState(this, instrumentationLibrary);
meterSharedState = new MeterSharedState_1.MeterSharedState(this, instrumentationScope);
this.meterSharedStates.set(id, meterSharedState);

@@ -41,0 +41,0 @@ }

import { HrTime } from '@opentelemetry/api';
import * as metrics from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationLibraryMetrics } from '../export/MetricData';
import { InstrumentationScope } from '@opentelemetry/core';
import { MetricCollectOptions } from '../export/MetricProducer';
import { ScopeMetrics } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Meter } from '../Meter';
import { AsyncMetricStorage } from './AsyncMetricStorage';
import { MeterProviderSharedState } from './MeterProviderSharedState';
import { MetricCollectorHandle } from './MetricCollector';
import { MultiMetricStorage } from './MultiWritableMetricStorage';
import { ObservableRegistry } from './ObservableRegistry';
import { SyncMetricStorage } from './SyncMetricStorage';

@@ -16,15 +18,21 @@ /**

private _meterProviderSharedState;
private _instrumentationLibrary;
private _instrumentationScope;
private _metricStorageRegistry;
observableRegistry: ObservableRegistry;
meter: Meter;
constructor(_meterProviderSharedState: MeterProviderSharedState, _instrumentationLibrary: InstrumentationLibrary);
registerMetricStorage(descriptor: InstrumentDescriptor): MultiMetricStorage | SyncMetricStorage<import("../utils").Maybe<import("..").Accumulation>>;
registerAsyncMetricStorage(descriptor: InstrumentDescriptor, callback: metrics.ObservableCallback): void;
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>>[];
/**
* @param collector opaque handle of {@link MetricCollector} which initiated the collection.
* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Promise<InstrumentationLibraryMetrics>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
errors: unknown[];
}
export {};
//# sourceMappingURL=MeterSharedState.d.ts.map

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

const MultiWritableMetricStorage_1 = require("./MultiWritableMetricStorage");
const ObservableRegistry_1 = require("./ObservableRegistry");
const SyncMetricStorage_1 = require("./SyncMetricStorage");

@@ -31,10 +32,11 @@ /**

class MeterSharedState {
constructor(_meterProviderSharedState, _instrumentationLibrary) {
constructor(_meterProviderSharedState, _instrumentationScope) {
this._meterProviderSharedState = _meterProviderSharedState;
this._instrumentationLibrary = _instrumentationLibrary;
this._instrumentationScope = _instrumentationScope;
this._metricStorageRegistry = new MetricStorageRegistry_1.MetricStorageRegistry();
this.observableRegistry = new ObservableRegistry_1.ObservableRegistry();
this.meter = new Meter_1.Meter(this);
}
registerMetricStorage(descriptor) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationScope);
const storages = views

@@ -53,10 +55,13 @@ .map(view => {

}
registerAsyncMetricStorage(descriptor, callback) {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
views.forEach(view => {
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, callback);
this._metricStorageRegistry.register(viewStorage);
});
const viewStorage = new AsyncMetricStorage_1.AsyncMetricStorage(viewDescriptor, aggregator, view.attributesProcessor);
return this._metricStorageRegistry.register(viewStorage);
})
.filter(utils_1.isNotNullish);
return storages;
}

@@ -66,5 +71,5 @@ /**

* @param collectionTime the HrTime at which the collection was initiated.
* @returns the list of {@link MetricData} collected.
* @returns the list of metric data collected.
*/
async collect(collector, collectionTime) {
async collect(collector, collectionTime, options) {
/**

@@ -74,10 +79,14 @@ * 1. Call all observable callbacks first.

*/
const metricDataList = await Promise.all(Array.from(this._metricStorageRegistry.getStorages())
const errors = await this.observableRegistry.observe(options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this._metricStorageRegistry.getStorages())
.map(metricStorage => {
return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, this._meterProviderSharedState.sdkStartTime, collectionTime);
})
.filter(utils_1.isNotNullish));
.filter(utils_1.isNotNullish);
return {
instrumentationLibrary: this._instrumentationLibrary,
metrics: metricDataList.filter(utils_1.isNotNullish),
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(utils_1.isNotNullish),
},
errors,
};

@@ -84,0 +93,0 @@ }

@@ -1,5 +0,6 @@

import { AggregationTemporality } from '../export/AggregationTemporality';
import { ResourceMetrics } from '../export/MetricData';
import { MetricProducer } from '../export/MetricProducer';
import { AggregationTemporalitySelector } from '../export/AggregationTemporality';
import { CollectionResult } from '../export/MetricData';
import { MetricProducer, MetricCollectOptions } from '../export/MetricProducer';
import { MetricReader } from '../export/MetricReader';
import { InstrumentType } from '../InstrumentDescriptor';
import { ForceFlushOptions, ShutdownOptions } from '../types';

@@ -15,5 +16,4 @@ import { MeterProviderSharedState } from './MeterProviderSharedState';

private _metricReader;
readonly aggregatorTemporality: AggregationTemporality;
constructor(_sharedState: MeterProviderSharedState, _metricReader: MetricReader);
collect(): Promise<ResourceMetrics>;
collect(options?: MetricCollectOptions): Promise<CollectionResult>;
/**

@@ -27,2 +27,3 @@ * Delegates for MetricReader.forceFlush.

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

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

export interface MetricCollectorHandle {
aggregatorTemporality: AggregationTemporality;
selectAggregationTemporality: AggregationTemporalitySelector;
}
//# sourceMappingURL=MetricCollector.d.ts.map

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

const core_1 = require("@opentelemetry/core");
const utils_1 = require("../utils");
/**

@@ -30,12 +31,14 @@ * An internal opaque interface that the MetricReader receives as

this._metricReader = _metricReader;
this.aggregatorTemporality = this._metricReader.getPreferredAggregationTemporality();
}
async collect() {
async collect(options) {
const collectionTime = (0, core_1.hrTime)();
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values())
.map(meterSharedState => meterSharedState.collect(this, collectionTime));
const instrumentationLibraryMetrics = await Promise.all(meterCollectionPromises);
.map(meterSharedState => meterSharedState.collect(this, collectionTime, options));
const result = await Promise.all(meterCollectionPromises);
return {
resource: this._sharedState.resource,
instrumentationLibraryMetrics,
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(it => it.scopeMetrics),
},
errors: (0, utils_1.FlatMap)(result, it => it.errors),
};

@@ -55,4 +58,7 @@ }

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

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

*/
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
abstract collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
getInstrumentDescriptor(): InstrumentDescriptor;

@@ -23,0 +23,0 @@ updateDescription(description: string): void;

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

import { Accumulation, Aggregator } from '../aggregator/types';
import { View } from '../view/View';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -30,5 +29,4 @@ import { AttributesProcessor } from '../view/AttributesProcessor';

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Promise<Maybe<MetricData>>;
static create(view: View, instrument: InstrumentDescriptor): SyncMetricStorage<Maybe<Accumulation>>;
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], sdkStartTime: HrTime, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

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

exports.SyncMetricStorage = void 0;
const InstrumentDescriptor_1 = require("../InstrumentDescriptor");
const MetricStorage_1 = require("./MetricStorage");

@@ -46,13 +45,8 @@ const DeltaMetricProcessor_1 = require("./DeltaMetricProcessor");

*/
async collect(collector, collectors, sdkStartTime, collectionTime) {
collect(collector, collectors, sdkStartTime, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, sdkStartTime, collectionTime);
}
static create(view, instrument) {
instrument = (0, InstrumentDescriptor_1.createInstrumentDescriptorWithView)(view, instrument);
const aggregator = view.aggregation.createAggregator(instrument);
return new SyncMetricStorage(instrument, aggregator, view.attributesProcessor);
}
}
exports.SyncMetricStorage = SyncMetricStorage;
//# sourceMappingURL=SyncMetricStorage.js.map

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

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

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

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

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

@@ -47,3 +47,2 @@ * @param currentAccumulations The current accumulation of metric data from instruments.

buildMetrics(collector, collectors, instrumentDescriptor, currentAccumulations, sdkStartTime, collectionTime) {
const aggregationTemporality = collector.aggregatorTemporality;
// In case it's our first collection, default to start timestamp (see below for explanation).

@@ -54,2 +53,3 @@ let lastCollectionTime = sdkStartTime;

let result = unreportedAccumulations;
let aggregationTemporality;
// Check our last report time.

@@ -60,2 +60,3 @@ if (this._reportHistory.has(collector)) {

lastCollectionTime = last.collectionTime;
aggregationTemporality = last.aggregationTemporality;
// Use aggregation temporality + instrument to determine if we do a merge or a diff of

@@ -65,11 +66,20 @@ // previous. We have the following four scenarios:

// Here we merge with our last record to get a cumulative aggregation.
// 2. Cumulative Aggregation + Cumulative recording - do nothing
// 3. Delta Aggregation + Delta recording - do nothing.
// 4. Delta Aggregation + Cumulative recording (async instrument) - do nothing
// 2. Cumulative Aggregation + Cumulative recording (async instrument).
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Here we merge with our last record to get a cumulative aggregation.
// 3. Delta Aggregation + Delta recording
// Do nothing here.
// 4. Delta Aggregation + Cumulative recording.
// Cumulative records are converted to delta recording with DeltaMetricProcessor.
// Do nothing here.
if (aggregationTemporality === AggregationTemporality_1.AggregationTemporality.CUMULATIVE) {
// We need to make sure the current delta recording gets merged into the previous cumulative
// for the next cumulative measurement.
// for the next cumulative recording.
result = TemporalMetricProcessor.merge(last.accumulations, unreportedAccumulations, this._aggregator);
}
}
else {
// Call into user code to select aggregation temporality for the instrument.
aggregationTemporality = collector.selectAggregationTemporality(instrumentDescriptor.type);
}
// Update last reported (cumulative) accumulation.

@@ -79,2 +89,3 @@ this._reportHistory.set(collector, {

collectionTime,
aggregationTemporality,
});

@@ -84,3 +95,3 @@ // Metric data time span is determined as:

// 2. Delta Aggregation time span: (lastCollectionTime, collectionTime]
return this._aggregator.toMetricData(instrumentDescriptor, AttributesMapToAccumulationRecords(result),
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
/* startTime */ aggregationTemporality === AggregationTemporality_1.AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime,

@@ -87,0 +98,0 @@ /* endTime */ collectionTime);

import { Context } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { AttributeHashMap } from './HashMap';
/**
* Internal interface.
* Internal interface. Stores measurements and allows synchronous writes of
* measurements.
*
* Stores {@link MetricData} and allows synchronous writes of measurements.
* An interface representing SyncMetricStorage with type parameters removed.
*/

@@ -12,5 +14,12 @@ export interface WritableMetricStorage {

}
export declare class NoopWritableMetricStorage implements WritableMetricStorage {
record(_value: number, _attributes: MetricAttributes, _context: Context): void;
/**
* Internal interface. Stores measurements and allows asynchronous writes of
* measurements.
*
* An interface representing AsyncMetricStorage with type parameters removed.
*/
export interface AsyncWritableMetricStorage {
/** Records a batch of measurements. */
record(measurements: AttributeHashMap<number>): void;
}
//# sourceMappingURL=WritableMetricStorage.d.ts.map

@@ -18,7 +18,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.NoopWritableMetricStorage = void 0;
class NoopWritableMetricStorage {
record(_value, _attributes, _context) { }
}
exports.NoopWritableMetricStorage = NoopWritableMetricStorage;
//# sourceMappingURL=WritableMetricStorage.js.map
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
export declare type Maybe<T> = T | undefined;

@@ -11,6 +11,6 @@ export declare function isNotNullish<T>(item: Maybe<T>): item is T;

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
export declare function instrumentationLibraryId(instrumentationLibrary: InstrumentationLibrary): string;
export declare function instrumentationScopeId(instrumentationScope: InstrumentationScope): string;
/**

@@ -32,2 +32,21 @@ * Error that is thrown on timeouts.

export declare function callWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T>;
export interface PromiseAllSettledFulfillResult<T> {
status: 'fulfilled';
value: T;
}
export interface PromiseAllSettledRejectionResult {
status: 'rejected';
reason: unknown;
}
export declare type PromiseAllSettledResult<T> = PromiseAllSettledFulfillResult<T> | PromiseAllSettledRejectionResult;
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
export declare function PromiseAllSettled<T>(promises: Promise<T>[]): Promise<PromiseAllSettledResult<T>[]>;
export declare function isPromiseAllSettledRejectionResult(it: PromiseAllSettledResult<unknown>): it is PromiseAllSettledRejectionResult;
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
export declare function FlatMap<T, R>(arr: T[], fn: (it: T) => R[]): R[];
export declare function setEquals(lhs: Set<unknown>, rhs: Set<unknown>): boolean;
//# sourceMappingURL=utils.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.callWithTimeout = exports.TimeoutError = exports.instrumentationLibraryId = exports.hashAttributes = exports.isNotNullish = void 0;
exports.setEquals = exports.FlatMap = exports.isPromiseAllSettledRejectionResult = exports.PromiseAllSettled = exports.callWithTimeout = exports.TimeoutError = exports.instrumentationScopeId = exports.hashAttributes = exports.isNotNullish = void 0;
function isNotNullish(item) {

@@ -42,10 +42,10 @@ return item !== undefined && item !== null;

/**
* Converting the instrumentation library object to a unique identifier string.
* @param instrumentationLibrary
* Converting the instrumentation scope object to a unique identifier string.
* @param instrumentationScope
*/
function instrumentationLibraryId(instrumentationLibrary) {
function instrumentationScopeId(instrumentationScope) {
var _a, _b;
return `${instrumentationLibrary.name}:${(_a = instrumentationLibrary.version) !== null && _a !== void 0 ? _a : ''}:${(_b = instrumentationLibrary.schemaUrl) !== null && _b !== void 0 ? _b : ''}`;
return `${instrumentationScope.name}:${(_a = instrumentationScope.version) !== null && _a !== void 0 ? _a : ''}:${(_b = instrumentationScope.schemaUrl) !== null && _b !== void 0 ? _b : ''}`;
}
exports.instrumentationLibraryId = instrumentationLibraryId;
exports.instrumentationScopeId = instrumentationScopeId;
/**

@@ -88,2 +88,50 @@ * Error that is thrown on timeouts.

exports.callWithTimeout = callWithTimeout;
/**
* Node.js v12.9 lower and browser compatible `Promise.allSettled`.
*/
async function PromiseAllSettled(promises) {
return Promise.all(promises.map(async (p) => {
try {
const ret = await p;
return {
status: 'fulfilled',
value: ret,
};
}
catch (e) {
return {
status: 'rejected',
reason: e,
};
}
}));
}
exports.PromiseAllSettled = PromiseAllSettled;
function isPromiseAllSettledRejectionResult(it) {
return it.status === 'rejected';
}
exports.isPromiseAllSettledRejectionResult = isPromiseAllSettledRejectionResult;
/**
* Node.js v11.0 lower and browser compatible `Array.prototype.flatMap`.
*/
function FlatMap(arr, fn) {
const result = [];
arr.forEach(it => {
result.push(...fn(it));
});
return result;
}
exports.FlatMap = FlatMap;
function setEquals(lhs, rhs) {
if (lhs.size !== rhs.size) {
return false;
}
for (const item of lhs) {
if (!rhs.has(item)) {
return false;
}
}
return true;
}
exports.setEquals = setEquals;
//# sourceMappingURL=utils.js.map

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

export declare const VERSION = "0.28.0";
export declare const VERSION = "0.29.0";
//# sourceMappingURL=version.d.ts.map

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

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

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

import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

@@ -10,3 +10,3 @@ import { InstrumentSelector } from './InstrumentSelector';

addView(view: View, instrumentSelector?: InstrumentSelector, meterSelector?: MeterSelector): void;
findViews(instrument: InstrumentDescriptor, meter: InstrumentationLibrary): View[];
findViews(instrument: InstrumentDescriptor, meter: InstrumentationScope): View[];
private _matchInstrument;

@@ -13,0 +13,0 @@ private _matchMeter;

{
"name": "@opentelemetry/sdk-metrics-base",
"version": "0.28.0",
"version": "0.29.0",
"description": "Work in progress OpenTelemetry metrics SDK",

@@ -73,3 +73,3 @@ "main": "build/src/index.js",

"sinon": "11.1.2",
"ts-mocha": "8.0.0",
"ts-mocha": "9.0.2",
"typescript": "4.4.4"

@@ -81,8 +81,8 @@ },

"dependencies": {
"@opentelemetry/api-metrics": "0.28.0",
"@opentelemetry/core": "1.2.0",
"@opentelemetry/resources": "1.2.0",
"@opentelemetry/api-metrics": "0.29.0",
"@opentelemetry/core": "1.3.0",
"@opentelemetry/resources": "1.3.0",
"lodash.merge": "4.6.2"
},
"gitHead": "28a177ffe3950c5602a91391af582a7a8c813c7d"
"gitHead": "eda0b092db484855ded8b4837ba7fc19a377c5a7"
}

@@ -24,2 +24,53 @@ # OpenTelemetry Metrics SDK

## Installation of the Latest experimental version
```bash
npm install --save @opentelemetry/sdk-metrics-base
```
## Usage of the Latest experimental version
The basic setup of the SDK can be seen as followings:
```js
const opentelemetry = require('@opentelemetry/api-metrics');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
// To create an instrument, you first need to initialize the Meter provider.
// NOTE: The default OpenTelemetry meter provider does not record any metric instruments.
// Registering a working meter provider allows the API methods to record instruments.
opentelemetry.setGlobalMeterProvider(new MeterProvider());
// To record a metric event, we used the global singleton meter to create an instrument.
const counter = opentelemetry.getMeter('default').createCounter('foo');
// record a metric event.
counter.add(1, { attributeKey: 'attribute-value' });
```
In conditions, we may need to setup an async instrument to observe costly events:
```js
// Creating an async instrument, similar to synchronous instruments
const observableCounter = opentelemetry.getMeter('default')
.createObservableCounter('observable-counter');
// Register a single-instrument callback to the async instrument.
observableCounter.addCallback(async (observableResult) => {
// ... do async stuff
observableResult.observe(1, { attributeKey: 'attribute-value' });
});
// Register a multi-instrument callback and associate it with a set of async instruments.
opentelemetry.getMeter('default')
.addBatchObservableCallback(batchObservableCallback, [ observableCounter ]);
async function batchObservableCallback(batchObservableResult) {
// ... do async stuff
batchObservableResult.observe(observableCounter, 1, { attributeKey: 'attribute-value' });
// This is been dropped since the observable is not associated with the callback at registration.
batchObservableResult.observe(otherObservable, 2);
}
```
## Useful links

@@ -26,0 +77,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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc