@opentelemetry/metrics
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -12,3 +12,3 @@ import * as api from '@opentelemetry/api'; | ||
* long to update. For example to avoid update after timeout. | ||
* See {@link BatchObserverMetric.getMetricRecord} | ||
* See {@link BatchObserver.collect} | ||
*/ | ||
@@ -15,0 +15,0 @@ cancelled: boolean; |
@@ -28,3 +28,3 @@ "use strict"; | ||
* long to update. For example to avoid update after timeout. | ||
* See {@link BatchObserverMetric.getMetricRecord} | ||
* See {@link BatchObserver.collect} | ||
*/ | ||
@@ -31,0 +31,0 @@ this.cancelled = false; |
import * as api from '@opentelemetry/api'; | ||
import { InstrumentationLibrary } from '@opentelemetry/core'; | ||
import { BatchObserver } from './BatchObserver'; | ||
import { Processor } from './export/Processor'; | ||
@@ -10,2 +11,3 @@ import { MeterConfig } from './types'; | ||
private readonly _logger; | ||
private readonly _batchObservers; | ||
private readonly _metrics; | ||
@@ -63,8 +65,7 @@ private readonly _processor; | ||
/** | ||
* Creates a new batch observer metric. | ||
* @param name the name of the metric. | ||
* Creates a new batch observer. | ||
* @param callback the batch observer callback | ||
* @param [options] the metric batch options. | ||
* @param [options] the batch options. | ||
*/ | ||
createBatchObserver(name: string, callback: (observerResult: api.BatchObserverResult) => void, options?: api.BatchMetricOptions): api.BatchObserver; | ||
createBatchObserver(callback: (observerResult: api.BatchObserverResult) => void, options?: api.BatchObserverOptions): BatchObserver; | ||
/** | ||
@@ -71,0 +72,0 @@ * Collects all the metrics created with this `Meter` for export. |
@@ -22,4 +22,3 @@ "use strict"; | ||
const resources_1 = require("@opentelemetry/resources"); | ||
const BatchObserverMetric_1 = require("./BatchObserverMetric"); | ||
const types_1 = require("./export/types"); | ||
const BatchObserver_1 = require("./BatchObserver"); | ||
const UpDownCounterMetric_1 = require("./UpDownCounterMetric"); | ||
@@ -31,3 +30,3 @@ const CounterMetric_1 = require("./CounterMetric"); | ||
const SumObserverMetric_1 = require("./SumObserverMetric"); | ||
const types_2 = require("./types"); | ||
const types_1 = require("./types"); | ||
const Processor_1 = require("./export/Processor"); | ||
@@ -43,4 +42,5 @@ const Controller_1 = require("./export/Controller"); | ||
*/ | ||
constructor(instrumentationLibrary, config = types_2.DEFAULT_CONFIG) { | ||
constructor(instrumentationLibrary, config = types_1.DEFAULT_CONFIG) { | ||
var _a; | ||
this._batchObservers = []; | ||
this._metrics = new Map(); | ||
@@ -68,3 +68,3 @@ this._isShutdown = false; | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_1.DEFAULT_METRIC_OPTIONS), options); | ||
const valueRecorder = new ValueRecorderMetric_1.ValueRecorderMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary); | ||
@@ -86,3 +86,3 @@ this._registerMetric(name, valueRecorder); | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_1.DEFAULT_METRIC_OPTIONS), options); | ||
const counter = new CounterMetric_1.CounterMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary); | ||
@@ -107,3 +107,3 @@ this._registerMetric(name, counter); | ||
} | ||
const opt = Object.assign(Object.assign(Object.assign({}, types_2.DEFAULT_METRIC_OPTIONS), { logger: this._logger }), options); | ||
const opt = Object.assign(Object.assign(Object.assign({}, types_1.DEFAULT_METRIC_OPTIONS), { logger: this._logger }), options); | ||
const upDownCounter = new UpDownCounterMetric_1.UpDownCounterMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary); | ||
@@ -124,3 +124,3 @@ this._registerMetric(name, upDownCounter); | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_1.DEFAULT_METRIC_OPTIONS), options); | ||
const valueObserver = new ValueObserverMetric_1.ValueObserverMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary, callback); | ||
@@ -135,3 +135,3 @@ this._registerMetric(name, valueObserver); | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_1.DEFAULT_METRIC_OPTIONS), options); | ||
const sumObserver = new SumObserverMetric_1.SumObserverMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary, callback); | ||
@@ -152,3 +152,3 @@ this._registerMetric(name, sumObserver); | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_1.DEFAULT_METRIC_OPTIONS), options); | ||
const upDownSumObserver = new UpDownSumObserverMetric_1.UpDownSumObserverMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary, callback); | ||
@@ -159,15 +159,10 @@ this._registerMetric(name, upDownSumObserver); | ||
/** | ||
* Creates a new batch observer metric. | ||
* @param name the name of the metric. | ||
* Creates a new batch observer. | ||
* @param callback the batch observer callback | ||
* @param [options] the metric batch options. | ||
* @param [options] the batch options. | ||
*/ | ||
createBatchObserver(name, callback, options = {}) { | ||
if (!this._isValidName(name)) { | ||
this._logger.warn(`Invalid metric name ${name}. Defaulting to noop metric implementation.`); | ||
return api.NOOP_BATCH_OBSERVER_METRIC; | ||
} | ||
const opt = Object.assign(Object.assign({ logger: this._logger }, types_2.DEFAULT_METRIC_OPTIONS), options); | ||
const batchObserver = new BatchObserverMetric_1.BatchObserverMetric(name, opt, this._processor, this._resource, this._instrumentationLibrary, callback); | ||
this._registerMetric(name, batchObserver); | ||
createBatchObserver(callback, options = {}) { | ||
const opt = Object.assign({ logger: this._logger }, options); | ||
const batchObserver = new BatchObserver_1.BatchObserver(opt, callback); | ||
this._batchObservers.push(batchObserver); | ||
return batchObserver; | ||
@@ -184,20 +179,8 @@ } | ||
// call batch observers first | ||
const batchObservers = Array.from(this._metrics.values()) | ||
.filter(metric => { | ||
return metric.getKind() === types_1.MetricKind.BATCH_OBSERVER; | ||
}) | ||
.map(metric => { | ||
return metric.getMetricRecord(); | ||
const observations = this._batchObservers.map(observer => { | ||
return observer.collect(); | ||
}); | ||
await Promise.all(batchObservers).then(records => { | ||
records.forEach(metrics => { | ||
metrics.forEach(metric => this._processor.process(metric)); | ||
}); | ||
}); | ||
await Promise.all(observations); | ||
// after this all remaining metrics can be run | ||
const metrics = Array.from(this._metrics.values()) | ||
.filter(metric => { | ||
return metric.getKind() !== types_1.MetricKind.BATCH_OBSERVER; | ||
}) | ||
.map(metric => { | ||
const metrics = Array.from(this._metrics.values()).map(metric => { | ||
return metric.getMetricRecord(); | ||
@@ -204,0 +187,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.13.0"; | ||
export declare const VERSION = "0.14.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.13.0'; | ||
exports.VERSION = '0.14.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/metrics", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "OpenTelemetry metrics SDK", | ||
@@ -45,4 +45,4 @@ "main": "build/src/index.js", | ||
"devDependencies": { | ||
"@types/mocha": "8.0.4", | ||
"@types/node": "14.14.10", | ||
"@types/mocha": "8.2.0", | ||
"@types/node": "14.14.12", | ||
"@types/sinon": "9.0.9", | ||
@@ -54,13 +54,13 @@ "codecov": "3.8.1", | ||
"rimraf": "3.0.2", | ||
"sinon": "9.2.1", | ||
"sinon": "9.2.2", | ||
"ts-mocha": "8.0.0", | ||
"ts-node": "9.0.0", | ||
"ts-node": "9.1.1", | ||
"typescript": "3.9.7" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.13.0", | ||
"@opentelemetry/core": "^0.13.0", | ||
"@opentelemetry/resources": "^0.13.0" | ||
"@opentelemetry/api": "^0.14.0", | ||
"@opentelemetry/core": "^0.14.0", | ||
"@opentelemetry/resources": "^0.14.0" | ||
}, | ||
"gitHead": "86cbd6798f9318c5920f9d9055f289a1c3f26500" | ||
"gitHead": "27a8d4530c56257c191468b073669909bf8892a1" | ||
} |
@@ -225,3 +225,3 @@ # OpenTelemetry Metrics SDK | ||
meter.createBatchObserver('metric_batch_observer', (observerBatchResult) => { | ||
meter.createBatchObserver((observerBatchResult) => { | ||
getSomeAsyncMetrics().then(metrics => { | ||
@@ -228,0 +228,0 @@ observerBatchResult.observe({ app: 'myApp' }, [ |
Sorry, the diff of this file is not supported yet
134686
2043
+ Added@opentelemetry/api@0.14.0(transitive)
+ Added@opentelemetry/context-base@0.14.0(transitive)
+ Added@opentelemetry/core@0.14.0(transitive)
+ Added@opentelemetry/resources@0.14.0(transitive)
- Removed@opentelemetry/api@0.13.0(transitive)
- Removed@opentelemetry/context-base@0.13.0(transitive)
- Removed@opentelemetry/core@0.13.0(transitive)
- Removed@opentelemetry/resources@0.13.0(transitive)
Updated@opentelemetry/api@^0.14.0
Updated@opentelemetry/core@^0.14.0