New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/metrics

Package Overview
Dependencies
Maintainers
5
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/metrics - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

14

build/src/BoundInstrument.d.ts

@@ -26,8 +26,8 @@ /*!

private readonly _aggregator;
protected _labelSet: types.LabelSet;
protected _labels: types.Labels;
protected _logger: types.Logger;
protected _monotonic: boolean;
constructor(labelSet: types.LabelSet, logger: types.Logger, monotonic: boolean, _disabled: boolean, _valueType: types.ValueType, _aggregator: Aggregator);
constructor(labels: types.Labels, logger: types.Logger, monotonic: boolean, _disabled: boolean, _valueType: types.ValueType, _aggregator: Aggregator);
update(value: number): void;
getLabelSet(): types.LabelSet;
getLabels(): types.Labels;
getAggregator(): Aggregator;

@@ -37,6 +37,6 @@ }

* BoundCounter allows the SDK to observe/record a single metric event. The
* value of single instrument in the `Counter` associated with specified LabelSet.
* value of single instrument in the `Counter` associated with specified Labels.
*/
export declare class BoundCounter extends BaseBoundInstrument implements types.BoundCounter {
constructor(labelSet: types.LabelSet, disabled: boolean, monotonic: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
constructor(labels: types.Labels, disabled: boolean, monotonic: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
add(value: number): void;

@@ -49,3 +49,3 @@ }

private readonly _absolute;
constructor(labelSet: types.LabelSet, disabled: boolean, monotonic: boolean, absolute: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
constructor(labels: types.Labels, disabled: boolean, monotonic: boolean, absolute: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
record(value: number, correlationContext?: types.CorrelationContext, spanContext?: types.SpanContext): void;

@@ -57,4 +57,4 @@ }

export declare class BoundObserver extends BaseBoundInstrument implements types.BoundObserver {
constructor(labelSet: types.LabelSet, disabled: boolean, monotonic: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
constructor(labels: types.Labels, disabled: boolean, monotonic: boolean, valueType: types.ValueType, logger: types.Logger, aggregator: Aggregator);
setCallback(callback: (observerResult: types.ObserverResult) => {}): void;
}

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

class BaseBoundInstrument {
constructor(labelSet, logger, monotonic, _disabled, _valueType, _aggregator) {
constructor(labels, logger, monotonic, _disabled, _valueType, _aggregator) {
this._disabled = _disabled;
this._valueType = _valueType;
this._aggregator = _aggregator;
this._labelSet = labelSet;
this._labels = labels;
this._logger = logger;

@@ -38,3 +38,3 @@ this._monotonic = monotonic;

if (this._valueType === types.ValueType.INT && !Number.isInteger(value)) {
this._logger.warn(`INT value type cannot accept a floating-point value for ${Object.values(this._labelSet.labels)}, ignoring the fractional digits.`);
this._logger.warn(`INT value type cannot accept a floating-point value for ${Object.values(this._labels)}, ignoring the fractional digits.`);
value = Math.trunc(value);

@@ -44,4 +44,4 @@ }

}
getLabelSet() {
return this._labelSet;
getLabels() {
return this._labels;
}

@@ -55,11 +55,11 @@ getAggregator() {

* BoundCounter allows the SDK to observe/record a single metric event. The
* value of single instrument in the `Counter` associated with specified LabelSet.
* value of single instrument in the `Counter` associated with specified Labels.
*/
class BoundCounter extends BaseBoundInstrument {
constructor(labelSet, disabled, monotonic, valueType, logger, aggregator) {
super(labelSet, logger, monotonic, disabled, valueType, aggregator);
constructor(labels, disabled, monotonic, valueType, logger, aggregator) {
super(labels, logger, monotonic, disabled, valueType, aggregator);
}
add(value) {
if (this._monotonic && value < 0) {
this._logger.error(`Monotonic counter cannot descend for ${Object.values(this._labelSet.labels)}`);
this._logger.error(`Monotonic counter cannot descend for ${Object.values(this._labels)}`);
return;

@@ -75,4 +75,4 @@ }

class BoundMeasure extends BaseBoundInstrument {
constructor(labelSet, disabled, monotonic, absolute, valueType, logger, aggregator) {
super(labelSet, logger, monotonic, disabled, valueType, aggregator);
constructor(labels, disabled, monotonic, absolute, valueType, logger, aggregator) {
super(labels, logger, monotonic, disabled, valueType, aggregator);
this._absolute = absolute;

@@ -82,3 +82,3 @@ }

if (this._absolute && value < 0) {
this._logger.error(`Absolute measure cannot contain negative values for ${Object.values(this._labelSet.labels)}}`);
this._logger.error(`Absolute measure cannot contain negative values for $${Object.values(this._labels)}`);
return;

@@ -94,4 +94,4 @@ }

class BoundObserver extends BaseBoundInstrument {
constructor(labelSet, disabled, monotonic, valueType, logger, aggregator) {
super(labelSet, logger, monotonic, disabled, valueType, aggregator);
constructor(labels, disabled, monotonic, valueType, logger, aggregator) {
super(labels, logger, monotonic, disabled, valueType, aggregator);
}

@@ -98,0 +98,0 @@ setCallback(callback) {

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

console.log(metric.descriptor);
console.log(metric.labels.labels);
console.log(metric.labels);
switch (metric.descriptor.metricKind) {

@@ -31,0 +31,0 @@ case types_1.MetricKind.COUNTER:

@@ -16,5 +16,4 @@ /*!

*/
import { ValueType, HrTime } from '@opentelemetry/api';
import { ValueType, HrTime, Labels } from '@opentelemetry/api';
import { ExportResult } from '@opentelemetry/base';
import { LabelSet } from '../LabelSet';
/** The kind of metric. */

@@ -38,3 +37,3 @@ export declare enum MetricKind {

readonly descriptor: MetricDescriptor;
readonly labels: LabelSet;
readonly labels: Labels;
readonly aggregator: Aggregator;

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

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

*/
export * from './LabelSet';
export * from './BoundInstrument';

@@ -19,0 +18,0 @@ export * from './Meter';

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

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./LabelSet"));
__export(require("./BoundInstrument"));

@@ -24,0 +23,0 @@ __export(require("./Meter"));

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

private readonly _resource;
readonly labels: typeof Meter.labels;
/**

@@ -63,9 +62,2 @@ * Constructs a new Meter instance.

/**
* Provide a pre-computed re-useable LabelSet by
* converting the unordered labels into a canonicalized
* set of labels with an unique identifier, useful for pre-aggregation.
* @param labels user provided unordered Labels.
*/
static labels(labels: types.Labels): types.LabelSet;
/**
* Registers metric to register.

@@ -72,0 +64,0 @@ * @param name The name of the metric.

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

const types_1 = require("./types");
const LabelSet_1 = require("./LabelSet");
const Batcher_1 = require("./export/Batcher");

@@ -37,3 +36,2 @@ const Controller_1 = require("./export/Controller");

this._metrics = new Map();
this.labels = Meter.labels;
this._logger = config.logger || new core_1.ConsoleLogger(config.logLevel);

@@ -112,22 +110,2 @@ this._batcher = new Batcher_1.UngroupedBatcher();

/**
* Provide a pre-computed re-useable LabelSet by
* converting the unordered labels into a canonicalized
* set of labels with an unique identifier, useful for pre-aggregation.
* @param labels user provided unordered Labels.
*/
static labels(labels) {
const keys = Object.keys(labels).sort();
const identifier = keys.reduce((result, key) => {
if (result.length > 2) {
result += ',';
}
return (result += key + ':' + labels[key]);
}, '|#');
const sortedLabels = {};
keys.forEach(key => {
sortedLabels[key] = labels[key];
});
return new LabelSet_1.LabelSet(identifier, sortedLabels);
}
/**
* Registers metric to register.

@@ -134,0 +112,0 @@ * @param name The name of the metric.

@@ -36,14 +36,14 @@ /*!

/**
* Returns an Instrument associated with specified LabelSet.
* Returns an Instrument associated with specified Labels.
* It is recommended to keep a reference to the Instrument instead of always
* calling this method for each operation.
* @param labelSet the canonicalized LabelSet used to associate with this metric instrument.
* @param labels key-values pairs that are associated with a specific metric
* that you want to record.
*/
bind(labelSet: types.LabelSet): T;
bind(labels: types.Labels): T;
/**
* Removes the Instrument from the metric, if it is present.
* @param labelSet the canonicalized LabelSet used to associate with this
* metric instrument.
* @param labels key-values pairs that are associated with a specific metric.
*/
unbind(labelSet: types.LabelSet): void;
unbind(labels: types.Labels): void;
/**

@@ -55,3 +55,3 @@ * Clears all Instruments from the Metric.

private _getMetricDescriptor;
protected abstract _makeInstrument(labelSet: types.LabelSet): T;
protected abstract _makeInstrument(labels: types.Labels): T;
}

@@ -62,9 +62,10 @@ /** This is a SDK implementation of Counter Metric. */

constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource);
protected _makeInstrument(labelSet: types.LabelSet): BoundCounter;
protected _makeInstrument(labels: types.Labels): BoundCounter;
/**
* Adds the given value to the current value. Values cannot be negative.
* @param value the value to add.
* @param labelSet the canonicalized LabelSet used to associate with this metric's instrument.
* @param labels key-values pairs that are associated with a specific metric
* that you want to record.
*/
add(value: number, labelSet: types.LabelSet): void;
add(value: number, labels: types.Labels): void;
}

@@ -75,4 +76,4 @@ export declare class MeasureMetric extends Metric<BoundMeasure> implements Pick<types.MetricUtils, 'record'> {

constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource);
protected _makeInstrument(labelSet: types.LabelSet): BoundMeasure;
record(value: number, labelSet: types.LabelSet): void;
protected _makeInstrument(labels: types.Labels): BoundMeasure;
record(value: number, labels: types.Labels): void;
}

@@ -84,3 +85,3 @@ /** This is a SDK implementation of Observer Metric. */

constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource);
protected _makeInstrument(labelSet: types.LabelSet): BoundObserver;
protected _makeInstrument(labels: types.Labels): BoundObserver;
getMetricRecord(): MetricRecord[];

@@ -87,0 +88,0 @@ /**

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

const types_1 = require("./export/types");
const Utils_1 = require("./Utils");
/** This is a SDK implementation of {@link Metric} interface. */

@@ -37,12 +38,14 @@ class Metric {

/**
* Returns an Instrument associated with specified LabelSet.
* Returns an Instrument associated with specified Labels.
* It is recommended to keep a reference to the Instrument instead of always
* calling this method for each operation.
* @param labelSet the canonicalized LabelSet used to associate with this metric instrument.
* @param labels key-values pairs that are associated with a specific metric
* that you want to record.
*/
bind(labelSet) {
if (this._instruments.has(labelSet.identifier))
return this._instruments.get(labelSet.identifier);
const instrument = this._makeInstrument(labelSet);
this._instruments.set(labelSet.identifier, instrument);
bind(labels) {
const hash = Utils_1.hashLabels(labels);
if (this._instruments.has(hash))
return this._instruments.get(hash);
const instrument = this._makeInstrument(labels);
this._instruments.set(hash, instrument);
return instrument;

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

* Removes the Instrument from the metric, if it is present.
* @param labelSet the canonicalized LabelSet used to associate with this
* metric instrument.
* @param labels key-values pairs that are associated with a specific metric.
*/
unbind(labelSet) {
this._instruments.delete(labelSet.identifier);
unbind(labels) {
this._instruments.delete(Utils_1.hashLabels(labels));
}

@@ -68,3 +70,3 @@ /**

descriptor: this._descriptor,
labels: instrument.getLabelSet(),
labels: instrument.getLabels(),
aggregator: instrument.getAggregator(),

@@ -92,4 +94,4 @@ }));

}
_makeInstrument(labelSet) {
return new BoundInstrument_1.BoundCounter(labelSet, this._disabled, this._monotonic, this._valueType, this._logger,
_makeInstrument(labels) {
return new BoundInstrument_1.BoundCounter(labels, this._disabled, this._monotonic, this._valueType, this._logger,
// @todo: consider to set to CounterSumAggregator always.

@@ -101,6 +103,7 @@ this._batcher.aggregatorFor(types_1.MetricKind.COUNTER));

* @param value the value to add.
* @param labelSet the canonicalized LabelSet used to associate with this metric's instrument.
* @param labels key-values pairs that are associated with a specific metric
* that you want to record.
*/
add(value, labelSet) {
this.bind(labelSet).add(value);
add(value, labels) {
this.bind(labels).add(value);
}

@@ -115,7 +118,7 @@ }

}
_makeInstrument(labelSet) {
return new BoundInstrument_1.BoundMeasure(labelSet, this._disabled, this._monotonic, this._absolute, this._valueType, this._logger, this._batcher.aggregatorFor(types_1.MetricKind.MEASURE));
_makeInstrument(labels) {
return new BoundInstrument_1.BoundMeasure(labels, this._disabled, this._monotonic, this._absolute, this._valueType, this._logger, this._batcher.aggregatorFor(types_1.MetricKind.MEASURE));
}
record(value, labelSet) {
this.bind(labelSet).record(value);
record(value, labels) {
this.bind(labels).record(value);
}

@@ -131,8 +134,8 @@ }

}
_makeInstrument(labelSet) {
return new BoundInstrument_1.BoundObserver(labelSet, this._disabled, this._monotonic, this._valueType, this._logger, this._batcher.aggregatorFor(types_1.MetricKind.OBSERVER));
_makeInstrument(labels) {
return new BoundInstrument_1.BoundObserver(labels, this._disabled, this._monotonic, this._valueType, this._logger, this._batcher.aggregatorFor(types_1.MetricKind.OBSERVER));
}
getMetricRecord() {
this._observerResult.observers.forEach((callback, labelSet) => {
const instrument = this.bind(labelSet);
this._observerResult.observers.forEach((callback, labels) => {
const instrument = this.bind(labels);
instrument.update(callback());

@@ -139,0 +142,0 @@ });

@@ -16,4 +16,3 @@ /*!

*/
import { ObserverResult as TypeObserverResult } from '@opentelemetry/api';
import { LabelSet } from './LabelSet';
import { ObserverResult as TypeObserverResult, Labels } from '@opentelemetry/api';
/**

@@ -23,4 +22,4 @@ * Implementation of {@link TypeObserverResult}

export declare class ObserverResult implements TypeObserverResult {
observers: Map<LabelSet, Function>;
observe(callback: any, labelSet: LabelSet): void;
observers: Map<Labels, Function>;
observe(callback: any, labels: Labels): void;
}

@@ -25,4 +25,4 @@ "use strict";

}
observe(callback, labelSet) {
this.observers.set(labelSet, callback);
observe(callback, labels) {
this.observers.set(labels, callback);
}

@@ -29,0 +29,0 @@ }

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

*/
import { Labels } from '@opentelemetry/api';
/**

@@ -23,1 +24,6 @@ * Type guard to remove nulls from arrays

export declare function notNull<T>(value: T | null): value is T;
/**
* Converting the unordered labels into unique identifier string.
* @param labels user provided unordered Labels.
*/
export declare function hashLabels(labels: Labels): string;

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

exports.notNull = notNull;
/**
* Converting the unordered labels into unique identifier string.
* @param labels user provided unordered Labels.
*/
function hashLabels(labels) {
let keys = Object.keys(labels);
if (keys.length === 0)
return '';
keys = keys.sort();
return keys.reduce((result, key) => {
if (result.length > 2) {
result += ',';
}
return (result += key + ':' + labels[key]);
}, '|#');
}
exports.hashLabels = hashLabels;
//# sourceMappingURL=Utils.js.map

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

*/
export declare const VERSION = "0.5.2";
export declare const VERSION = "0.6.0";

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

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

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

"mocha": "^6.2.0",
"nyc": "^14.1.1",
"nyc": "^15.0.0",
"rimraf": "^3.0.0",

@@ -61,7 +61,7 @@ "sinon": "^7.5.0",

"dependencies": {
"@opentelemetry/api": "^0.5.2",
"@opentelemetry/base": "^0.5.2",
"@opentelemetry/core": "^0.5.2",
"@opentelemetry/resources": "^0.5.2"
"@opentelemetry/api": "^0.6.0",
"@opentelemetry/base": "^0.6.0",
"@opentelemetry/core": "^0.6.0",
"@opentelemetry/resources": "^0.6.0"
}
}

@@ -32,3 +32,3 @@ # OpenTelemetry Metrics SDK

const labels = meter.labels({ pid: process.pid });
const labels = { pid: process.pid };

@@ -35,0 +35,0 @@ // Create a BoundInstrument associated with specified label values.

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