@boxyhq/metrics 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.ts +2 -2
- package/dist/init.js +3 -4
- package/dist/instruments/counter.d.ts +9 -4
- package/dist/instruments/gauge.d.ts +9 -4
- package/dist/instruments/gauge.js +1 -1
- package/dist/instruments/histogram.d.ts +9 -4
- package/dist/instruments/index.d.ts +5 -5
- package/dist/instruments/index.js +19 -12
- package/dist/instruments/instrument.d.ts +9 -4
- package/dist/instruments/instrument.js +29 -25
- package/dist/instruments/timer.d.ts +9 -4
- package/dist/instruments/timer.js +2 -2
- package/package.json +10 -8
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './init';
|
|
2
|
+
export * from './instruments';
|
package/dist/init.js
CHANGED
|
@@ -13,8 +13,7 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
13
13
|
* See https://opentelemetry.io/docs/instrumentation/js/instrumentation/#initialize-metrics
|
|
14
14
|
*/
|
|
15
15
|
function initializeMetrics(serviceInfo) {
|
|
16
|
-
if (process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ||
|
|
17
|
-
process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
|
|
16
|
+
if (process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
|
|
18
17
|
const meterProvider = new sdk_metrics_1.MeterProvider({
|
|
19
18
|
resource: new resources_1.Resource({
|
|
20
19
|
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: `${serviceInfo.name}`,
|
|
@@ -22,8 +21,8 @@ function initializeMetrics(serviceInfo) {
|
|
|
22
21
|
}),
|
|
23
22
|
});
|
|
24
23
|
let metricExporter;
|
|
25
|
-
if (process.env.OTEL_EXPORTER_OTLP_PROTOCOL ===
|
|
26
|
-
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL ===
|
|
24
|
+
if (process.env.OTEL_EXPORTER_OTLP_PROTOCOL === 'grpc' ||
|
|
25
|
+
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL === 'grpc') {
|
|
27
26
|
metricExporter = new exporter_metrics_otlp_grpc_1.OTLPMetricExporter();
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { Attributes, MetricOptions } from
|
|
2
|
-
type
|
|
1
|
+
import type { Attributes, MetricOptions } from '@opentelemetry/api';
|
|
2
|
+
type CounterOperationParams = {
|
|
3
|
+
/** OTel meter name */
|
|
3
4
|
meter: string;
|
|
5
|
+
/** Metric name being instrumented */
|
|
4
6
|
name: string;
|
|
7
|
+
/** Value by which counter is incremented, defaults to 1 */
|
|
5
8
|
inc?: number;
|
|
9
|
+
/** MetricOptions such as unit */
|
|
6
10
|
counterOptions?: MetricOptions;
|
|
11
|
+
/** Metric Attributes in the form of key value pairs */
|
|
7
12
|
counterAttributes?: Attributes;
|
|
8
13
|
};
|
|
9
|
-
declare const incrementCounter: ({ meter, name, inc, counterOptions, counterAttributes, }:
|
|
10
|
-
export { incrementCounter };
|
|
14
|
+
declare const incrementCounter: ({ meter, name, inc, counterOptions, counterAttributes, }: CounterOperationParams) => void;
|
|
15
|
+
export { incrementCounter, type CounterOperationParams };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { Attributes, MetricOptions } from
|
|
2
|
-
type
|
|
1
|
+
import type { Attributes, MetricOptions } from '@opentelemetry/api';
|
|
2
|
+
type GaugeOperationParams = {
|
|
3
|
+
/** OTel meter name */
|
|
3
4
|
meter: string;
|
|
5
|
+
/** Metric name being instrumented */
|
|
4
6
|
name: string;
|
|
7
|
+
/** Non-additive value observed at a point in time */
|
|
5
8
|
val: number;
|
|
9
|
+
/** MetricOptions such as unit */
|
|
6
10
|
gaugeOptions?: MetricOptions;
|
|
11
|
+
/** Metric Attributes in the form of key value pairs */
|
|
7
12
|
gaugeAttributes?: Attributes;
|
|
8
13
|
};
|
|
9
|
-
declare const observeGauge: ({ meter, name, val, gaugeOptions, gaugeAttributes
|
|
10
|
-
export { observeGauge };
|
|
14
|
+
declare const observeGauge: ({ meter, name, val, gaugeOptions, gaugeAttributes }: GaugeOperationParams) => void;
|
|
15
|
+
export { observeGauge, type GaugeOperationParams };
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.observeGauge = void 0;
|
|
4
4
|
const meter_1 = require("../lib/meter");
|
|
5
5
|
const gauges = {};
|
|
6
|
-
const observeGauge = ({ meter, name, val, gaugeOptions, gaugeAttributes
|
|
6
|
+
const observeGauge = ({ meter, name, val, gaugeOptions, gaugeAttributes }) => {
|
|
7
7
|
let gauge = gauges[name];
|
|
8
8
|
if (gauge === undefined) {
|
|
9
9
|
const _otelMeter = (0, meter_1.acquireMeter)(meter);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { Attributes, MetricOptions } from
|
|
2
|
-
type
|
|
1
|
+
import type { Attributes, MetricOptions } from '@opentelemetry/api';
|
|
2
|
+
type HistogramOperationParams = {
|
|
3
|
+
/** OTel meter name */
|
|
3
4
|
meter: string;
|
|
5
|
+
/** Metric name being instrumented */
|
|
4
6
|
name: string;
|
|
7
|
+
/** Value to be recorded */
|
|
5
8
|
val: number;
|
|
9
|
+
/** MetricOptions such as unit */
|
|
6
10
|
histogramOptions?: MetricOptions;
|
|
11
|
+
/** Metric Attributes in the form of key value pairs */
|
|
7
12
|
histogramAttributes?: Attributes;
|
|
8
13
|
};
|
|
9
|
-
declare const recordHistogram: ({ meter, name, val, histogramOptions, histogramAttributes, }:
|
|
10
|
-
export { recordHistogram };
|
|
14
|
+
declare const recordHistogram: ({ meter, name, val, histogramOptions, histogramAttributes, }: HistogramOperationParams) => void;
|
|
15
|
+
export { recordHistogram, type HistogramOperationParams };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export * from './counter';
|
|
2
|
+
export * from './gauge';
|
|
3
|
+
export * from './histogram';
|
|
4
|
+
export * from './timer';
|
|
5
|
+
export * from './instrument';
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var histogram_1 = require("./histogram");
|
|
9
|
-
Object.defineProperty(exports, "recordHistogram", { enumerable: true, get: function () { return histogram_1.recordHistogram; } });
|
|
10
|
-
var timer_1 = require("./timer");
|
|
11
|
-
Object.defineProperty(exports, "recordTimer", { enumerable: true, get: function () { return timer_1.recordTimer; } });
|
|
12
|
-
var instrument_1 = require("./instrument");
|
|
13
|
-
Object.defineProperty(exports, "instrument", { enumerable: true, get: function () { return instrument_1.instrument; } });
|
|
14
|
-
Object.defineProperty(exports, "instrumented", { enumerable: true, get: function () { return instrument_1.instrumented; } });
|
|
17
|
+
__exportStar(require("./counter"), exports);
|
|
18
|
+
__exportStar(require("./gauge"), exports);
|
|
19
|
+
__exportStar(require("./histogram"), exports);
|
|
20
|
+
__exportStar(require("./timer"), exports);
|
|
21
|
+
__exportStar(require("./instrument"), exports);
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { Attributes } from '@opentelemetry/api';
|
|
2
|
+
type InstrumentOperationParams = {
|
|
2
3
|
/** OTel meter name */
|
|
3
4
|
meter: string;
|
|
4
5
|
/** Function name being instrumented */
|
|
5
6
|
name: string;
|
|
6
7
|
/** Handle to execute the function */
|
|
7
8
|
delegate: () => unknown;
|
|
9
|
+
/** Metric Attributes in the form of key value pairs */
|
|
10
|
+
instrumentAttributes?: Attributes;
|
|
8
11
|
};
|
|
9
12
|
/**
|
|
10
13
|
* Run the given function, recording throughput, latency and errors
|
|
11
14
|
*
|
|
12
15
|
* @param operationParams
|
|
13
16
|
*/
|
|
14
|
-
declare function instrument({ meter, name, delegate }:
|
|
17
|
+
declare function instrument({ meter, name, delegate, instrumentAttributes }: InstrumentOperationParams): Promise<unknown>;
|
|
15
18
|
/**
|
|
16
19
|
* Decorator that instruments a class method
|
|
20
|
+
*
|
|
21
|
+
* @param meter - Name of OTel meter
|
|
17
22
|
*/
|
|
18
|
-
declare function instrumented(meter: string
|
|
19
|
-
export { instrument, instrumented };
|
|
23
|
+
declare function instrumented(meter: string): (target: any, key: string, descriptor?: PropertyDescriptor) => PropertyDescriptor | undefined;
|
|
24
|
+
export { instrument, instrumented, type InstrumentOperationParams };
|
|
@@ -17,7 +17,7 @@ const timer_1 = require("./timer");
|
|
|
17
17
|
*
|
|
18
18
|
* @param operationParams
|
|
19
19
|
*/
|
|
20
|
-
function instrument({ meter, name, delegate }) {
|
|
20
|
+
function instrument({ meter, name, delegate, instrumentAttributes }) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
const start = process.hrtime();
|
|
23
23
|
try {
|
|
@@ -26,8 +26,8 @@ function instrument({ meter, name, delegate }) {
|
|
|
26
26
|
catch (err) {
|
|
27
27
|
(0, counter_1.incrementCounter)({
|
|
28
28
|
meter,
|
|
29
|
-
name:
|
|
30
|
-
counterAttributes: { function: name },
|
|
29
|
+
name: 'function.errors',
|
|
30
|
+
counterAttributes: Object.assign({ function: name }, instrumentAttributes),
|
|
31
31
|
});
|
|
32
32
|
throw err;
|
|
33
33
|
}
|
|
@@ -36,9 +36,9 @@ function instrument({ meter, name, delegate }) {
|
|
|
36
36
|
const elapsedNanos = elapsed[0] * 1000000000 + elapsed[1];
|
|
37
37
|
(0, timer_1.recordTimer)({
|
|
38
38
|
meter,
|
|
39
|
-
name:
|
|
39
|
+
name: 'function.executionTime',
|
|
40
40
|
val: elapsedNanos,
|
|
41
|
-
timerAttributes: { function: name },
|
|
41
|
+
timerAttributes: Object.assign({ function: name }, instrumentAttributes),
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
});
|
|
@@ -46,27 +46,31 @@ function instrument({ meter, name, delegate }) {
|
|
|
46
46
|
exports.instrument = instrument;
|
|
47
47
|
/**
|
|
48
48
|
* Decorator that instruments a class method
|
|
49
|
+
*
|
|
50
|
+
* @param meter - Name of OTel meter
|
|
49
51
|
*/
|
|
50
|
-
function instrumented(meter
|
|
51
|
-
|
|
52
|
-
descriptor
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
function instrumented(meter) {
|
|
53
|
+
return function (target, key, descriptor) {
|
|
54
|
+
if (descriptor === undefined) {
|
|
55
|
+
descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
56
|
+
}
|
|
57
|
+
if (descriptor === undefined) {
|
|
58
|
+
return descriptor;
|
|
59
|
+
}
|
|
60
|
+
const originalMethod = descriptor.value;
|
|
61
|
+
const klass = target.constructor.name;
|
|
62
|
+
// this needs to be a non-arrow function or we'll get the wrong `this`
|
|
63
|
+
function overrideMethod(...args) {
|
|
64
|
+
return instrument({
|
|
65
|
+
meter,
|
|
66
|
+
name: `${klass}.${key}`,
|
|
67
|
+
delegate: () => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return yield originalMethod.apply(this, args);
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
descriptor.value = overrideMethod;
|
|
55
73
|
return descriptor;
|
|
56
|
-
}
|
|
57
|
-
const originalMethod = descriptor.value;
|
|
58
|
-
const klass = target.constructor.name;
|
|
59
|
-
// this needs to be a non-arrow function or we'll get the wrong `this`
|
|
60
|
-
function overrideMethod(...args) {
|
|
61
|
-
return instrument({
|
|
62
|
-
meter,
|
|
63
|
-
name: `${klass}.${key}`,
|
|
64
|
-
delegate: () => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
return yield originalMethod.apply(this, args);
|
|
66
|
-
}),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
descriptor.value = overrideMethod;
|
|
70
|
-
return descriptor;
|
|
74
|
+
};
|
|
71
75
|
}
|
|
72
76
|
exports.instrumented = instrumented;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { Attributes, MetricOptions } from
|
|
2
|
-
type
|
|
1
|
+
import type { Attributes, MetricOptions } from '@opentelemetry/api';
|
|
2
|
+
type TimerOperationParams = {
|
|
3
|
+
/** OTel meter name */
|
|
3
4
|
meter: string;
|
|
5
|
+
/** Metric name being instrumented */
|
|
4
6
|
name: string;
|
|
7
|
+
/** Timer value to be recorded */
|
|
5
8
|
val: number;
|
|
9
|
+
/** MetricOptions such as unit */
|
|
6
10
|
timerOptions?: MetricOptions;
|
|
11
|
+
/** Metric Attributes in the form of key value pairs */
|
|
7
12
|
timerAttributes?: Attributes;
|
|
8
13
|
};
|
|
9
|
-
declare const recordTimer: ({ meter, name, val, timerOptions, timerAttributes
|
|
10
|
-
export { recordTimer };
|
|
14
|
+
declare const recordTimer: ({ meter, name, val, timerOptions, timerAttributes }: TimerOperationParams) => void;
|
|
15
|
+
export { recordTimer, type TimerOperationParams };
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.recordTimer = void 0;
|
|
4
4
|
const meter_1 = require("../lib/meter");
|
|
5
5
|
const timers = {};
|
|
6
|
-
const recordTimer = ({ meter, name, val, timerOptions, timerAttributes
|
|
6
|
+
const recordTimer = ({ meter, name, val, timerOptions, timerAttributes }) => {
|
|
7
7
|
let timer = timers[name];
|
|
8
8
|
if (timer === undefined) {
|
|
9
9
|
const _otelMeter = (0, meter_1.acquireMeter)(meter);
|
|
10
|
-
timer = timers[name] = _otelMeter.createHistogram(name, Object.assign(Object.assign({}, timerOptions), { unit:
|
|
10
|
+
timer = timers[name] = _otelMeter.createHistogram(name, Object.assign(Object.assign({}, timerOptions), { unit: 'ns' }));
|
|
11
11
|
}
|
|
12
12
|
timer.record(val, timerAttributes);
|
|
13
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boxyhq/metrics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Internal SDK for OTel instrumentation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc -p tsconfig.json",
|
|
12
|
-
"prepublishOnly": "npm run build"
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"lint": "eslint -c .eslintrc.json --ext .ts ./"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/boxyhq/
|
|
17
|
-
"directory": "metrics"
|
|
17
|
+
"url": "git+https://github.com/boxyhq/metrics.git"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"otel",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/boxyhq/
|
|
25
|
+
"url": "https://github.com/boxyhq/metrics/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/boxyhq/
|
|
27
|
+
"homepage": "https://github.com/boxyhq/metrics#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@opentelemetry/api": "1.4.1",
|
|
30
30
|
"@opentelemetry/exporter-metrics-otlp-grpc": "0.37.0",
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"@tsconfig/recommended": "1.0.2",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "5.57.1",
|
|
39
39
|
"@typescript-eslint/parser": "5.57.1",
|
|
40
|
-
"eslint": "8.
|
|
41
|
-
"
|
|
40
|
+
"eslint": "8.38.0",
|
|
41
|
+
"eslint-config-prettier": "8.8.0",
|
|
42
|
+
"prettier": "2.8.7",
|
|
43
|
+
"typescript": "5.0.4"
|
|
42
44
|
}
|
|
43
45
|
}
|