Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/sdk-metrics

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/sdk-metrics - npm Package Compare versions

Comparing version 1.17.0 to 1.17.1

2

build/esm/InstrumentDescriptor.js

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

// NB: the first character counted separately from the rest.
var NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,254}$/i;
var NAME_REGEXP = /^[a-z][a-z0-9_.\-/]{0,254}$/i;
export function isValidName(name) {

@@ -65,0 +65,0 @@ return name.match(NAME_REGEXP) != null;

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

private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(measurements: AttributeHashMap<number>, observationTime: HrTime): void;

@@ -30,4 +30,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

@@ -58,7 +58,7 @@ /*

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

@@ -82,5 +82,5 @@ }

*/
AsyncMetricStorage.prototype.collect = function (collector, collectors, collectionTime) {
AsyncMetricStorage.prototype.collect = function (collector, collectionTime) {
var accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
};

@@ -87,0 +87,0 @@ return AsyncMetricStorage;

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

*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult | null>;
private _registerMetricStorage;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
scopeMetrics?: ScopeMetrics;
errors: unknown[];

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

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

return __awaiter(this, void 0, void 0, function () {
var errors, metricDataList;
var _this = this;
var errors, storages, metricDataList;
return __generator(this, function (_a) {

@@ -115,11 +114,20 @@ switch (_a.label) {

errors = _a.sent();
metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
storages = this.metricStorageRegistry.getStorages(collector);
// prevent more allocations if there are no storages.
if (storages.length === 0) {
return [2 /*return*/, null];
}
metricDataList = storages
.map(function (metricStorage) {
return metricStorage.collect(collector, _this._meterProviderSharedState.metricCollectors, collectionTime);
return metricStorage.collect(collector, collectionTime);
})
.filter(isNotNullish);
// skip this scope if no data was collected (storage created, but no data observed)
if (metricDataList.length === 0) {
return [2 /*return*/, { errors: errors }];
}
return [2 /*return*/, {
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(isNotNullish),
metrics: metricDataList,
},

@@ -142,3 +150,3 @@ errors: errors,

var aggregator = view.aggregation.createAggregator(viewDescriptor);
var viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
var viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor, _this._meterProviderSharedState.metricCollectors);
_this.metricStorageRegistry.register(viewStorage);

@@ -157,3 +165,3 @@ return viewStorage;

var aggregator = aggregation.createAggregator(descriptor);
var storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop());
var storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop(), [collector]);
_this.metricStorageRegistry.registerForCollector(collector, storage);

@@ -160,0 +168,0 @@ return storage;

@@ -52,4 +52,28 @@ /*

};
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 { millisToHrTime } from '@opentelemetry/core';
import { FlatMap } from '../utils';
/**

@@ -67,3 +91,3 @@ * An internal opaque interface that the MetricReader receives as

return __awaiter(this, void 0, void 0, function () {
var collectionTime, meterCollectionPromises, result;
var collectionTime, scopeMetrics, errors, meterCollectionPromises;
var _this = this;

@@ -74,14 +98,32 @@ return __generator(this, function (_a) {

collectionTime = millisToHrTime(Date.now());
meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(function (meterSharedState) {
return meterSharedState.collect(_this, collectionTime, options);
});
scopeMetrics = [];
errors = [];
meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(function (meterSharedState) { return __awaiter(_this, void 0, void 0, function () {
var current;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, meterSharedState.collect(this, collectionTime, options)];
case 1:
current = _a.sent();
// only add scope metrics if available
if ((current === null || current === void 0 ? void 0 : current.scopeMetrics) != null) {
scopeMetrics.push(current.scopeMetrics);
}
// only add errors if available
if ((current === null || current === void 0 ? void 0 : current.errors) != null) {
errors.push.apply(errors, __spreadArray([], __read(current.errors), false));
}
return [2 /*return*/];
}
});
}); });
return [4 /*yield*/, Promise.all(meterCollectionPromises)];
case 1:
result = _a.sent();
_a.sent();
return [2 /*return*/, {
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(function (it) { return it.scopeMetrics; }),
scopeMetrics: scopeMetrics,
},
errors: FlatMap(result, function (it) { return it.errors; }),
errors: errors,
}];

@@ -88,0 +130,0 @@ }

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

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

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

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

private _temporalMetricStorage;
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(value: number, attributes: MetricAttributes, context: Context, recordTime: HrTime): void;

@@ -28,4 +28,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

@@ -41,7 +41,7 @@ /*

__extends(SyncMetricStorage, _super);
function SyncMetricStorage(instrumentDescriptor, aggregator, _attributesProcessor) {
function SyncMetricStorage(instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
var _this = _super.call(this, instrumentDescriptor) || this;
_this._attributesProcessor = _attributesProcessor;
_this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
_this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
_this._temporalMetricStorage = new TemporalMetricProcessor(aggregator, collectorHandles);
return _this;

@@ -59,5 +59,5 @@ }

*/
SyncMetricStorage.prototype.collect = function (collector, collectors, collectionTime) {
SyncMetricStorage.prototype.collect = function (collector, collectionTime) {
var accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
};

@@ -64,0 +64,0 @@ return SyncMetricStorage;

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

private _reportHistory;
constructor(_aggregator: Aggregator<T>);
constructor(_aggregator: Aggregator<T>, collectorHandles: MetricCollectorHandle[]);
/**

@@ -29,3 +29,3 @@ * Builds the {@link MetricData} streams to report against a specific MetricCollector.

*/
buildMetrics(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
buildMetrics(collector: MetricCollectorHandle, instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
private _stashAccumulations;

@@ -32,0 +32,0 @@ private _getMergedUnreportedAccumulations;

@@ -52,6 +52,10 @@ /*

var TemporalMetricProcessor = /** @class */ (function () {
function TemporalMetricProcessor(_aggregator) {
function TemporalMetricProcessor(_aggregator, collectorHandles) {
var _this = this;
this._aggregator = _aggregator;
this._unreportedAccumulations = new Map();
this._reportHistory = new Map();
collectorHandles.forEach(function (handle) {
_this._unreportedAccumulations.set(handle, []);
});
}

@@ -67,4 +71,4 @@ /**

*/
TemporalMetricProcessor.prototype.buildMetrics = function (collector, collectors, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(collectors, currentAccumulations);
TemporalMetricProcessor.prototype.buildMetrics = function (collector, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(currentAccumulations);
var unreportedAccumulations = this._getMergedUnreportedAccumulations(collector);

@@ -110,18 +114,34 @@ var result = unreportedAccumulations;

});
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
var accumulationRecords = AttributesMapToAccumulationRecords(result);
// do not convert to metric data if there is nothing to convert.
if (accumulationRecords.length === 0) {
return undefined;
}
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, accumulationRecords,
/* endTime */ collectionTime);
};
TemporalMetricProcessor.prototype._stashAccumulations = function (collectors, currentAccumulation) {
var _this = this;
collectors.forEach(function (it) {
var stash = _this._unreportedAccumulations.get(it);
if (stash === undefined) {
stash = [];
_this._unreportedAccumulations.set(it, stash);
TemporalMetricProcessor.prototype._stashAccumulations = function (currentAccumulation) {
var e_1, _a;
var registeredCollectors = this._unreportedAccumulations.keys();
try {
for (var registeredCollectors_1 = __values(registeredCollectors), registeredCollectors_1_1 = registeredCollectors_1.next(); !registeredCollectors_1_1.done; registeredCollectors_1_1 = registeredCollectors_1.next()) {
var collector = registeredCollectors_1_1.value;
var stash = this._unreportedAccumulations.get(collector);
if (stash === undefined) {
stash = [];
this._unreportedAccumulations.set(collector, stash);
}
stash.push(currentAccumulation);
}
stash.push(currentAccumulation);
});
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (registeredCollectors_1_1 && !registeredCollectors_1_1.done && (_a = registeredCollectors_1.return)) _a.call(registeredCollectors_1);
}
finally { if (e_1) throw e_1.error; }
}
};
TemporalMetricProcessor.prototype._getMergedUnreportedAccumulations = function (collector) {
var e_1, _a;
var e_2, _a;
var result = new AttributeHashMap();

@@ -139,3 +159,3 @@ var unreportedList = this._unreportedAccumulations.get(collector);

}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {

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

}
finally { if (e_1) throw e_1.error; }
finally { if (e_2) throw e_2.error; }
}

@@ -175,3 +195,3 @@ return result;

TemporalMetricProcessor.calibrateStartTime = function (last, current, lastCollectionTime) {
var e_2, _a;
var e_3, _a;
try {

@@ -184,3 +204,3 @@ for (var _b = __values(last.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {

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

@@ -190,3 +210,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -193,0 +213,0 @@ return current;

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

export declare const VERSION = "1.17.0";
export declare const VERSION = "1.17.1";
//# sourceMappingURL=version.d.ts.map

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

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

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

// NB: the first character counted separately from the rest.
const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,254}$/i;
const NAME_REGEXP = /^[a-z][a-z0-9_.\-/]{0,254}$/i;
export function isValidName(name) {

@@ -65,0 +65,0 @@ return name.match(NAME_REGEXP) != null;

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

private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(measurements: AttributeHashMap<number>, observationTime: HrTime): void;

@@ -30,4 +30,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

@@ -26,7 +26,7 @@ /*

export class AsyncMetricStorage extends MetricStorage {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor) {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
super(_instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator, collectorHandles);
}

@@ -47,7 +47,7 @@ record(measurements, observationTime) {

*/
collect(collector, collectors, collectionTime) {
collect(collector, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
}
}
//# sourceMappingURL=AsyncMetricStorage.js.map

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

*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult | null>;
private _registerMetricStorage;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
scopeMetrics?: ScopeMetrics;
errors: unknown[];

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

@@ -59,11 +59,20 @@ /*

const errors = await this.observableRegistry.observe(collectionTime, options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
const storages = this.metricStorageRegistry.getStorages(collector);
// prevent more allocations if there are no storages.
if (storages.length === 0) {
return null;
}
const metricDataList = storages
.map(metricStorage => {
return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, collectionTime);
return metricStorage.collect(collector, collectionTime);
})
.filter(isNotNullish);
// skip this scope if no data was collected (storage created, but no data observed)
if (metricDataList.length === 0) {
return { errors };
}
return {
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(isNotNullish),
metrics: metricDataList,
},

@@ -82,3 +91,3 @@ errors,

const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor, this._meterProviderSharedState.metricCollectors);
this.metricStorageRegistry.register(viewStorage);

@@ -96,3 +105,3 @@ return viewStorage;

const aggregator = aggregation.createAggregator(descriptor);
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop());
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor.Noop(), [collector]);
this.metricStorageRegistry.registerForCollector(collector, storage);

@@ -99,0 +108,0 @@ return storage;

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

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

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

const collectionTime = millisToHrTime(Date.now());
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(meterSharedState => meterSharedState.collect(this, collectionTime, options));
const result = await Promise.all(meterCollectionPromises);
const scopeMetrics = [];
const errors = [];
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(async (meterSharedState) => {
const current = await meterSharedState.collect(this, collectionTime, options);
// only add scope metrics if available
if ((current === null || current === void 0 ? void 0 : current.scopeMetrics) != null) {
scopeMetrics.push(current.scopeMetrics);
}
// only add errors if available
if ((current === null || current === void 0 ? void 0 : current.errors) != null) {
errors.push(...current.errors);
}
});
await Promise.all(meterCollectionPromises);
return {
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(it => it.scopeMetrics),
scopeMetrics: scopeMetrics,
},
errors: FlatMap(result, it => it.errors),
errors: errors,
};

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

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

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

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

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

private _temporalMetricStorage;
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(value: number, attributes: MetricAttributes, context: Context, recordTime: HrTime): void;

@@ -28,4 +28,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

@@ -25,7 +25,7 @@ /*

export class SyncMetricStorage extends MetricStorage {
constructor(instrumentDescriptor, aggregator, _attributesProcessor) {
constructor(instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
super(instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator, collectorHandles);
}

@@ -42,7 +42,7 @@ record(value, attributes, context, recordTime) {

*/
collect(collector, collectors, collectionTime) {
collect(collector, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
}
}
//# sourceMappingURL=SyncMetricStorage.js.map

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

private _reportHistory;
constructor(_aggregator: Aggregator<T>);
constructor(_aggregator: Aggregator<T>, collectorHandles: MetricCollectorHandle[]);
/**

@@ -29,3 +29,3 @@ * Builds the {@link MetricData} streams to report against a specific MetricCollector.

*/
buildMetrics(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
buildMetrics(collector: MetricCollectorHandle, instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
private _stashAccumulations;

@@ -32,0 +32,0 @@ private _getMergedUnreportedAccumulations;

@@ -25,6 +25,9 @@ /*

export class TemporalMetricProcessor {
constructor(_aggregator) {
constructor(_aggregator, collectorHandles) {
this._aggregator = _aggregator;
this._unreportedAccumulations = new Map();
this._reportHistory = new Map();
collectorHandles.forEach(handle => {
this._unreportedAccumulations.set(handle, []);
});
}

@@ -40,4 +43,4 @@ /**

*/
buildMetrics(collector, collectors, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(collectors, currentAccumulations);
buildMetrics(collector, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(currentAccumulations);
const unreportedAccumulations = this._getMergedUnreportedAccumulations(collector);

@@ -83,14 +86,20 @@ let result = unreportedAccumulations;

});
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
const accumulationRecords = AttributesMapToAccumulationRecords(result);
// do not convert to metric data if there is nothing to convert.
if (accumulationRecords.length === 0) {
return undefined;
}
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, accumulationRecords,
/* endTime */ collectionTime);
}
_stashAccumulations(collectors, currentAccumulation) {
collectors.forEach(it => {
let stash = this._unreportedAccumulations.get(it);
_stashAccumulations(currentAccumulation) {
const registeredCollectors = this._unreportedAccumulations.keys();
for (const collector of registeredCollectors) {
let stash = this._unreportedAccumulations.get(collector);
if (stash === undefined) {
stash = [];
this._unreportedAccumulations.set(it, stash);
this._unreportedAccumulations.set(collector, stash);
}
stash.push(currentAccumulation);
});
}
}

@@ -97,0 +106,0 @@ _getMergedUnreportedAccumulations(collector) {

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

export declare const VERSION = "1.17.0";
export declare const VERSION = "1.17.1";
//# sourceMappingURL=version.d.ts.map

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

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

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

// NB: the first character counted separately from the rest.
const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,254}$/i;
const NAME_REGEXP = /^[a-z][a-z0-9_.\-/]{0,254}$/i;
function isValidName(name) {

@@ -71,0 +71,0 @@ return name.match(NAME_REGEXP) != null;

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

private _temporalMetricStorage;
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(_instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(measurements: AttributeHashMap<number>, observationTime: HrTime): void;

@@ -30,4 +30,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=AsyncMetricStorage.d.ts.map

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

class AsyncMetricStorage extends MetricStorage_1.MetricStorage {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor) {
constructor(_instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
super(_instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor_1.DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator, collectorHandles);
}

@@ -50,5 +50,5 @@ record(measurements, observationTime) {

*/
collect(collector, collectors, collectionTime) {
collect(collector, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
}

@@ -55,0 +55,0 @@ }

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

*/
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime, options?: MetricCollectOptions): Promise<ScopeMetricsResult | null>;
private _registerMetricStorage;
}
interface ScopeMetricsResult {
scopeMetrics: ScopeMetrics;
scopeMetrics?: ScopeMetrics;
errors: unknown[];

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

@@ -62,11 +62,20 @@ "use strict";

const errors = await this.observableRegistry.observe(collectionTime, options === null || options === void 0 ? void 0 : options.timeoutMillis);
const metricDataList = Array.from(this.metricStorageRegistry.getStorages(collector))
const storages = this.metricStorageRegistry.getStorages(collector);
// prevent more allocations if there are no storages.
if (storages.length === 0) {
return null;
}
const metricDataList = storages
.map(metricStorage => {
return metricStorage.collect(collector, this._meterProviderSharedState.metricCollectors, collectionTime);
return metricStorage.collect(collector, collectionTime);
})
.filter(utils_1.isNotNullish);
// skip this scope if no data was collected (storage created, but no data observed)
if (metricDataList.length === 0) {
return { errors };
}
return {
scopeMetrics: {
scope: this._instrumentationScope,
metrics: metricDataList.filter(utils_1.isNotNullish),
metrics: metricDataList,
},

@@ -85,3 +94,3 @@ errors,

const aggregator = view.aggregation.createAggregator(viewDescriptor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor);
const viewStorage = new MetricStorageType(viewDescriptor, aggregator, view.attributesProcessor, this._meterProviderSharedState.metricCollectors);
this.metricStorageRegistry.register(viewStorage);

@@ -99,3 +108,3 @@ return viewStorage;

const aggregator = aggregation.createAggregator(descriptor);
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor_1.AttributesProcessor.Noop());
const storage = new MetricStorageType(descriptor, aggregator, AttributesProcessor_1.AttributesProcessor.Noop(), [collector]);
this.metricStorageRegistry.registerForCollector(collector, storage);

@@ -102,0 +111,0 @@ return storage;

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

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

@@ -34,10 +33,22 @@ * An internal opaque interface that the MetricReader receives as

const collectionTime = (0, core_1.millisToHrTime)(Date.now());
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(meterSharedState => meterSharedState.collect(this, collectionTime, options));
const result = await Promise.all(meterCollectionPromises);
const scopeMetrics = [];
const errors = [];
const meterCollectionPromises = Array.from(this._sharedState.meterSharedStates.values()).map(async (meterSharedState) => {
const current = await meterSharedState.collect(this, collectionTime, options);
// only add scope metrics if available
if ((current === null || current === void 0 ? void 0 : current.scopeMetrics) != null) {
scopeMetrics.push(current.scopeMetrics);
}
// only add errors if available
if ((current === null || current === void 0 ? void 0 : current.errors) != null) {
errors.push(...current.errors);
}
});
await Promise.all(meterCollectionPromises);
return {
resourceMetrics: {
resource: this._sharedState.resource,
scopeMetrics: result.map(it => it.scopeMetrics),
scopeMetrics: scopeMetrics,
},
errors: (0, utils_1.FlatMap)(result, it => it.errors),
errors: errors,
};

@@ -44,0 +55,0 @@ }

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

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

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

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

private _temporalMetricStorage;
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor);
constructor(instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator<T>, _attributesProcessor: AttributesProcessor, collectorHandles: MetricCollectorHandle[]);
record(value: number, attributes: MetricAttributes, context: Context, recordTime: HrTime): void;

@@ -28,4 +28,4 @@ /**

*/
collect(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], collectionTime: HrTime): Maybe<MetricData>;
collect(collector: MetricCollectorHandle, collectionTime: HrTime): Maybe<MetricData>;
}
//# sourceMappingURL=SyncMetricStorage.d.ts.map

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

class SyncMetricStorage extends MetricStorage_1.MetricStorage {
constructor(instrumentDescriptor, aggregator, _attributesProcessor) {
constructor(instrumentDescriptor, aggregator, _attributesProcessor, collectorHandles) {
super(instrumentDescriptor);
this._attributesProcessor = _attributesProcessor;
this._deltaMetricStorage = new DeltaMetricProcessor_1.DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor_1.TemporalMetricProcessor(aggregator, collectorHandles);
}

@@ -45,5 +45,5 @@ record(value, attributes, context, recordTime) {

*/
collect(collector, collectors, collectionTime) {
collect(collector, collectionTime) {
const accumulations = this._deltaMetricStorage.collect();
return this._temporalMetricStorage.buildMetrics(collector, collectors, this._instrumentDescriptor, accumulations, collectionTime);
return this._temporalMetricStorage.buildMetrics(collector, this._instrumentDescriptor, accumulations, collectionTime);
}

@@ -50,0 +50,0 @@ }

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

private _reportHistory;
constructor(_aggregator: Aggregator<T>);
constructor(_aggregator: Aggregator<T>, collectorHandles: MetricCollectorHandle[]);
/**

@@ -29,3 +29,3 @@ * Builds the {@link MetricData} streams to report against a specific MetricCollector.

*/
buildMetrics(collector: MetricCollectorHandle, collectors: MetricCollectorHandle[], instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
buildMetrics(collector: MetricCollectorHandle, instrumentDescriptor: InstrumentDescriptor, currentAccumulations: AttributeHashMap<T>, collectionTime: HrTime): Maybe<MetricData>;
private _stashAccumulations;

@@ -32,0 +32,0 @@ private _getMergedUnreportedAccumulations;

@@ -28,6 +28,9 @@ "use strict";

class TemporalMetricProcessor {
constructor(_aggregator) {
constructor(_aggregator, collectorHandles) {
this._aggregator = _aggregator;
this._unreportedAccumulations = new Map();
this._reportHistory = new Map();
collectorHandles.forEach(handle => {
this._unreportedAccumulations.set(handle, []);
});
}

@@ -43,4 +46,4 @@ /**

*/
buildMetrics(collector, collectors, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(collectors, currentAccumulations);
buildMetrics(collector, instrumentDescriptor, currentAccumulations, collectionTime) {
this._stashAccumulations(currentAccumulations);
const unreportedAccumulations = this._getMergedUnreportedAccumulations(collector);

@@ -86,14 +89,20 @@ let result = unreportedAccumulations;

});
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, AttributesMapToAccumulationRecords(result),
const accumulationRecords = AttributesMapToAccumulationRecords(result);
// do not convert to metric data if there is nothing to convert.
if (accumulationRecords.length === 0) {
return undefined;
}
return this._aggregator.toMetricData(instrumentDescriptor, aggregationTemporality, accumulationRecords,
/* endTime */ collectionTime);
}
_stashAccumulations(collectors, currentAccumulation) {
collectors.forEach(it => {
let stash = this._unreportedAccumulations.get(it);
_stashAccumulations(currentAccumulation) {
const registeredCollectors = this._unreportedAccumulations.keys();
for (const collector of registeredCollectors) {
let stash = this._unreportedAccumulations.get(collector);
if (stash === undefined) {
stash = [];
this._unreportedAccumulations.set(it, stash);
this._unreportedAccumulations.set(collector, stash);
}
stash.push(currentAccumulation);
});
}
}

@@ -100,0 +109,0 @@ _getMergedUnreportedAccumulations(collector) {

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

export declare const VERSION = "1.17.0";
export declare const VERSION = "1.17.1";
//# sourceMappingURL=version.d.ts.map

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

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '1.17.0';
exports.VERSION = '1.17.1';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/sdk-metrics",
"version": "1.17.0",
"version": "1.17.1",
"description": "OpenTelemetry metrics SDK",

@@ -57,8 +57,8 @@ "main": "build/src/index.js",

"devDependencies": {
"@babel/core": "7.22.17",
"@babel/core": "7.22.20",
"@opentelemetry/api": ">=1.3.0 <1.7.0",
"@types/lodash.merge": "4.6.7",
"@types/mocha": "10.0.1",
"@types/mocha": "10.0.2",
"@types/node": "18.6.5",
"@types/sinon": "10.0.16",
"@types/sinon": "10.0.18",
"babel-plugin-istanbul": "6.1.1",

@@ -88,4 +88,4 @@ "codecov": "3.8.3",

"dependencies": {
"@opentelemetry/core": "1.17.0",
"@opentelemetry/resources": "1.17.0",
"@opentelemetry/core": "1.17.1",
"@opentelemetry/resources": "1.17.1",
"lodash.merge": "^4.6.2"

@@ -95,3 +95,3 @@ },

"sideEffects": false,
"gitHead": "faf939c77591f709afbc23fadbe629c9d3607ef6"
"gitHead": "f8e187b473274cc2011e7385992f07d319d667dc"
}

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