@rsdk/cli.cmd.start 5.11.5 → 5.11.6-next.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/dist/opentelemetry/exporter.d.ts +8 -0
- package/dist/opentelemetry/exporter.js +69 -0
- package/dist/opentelemetry/exporter.js.map +1 -0
- package/dist/opentelemetry/opentelemetry.init.js +49 -26
- package/dist/opentelemetry/opentelemetry.init.js.map +1 -1
- package/dist/opentelemetry/otlp-exporter.d.ts +6 -0
- package/dist/opentelemetry/otlp-exporter.js +21 -0
- package/dist/opentelemetry/otlp-exporter.js.map +1 -0
- package/dist/opentelemetry/profiling.context-manager.d.ts +6 -0
- package/dist/opentelemetry/profiling.context-manager.js +87 -0
- package/dist/opentelemetry/profiling.context-manager.js.map +1 -0
- package/dist/opentelemetry/prom-metrics.type.d.ts +2 -0
- package/dist/opentelemetry/prom-metrics.type.js +3 -0
- package/dist/opentelemetry/prom-metrics.type.js.map +1 -0
- package/dist/opentelemetry/propagators.d.ts +5 -0
- package/dist/opentelemetry/propagators.js +34 -0
- package/dist/opentelemetry/propagators.js.map +1 -0
- package/dist/otel-convertors/counter.convertor.d.ts +6 -0
- package/dist/otel-convertors/counter.convertor.js +25 -0
- package/dist/otel-convertors/counter.convertor.js.map +1 -0
- package/dist/otel-convertors/data-points.d.ts +4 -0
- package/dist/otel-convertors/data-points.js +15 -0
- package/dist/otel-convertors/data-points.js.map +1 -0
- package/dist/otel-convertors/gauge.convertor.d.ts +6 -0
- package/dist/otel-convertors/gauge.convertor.js +24 -0
- package/dist/otel-convertors/gauge.convertor.js.map +1 -0
- package/dist/otel-convertors/histogram.convertor.d.ts +6 -0
- package/dist/otel-convertors/histogram.convertor.js +81 -0
- package/dist/otel-convertors/histogram.convertor.js.map +1 -0
- package/dist/otel-convertors/index.d.ts +4 -0
- package/dist/otel-convertors/index.js +21 -0
- package/dist/otel-convertors/index.js.map +1 -0
- package/dist/otel-convertors/summary.convertor.d.ts +6 -0
- package/dist/otel-convertors/summary.convertor.js +69 -0
- package/dist/otel-convertors/summary.convertor.js.map +1 -0
- package/dist/profiling/profiling.d.ts +10 -0
- package/dist/profiling/profiling.js +34 -0
- package/dist/profiling/profiling.js.map +1 -0
- package/dist/start-dev.cmd.d.ts +1 -1
- package/dist/start-dev.cmd.js +17 -3
- package/dist/start-dev.cmd.js.map +1 -1
- package/dist/start.cmd.d.ts +1 -1
- package/dist/start.cmd.js +12 -2
- package/dist/start.cmd.js.map +1 -1
- package/jest.config.js +1 -0
- package/package.json +21 -4
- package/src/opentelemetry/exporter.spec.ts +220 -0
- package/src/opentelemetry/exporter.ts +88 -0
- package/src/opentelemetry/opentelemetry.init.ts +60 -29
- package/src/opentelemetry/otlp-exporter.spec.ts +66 -0
- package/src/opentelemetry/otlp-exporter.ts +28 -0
- package/src/opentelemetry/profiling.context-manager.spec.ts +93 -0
- package/src/opentelemetry/profiling.context-manager.ts +118 -0
- package/src/opentelemetry/prom-metrics.type.ts +9 -0
- package/src/opentelemetry/propagators.spec.ts +67 -0
- package/src/opentelemetry/propagators.ts +35 -0
- package/src/otel-convertors/counter.convertor.ts +34 -0
- package/src/otel-convertors/data-points.ts +19 -0
- package/src/otel-convertors/gauge.convertor.ts +33 -0
- package/src/otel-convertors/histogram.convertor.ts +121 -0
- package/src/otel-convertors/index.ts +4 -0
- package/src/otel-convertors/summary.convertor.ts +86 -0
- package/src/profiling/profiling.ts +37 -0
- package/src/start-dev.cmd.ts +24 -2
- package/src/start.cmd.ts +21 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"histogram.convertor.js","sourceRoot":"","sources":["../../src/otel-convertors/histogram.convertor.ts"],"names":[],"mappings":";;;AACA,4CAA+C;AAM/C,4DAIoC;AAKpC,MAAM,aAAa,GAAG,SAAS,CAAC;AAChC,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,YAAY,GAAG,QAAQ,CAAC;AAS9B,MAAa,kBAAkB;IAC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AC,CAAC,EAAE,CAAC;oBACP,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE;iBAChC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,UAAU,EAAE;gBACV,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,WAAW,EAAE,WAAW,CAAC,IAAI;gBAC7B,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,4BAAc,CAAC,SAAS;gBAC9B,SAAS,EAAE,eAAS,CAAC,MAAM;aAC5B;YACD,sBAAsB,EAAE,oCAAsB,CAAC,UAAU;YACzD,aAAa,EAAE,2BAAa,CAAC,SAAS;YACtC,UAAU;SACX,CAAC;IACJ,CAAC;CACF;AA7FD,gDA6FC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./counter.convertor"), exports);
|
|
18
|
+
__exportStar(require("./gauge.convertor"), exports);
|
|
19
|
+
__exportStar(require("./histogram.convertor"), exports);
|
|
20
|
+
__exportStar(require("./summary.convertor"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/otel-convertors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAClC,wDAAsC;AACtC,sDAAoC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HrTime } from '@opentelemetry/api';
|
|
2
|
+
import type { MetricData } from '@opentelemetry/sdk-metrics';
|
|
3
|
+
import type { PromMetricWithValues } from '../opentelemetry/prom-metrics.type';
|
|
4
|
+
export declare class SummaryConvertor {
|
|
5
|
+
static toOtel(promMetrics: PromMetricWithValues, startTime: HrTime, endTime: HrTime): MetricData[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SummaryConvertor = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
6
|
+
const data_points_1 = require("./data-points");
|
|
7
|
+
// В sdk-metrics нет типа Summary: квантили уходят как gauge, _sum и _count как sum
|
|
8
|
+
class SummaryConvertor {
|
|
9
|
+
static toOtel(promMetrics, startTime, endTime) {
|
|
10
|
+
// prom-client отдает summary плоским списком: квантили с меткой quantile,
|
|
11
|
+
// а _sum и _count отдельными записями с metricName
|
|
12
|
+
const quantileValues = [];
|
|
13
|
+
const sumValues = [];
|
|
14
|
+
const countValues = [];
|
|
15
|
+
for (const v of promMetrics.values) {
|
|
16
|
+
if (v.metricName === `${promMetrics.name}_sum`) {
|
|
17
|
+
sumValues.push(v);
|
|
18
|
+
}
|
|
19
|
+
else if (v.metricName === `${promMetrics.name}_count`) {
|
|
20
|
+
countValues.push(v);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
quantileValues.push(v);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const quantiles = {
|
|
27
|
+
descriptor: {
|
|
28
|
+
name: promMetrics.name,
|
|
29
|
+
description: promMetrics.help,
|
|
30
|
+
unit: '',
|
|
31
|
+
type: sdk_metrics_1.InstrumentType.GAUGE,
|
|
32
|
+
valueType: api_1.ValueType.DOUBLE,
|
|
33
|
+
},
|
|
34
|
+
aggregationTemporality: sdk_metrics_1.AggregationTemporality.CUMULATIVE,
|
|
35
|
+
dataPointType: sdk_metrics_1.DataPointType.GAUGE,
|
|
36
|
+
dataPoints: (0, data_points_1.toDataPoints)(quantileValues, startTime, endTime),
|
|
37
|
+
};
|
|
38
|
+
// наблюдения могут быть отрицательными, поэтому _sum не монотонный
|
|
39
|
+
const sum = {
|
|
40
|
+
descriptor: {
|
|
41
|
+
name: `${promMetrics.name}_sum`,
|
|
42
|
+
description: `${promMetrics.help} (sum)`,
|
|
43
|
+
unit: '',
|
|
44
|
+
type: sdk_metrics_1.InstrumentType.UP_DOWN_COUNTER,
|
|
45
|
+
valueType: api_1.ValueType.DOUBLE,
|
|
46
|
+
},
|
|
47
|
+
aggregationTemporality: sdk_metrics_1.AggregationTemporality.CUMULATIVE,
|
|
48
|
+
dataPointType: sdk_metrics_1.DataPointType.SUM,
|
|
49
|
+
isMonotonic: false,
|
|
50
|
+
dataPoints: (0, data_points_1.toDataPoints)(sumValues, startTime, endTime),
|
|
51
|
+
};
|
|
52
|
+
const count = {
|
|
53
|
+
descriptor: {
|
|
54
|
+
name: `${promMetrics.name}_count`,
|
|
55
|
+
description: `${promMetrics.help} (count)`,
|
|
56
|
+
unit: '',
|
|
57
|
+
type: sdk_metrics_1.InstrumentType.COUNTER,
|
|
58
|
+
valueType: api_1.ValueType.DOUBLE,
|
|
59
|
+
},
|
|
60
|
+
aggregationTemporality: sdk_metrics_1.AggregationTemporality.CUMULATIVE,
|
|
61
|
+
dataPointType: sdk_metrics_1.DataPointType.SUM,
|
|
62
|
+
isMonotonic: true,
|
|
63
|
+
dataPoints: (0, data_points_1.toDataPoints)(countValues, startTime, endTime),
|
|
64
|
+
};
|
|
65
|
+
return [quantiles, sum, count];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.SummaryConvertor = SummaryConvertor;
|
|
69
|
+
//# sourceMappingURL=summary.convertor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.convertor.js","sourceRoot":"","sources":["../../src/otel-convertors/summary.convertor.ts"],"names":[],"mappings":";;;AACA,4CAA+C;AAM/C,4DAIoC;AAKpC,+CAA6C;AAE7C,mFAAmF;AACnF,MAAa,gBAAgB;IAC3B,MAAM,CAAC,MAAM,CACX,WAAiC,EACjC,SAAiB,EACjB,OAAe;QAEf,0EAA0E;QAC1E,mDAAmD;QACnD,MAAM,cAAc,GAA0B,EAAE,CAAC;QACjD,MAAM,SAAS,GAA0B,EAAE,CAAC;QAC5C,MAAM,WAAW,GAA0B,EAAE,CAAC;QAE9C,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,MAAuC,EAAE,CAAC;YACpE,IAAI,CAAC,CAAC,UAAU,KAAK,GAAG,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;gBAC/C,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,CAAC;iBAAM,IAAI,CAAC,CAAC,UAAU,KAAK,GAAG,WAAW,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACxD,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAED,MAAM,SAAS,GAAoB;YACjC,UAAU,EAAE;gBACV,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,WAAW,EAAE,WAAW,CAAC,IAAI;gBAC7B,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,4BAAc,CAAC,KAAK;gBAC1B,SAAS,EAAE,eAAS,CAAC,MAAM;a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FILING.
|
|
3
|
+
* Без значения опция приходит как true
|
|
4
|
+
*/
|
|
5
|
+
export declare function applyProfilingOption(value: string | boolean | undefined): void;
|
|
6
|
+
/**
|
|
7
|
+
* Путь к прелоаду из node_modules приложения. Без @rsdk/profiling.common
|
|
8
|
+
* профилирование недоступно, но приложение запускается
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveProfilingRegister(): string | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyProfilingOption = applyProfilingOption;
|
|
4
|
+
exports.resolveProfilingRegister = resolveProfilingRegister;
|
|
5
|
+
const logging_1 = require("@rsdk/logging");
|
|
6
|
+
const logger = logging_1.LoggerFactory.create('Profiling');
|
|
7
|
+
/**
|
|
8
|
+
* Передает --profiling прелоаду через переменную PROFILING.
|
|
9
|
+
* Без значения опция приходит как true
|
|
10
|
+
*/
|
|
11
|
+
function applyProfilingOption(value) {
|
|
12
|
+
if (value !== undefined && value !== false) {
|
|
13
|
+
process.env['PROFILING'] = String(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Путь к прелоаду из node_modules приложения. Без @rsdk/profiling.common
|
|
18
|
+
* профилирование недоступно, но приложение запускается
|
|
19
|
+
*/
|
|
20
|
+
function resolveProfilingRegister() {
|
|
21
|
+
try {
|
|
22
|
+
return require.resolve('@rsdk/profiling.common/register', {
|
|
23
|
+
paths: [process.cwd()],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
const requested = process.env['PROFILING'];
|
|
28
|
+
if (requested && requested !== 'false') {
|
|
29
|
+
logger.error('Profiling is disabled: @rsdk/profiling.common is not installed');
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=profiling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiling.js","sourceRoot":"","sources":["../../src/profiling/profiling.ts"],"names":[],"mappings":";;AAQA,oDAMC;AAMD,4DAgBC;AApCD,2CAA8C;AAE9C,MAAM,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAEjD;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,KAAmC;IAEnC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,wBAAwB;IACtC,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,OAAO,CAAC,iCAAiC,EAAE;YACxD,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;SACvB,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAE3C,IAAI,SAAS,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YACvC,MAAM,CAAC,KAAK,CACV,gEAAgE,CACjE,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/start-dev.cmd.d.ts
CHANGED
package/dist/start-dev.cmd.js
CHANGED
|
@@ -21,17 +21,29 @@ const logging_1 = require("@rsdk/logging");
|
|
|
21
21
|
const execa_1 = __importDefault(require("execa"));
|
|
22
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
23
23
|
const opentelemetry_path_1 = require("./opentelemetry/opentelemetry.path");
|
|
24
|
+
const profiling_1 = require("./profiling/profiling");
|
|
24
25
|
class StartDevCmd {
|
|
25
26
|
static logger = logging_1.LoggerFactory.create(StartDevCmd);
|
|
26
|
-
async handle(otel, pretty) {
|
|
27
|
+
async handle(otel, pretty, profiling) {
|
|
27
28
|
const tracingPart = [`-r`, opentelemetry_path_1.OPENTELEMETRY_INIT_PATH];
|
|
28
29
|
const env = {};
|
|
29
30
|
const command = [`--watch`];
|
|
31
|
+
(0, profiling_1.applyProfilingOption)(profiling);
|
|
32
|
+
const profilingRegister = (0, profiling_1.resolveProfilingRegister)();
|
|
33
|
+
// ts-node подключается до профилировщика, потому что по нему профилировщик
|
|
34
|
+
// включает в Node source maps, иначе строки в профиле будут из JS.
|
|
35
|
+
// Профилировщик подключается до OTEL, чтобы тот связал профили со спанами
|
|
36
|
+
if (profilingRegister) {
|
|
37
|
+
command.push('-r', 'ts-node/register', '-r', profilingRegister);
|
|
38
|
+
}
|
|
30
39
|
if (otel) {
|
|
31
40
|
command.push(...tracingPart);
|
|
32
41
|
env['LOG_OTEL_ENABLED'] = 'true';
|
|
33
42
|
}
|
|
34
|
-
|
|
43
|
+
if (!profilingRegister) {
|
|
44
|
+
command.push('-r', 'ts-node/register');
|
|
45
|
+
}
|
|
46
|
+
command.push('src/main.ts');
|
|
35
47
|
const bin = 'node';
|
|
36
48
|
const cmd = [bin, ...command].join(' ');
|
|
37
49
|
StartDevCmd.logger.trace('run command: ' + cmd);
|
|
@@ -67,8 +79,10 @@ __decorate([
|
|
|
67
79
|
__param(0, (0, cli_common_1.Option)('otel', 'Enable opentelemetry tracing', Boolean)),
|
|
68
80
|
__param(1, (0, cli_common_1.Option)('pretty', 'Enable PinoPretty output', String, (v) => v === 'true')),
|
|
69
81
|
__param(1, (0, cli_common_1.Default)('true')),
|
|
82
|
+
__param(2, (0, cli_common_1.Option)('profiling', 'Enable profiling, pyroscope by default', String)),
|
|
83
|
+
__param(2, (0, cli_common_1.OptionalValue)()),
|
|
70
84
|
__metadata("design:type", Function),
|
|
71
|
-
__metadata("design:paramtypes", [Boolean, Boolean]),
|
|
85
|
+
__metadata("design:paramtypes", [Boolean, Boolean, Object]),
|
|
72
86
|
__metadata("design:returntype", Promise)
|
|
73
87
|
], StartDevCmd.prototype, "handle", null);
|
|
74
88
|
//# sourceMappingURL=start-dev.cmd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-dev.cmd.js","sourceRoot":"","sources":["../src/start-dev.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"start-dev.cmd.js","sourceRoot":"","sources":["../src/start-dev.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iDAA0E;AAC1E,2CAA8C;AAC9C,kDAA0B;AAC1B,0DAA6B;AAE7B,2EAA6E;AAC7E,qDAG+B;AAE/B,MAAa,WAAW;IACtB,MAAM,CAAC,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAG5C,AAAN,KAAK,CAAC,MAAM,CAEV,IAAa,EAGb,MAAe,EAGf,SAAuC;QAEvC,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,4CAAuB,CAAC,CAAC;QACpD,MAAM,GAAG,GAAsB,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC;QAE5B,IAAA,gCAAoB,EAAC,SAAS,CAAC,CAAC;QAEhC,MAAM,iBAAiB,GAAG,IAAA,oCAAwB,GAAE,CAAC;QAErD,2EAA2E;QAC3E,mEAAmE;QACnE,0EAA0E;QAC1E,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;YAC7B,GAAG,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACzC,CAAC;QAED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CAAC;;AAvEH,kCAwEC;AApEO;IADL,IAAA,mBAAM,EAAC,WAAW,EAAE,2BAA2B,CAAC;IAE9C,WAAA,IAAA,mBAAM,EAAC,MAAM,EAAE,8BAA8B,EAAE,OAAO,CAAC,CAAA;IAEvD,WAAA,IAAA,mBAAM,EAAC,QAAQ,EAAE,0BAA0B,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,CAAA;IACzE,WAAA,IAAA,oBAAO,EAAC,MAAM,CAAC,CAAA;IAEf,WAAA,IAAA,mBAAM,EAAC,WAAW,EAAE,wCAAwC,EAAE,MAAM,CAAC,CAAA;IACrE,WAAA,IAAA,0BAAa,GAAE,CAAA;;;;yCA4DjB"}
|
package/dist/start.cmd.d.ts
CHANGED
package/dist/start.cmd.js
CHANGED
|
@@ -20,11 +20,19 @@ const cli_common_1 = require("@rsdk/cli.common");
|
|
|
20
20
|
const logging_1 = require("@rsdk/logging");
|
|
21
21
|
const node_path_1 = __importDefault(require("node:path"));
|
|
22
22
|
const opentelemetry_path_1 = require("./opentelemetry/opentelemetry.path");
|
|
23
|
+
const profiling_1 = require("./profiling/profiling");
|
|
23
24
|
class StartCmd {
|
|
24
25
|
logger = logging_1.LoggerFactory.create(StartCmd);
|
|
25
|
-
async handle(otel) {
|
|
26
|
+
async handle(otel, profiling) {
|
|
26
27
|
this.logger.trace('execute start command');
|
|
27
28
|
try {
|
|
29
|
+
(0, profiling_1.applyProfilingOption)(profiling);
|
|
30
|
+
const profilingRegister = (0, profiling_1.resolveProfilingRegister)();
|
|
31
|
+
if (profilingRegister) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
33
|
+
const { register } = require(profilingRegister);
|
|
34
|
+
register?.();
|
|
35
|
+
}
|
|
28
36
|
if (otel) {
|
|
29
37
|
require(opentelemetry_path_1.OPENTELEMETRY_INIT_PATH);
|
|
30
38
|
process.env.LOG_OTEL_ENABLED = 'true';
|
|
@@ -49,8 +57,10 @@ exports.StartCmd = StartCmd;
|
|
|
49
57
|
__decorate([
|
|
50
58
|
(0, cli_common_1.SubCmd)('start', 'Start built app'),
|
|
51
59
|
__param(0, (0, cli_common_1.Option)('otel', 'Enable opentelemetry tracing', Boolean)),
|
|
60
|
+
__param(1, (0, cli_common_1.Option)('profiling', 'Enable profiling, pyroscope by default', String)),
|
|
61
|
+
__param(1, (0, cli_common_1.OptionalValue)()),
|
|
52
62
|
__metadata("design:type", Function),
|
|
53
|
-
__metadata("design:paramtypes", [Boolean]),
|
|
63
|
+
__metadata("design:paramtypes", [Boolean, Object]),
|
|
54
64
|
__metadata("design:returntype", Promise)
|
|
55
65
|
], StartCmd.prototype, "handle", null);
|
|
56
66
|
//# sourceMappingURL=start.cmd.js.map
|
package/dist/start.cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.cmd.js","sourceRoot":"","sources":["../src/start.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"start.cmd.js","sourceRoot":"","sources":["../src/start.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iDAAiE;AACjE,2CAA8C;AAC9C,0DAA6B;AAE7B,2EAA6E;AAC7E,qDAG+B;AAE/B,MAAa,QAAQ;IACF,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAGnD,AAAN,KAAK,CAAC,MAAM,CAC+C,IAAa,EAGtE,SAAuC;QAEvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAE3C,IAAI,CAAC;YACH,IAAA,gCAAoB,EAAC,SAAS,CAAC,CAAC;YAEhC,MAAM,iBAAiB,GAAG,IAAA,oCAAwB,GAAE,CAAC;YAErD,IAAI,iBAAiB,EAAE,CAAC;gBACtB,qGAAqG;gBACrG,MAAM,EAAE,QAAQ,EAAE,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|
|
2
2
|
"name": "@rsdk/cli.cmd.start",
|
|
3
|
-
"version": "5.11.
|
|
3
|
+
"version": "5.11.6-next.0",
|
|
4
4
|
"description": "Start command for rsdk cli",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -26,9 +26,12 @@
|
|
|
26
26
|
"@opentelemetry/api": "^1.9.0",
|
|
27
27
|
"@opentelemetry/auto-instrumentations-node": "^0.56.1",
|
|
28
28
|
"@opentelemetry/core": "^1.30.1",
|
|
29
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.57.2",
|
|
29
30
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.2",
|
|
31
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.57.2",
|
|
32
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.57.2",
|
|
30
33
|
"@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
|
|
31
|
-
"@opentelemetry/
|
|
34
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.57.2",
|
|
32
35
|
"@opentelemetry/resource-detector-container": "^0.6.1",
|
|
33
36
|
"@opentelemetry/resources": "^1.30.1",
|
|
34
37
|
"@opentelemetry/sdk-metrics": "^1.30.1",
|
|
@@ -37,8 +40,10 @@
|
|
|
37
40
|
"@opentelemetry/semantic-conventions": "^1.30.0",
|
|
38
41
|
"@rsdk/actx": "*",
|
|
39
42
|
"@rsdk/cli.common": "*",
|
|
43
|
+
"@rsdk/common.node": "*",
|
|
40
44
|
"@rsdk/core": "*",
|
|
41
45
|
"@rsdk/logging": "*",
|
|
46
|
+
"@rsdk/profiling.common": "*",
|
|
42
47
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
43
48
|
"rxjs": "^7.1.0"
|
|
44
49
|
},
|
|
@@ -52,13 +57,22 @@
|
|
|
52
57
|
"@opentelemetry/core": {
|
|
53
58
|
"optional": true
|
|
54
59
|
},
|
|
60
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
55
63
|
"@opentelemetry/exporter-metrics-otlp-http": {
|
|
56
64
|
"optional": true
|
|
57
65
|
},
|
|
66
|
+
"@opentelemetry/exporter-metrics-otlp-proto": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@opentelemetry/exporter-trace-otlp-grpc": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
58
72
|
"@opentelemetry/exporter-trace-otlp-http": {
|
|
59
73
|
"optional": true
|
|
60
74
|
},
|
|
61
|
-
"@opentelemetry/
|
|
75
|
+
"@opentelemetry/exporter-trace-otlp-proto": {
|
|
62
76
|
"optional": true
|
|
63
77
|
},
|
|
64
78
|
"@opentelemetry/resource-detector-container": {
|
|
@@ -78,7 +92,10 @@
|
|
|
78
92
|
},
|
|
79
93
|
"@opentelemetry/semantic-conventions": {
|
|
80
94
|
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@rsdk/profiling.common": {
|
|
97
|
+
"optional": true
|
|
81
98
|
}
|
|
82
99
|
},
|
|
83
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "36ecf2006c7e322bc53eb12b81de37ac3719180c"
|
|
84
101
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GaugeMetricData,
|
|
3
|
+
Histogram as OtelHistogram,
|
|
4
|
+
HistogramMetricData,
|
|
5
|
+
MetricData,
|
|
6
|
+
SumMetricData,
|
|
7
|
+
} from '@opentelemetry/sdk-metrics';
|
|
8
|
+
import {
|
|
9
|
+
AggregationTemporality,
|
|
10
|
+
DataPointType,
|
|
11
|
+
InstrumentType,
|
|
12
|
+
} from '@opentelemetry/sdk-metrics';
|
|
13
|
+
import { Counter, Gauge, Histogram, Registry, Summary } from 'prom-client';
|
|
14
|
+
|
|
15
|
+
import { PromClientMetricProducer } from './exporter';
|
|
16
|
+
|
|
17
|
+
async function collect(
|
|
18
|
+
registry: Registry,
|
|
19
|
+
): Promise<{ metrics: MetricData[]; errors: unknown[] }> {
|
|
20
|
+
const { resourceMetrics, errors } = await new PromClientMetricProducer(
|
|
21
|
+
() => registry,
|
|
22
|
+
).collect();
|
|
23
|
+
|
|
24
|
+
return { metrics: resourceMetrics.scopeMetrics[0]?.metrics ?? [], errors };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function byName<T extends MetricData>(metrics: MetricData[], name: string): T {
|
|
28
|
+
const metric = metrics.find((m) => m.descriptor.name === name);
|
|
29
|
+
|
|
30
|
+
if (!metric) throw new Error(`metric ${name} not found`);
|
|
31
|
+
|
|
32
|
+
return metric as T;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('PromClientMetricProducer', () => {
|
|
36
|
+
let registry: Registry;
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
registry = new Registry();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('конвертирует counter в монотонный кумулятивный sum', async () => {
|
|
43
|
+
const counter = new Counter({
|
|
44
|
+
name: 'calls_total',
|
|
45
|
+
help: 'calls',
|
|
46
|
+
labelNames: ['route'],
|
|
47
|
+
registers: [registry],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
counter.inc({ route: '/a' }, 2);
|
|
51
|
+
counter.inc({ route: '/b' });
|
|
52
|
+
|
|
53
|
+
const { metrics, errors } = await collect(registry);
|
|
54
|
+
const sum = byName<SumMetricData>(metrics, 'calls_total');
|
|
55
|
+
|
|
56
|
+
expect(errors).toEqual([]);
|
|
57
|
+
expect(sum.descriptor).toMatchObject({
|
|
58
|
+
description: 'calls',
|
|
59
|
+
type: InstrumentType.COUNTER,
|
|
60
|
+
});
|
|
61
|
+
expect(sum.dataPointType).toBe(DataPointType.SUM);
|
|
62
|
+
expect(sum.isMonotonic).toBe(true);
|
|
63
|
+
expect(sum.aggregationTemporality).toBe(AggregationTemporality.CUMULATIVE);
|
|
64
|
+
expect(sum.dataPoints.map((p) => [p.attributes, p.value])).toEqual([
|
|
65
|
+
[{ route: '/a' }, 2],
|
|
66
|
+
[{ route: '/b' }, 1],
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('отбрасывает точки gauge с NaN и Infinity', async () => {
|
|
71
|
+
const gauge = new Gauge({
|
|
72
|
+
name: 'latency',
|
|
73
|
+
help: 'latency',
|
|
74
|
+
labelNames: ['kind'],
|
|
75
|
+
registers: [registry],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
gauge.set({ kind: 'ok' }, 5);
|
|
79
|
+
gauge.set({ kind: 'nan' }, Number.NaN);
|
|
80
|
+
gauge.set({ kind: 'inf' }, Number.POSITIVE_INFINITY);
|
|
81
|
+
|
|
82
|
+
const { metrics } = await collect(registry);
|
|
83
|
+
const otel = byName<GaugeMetricData>(metrics, 'latency');
|
|
84
|
+
|
|
85
|
+
expect(otel.dataPointType).toBe(DataPointType.GAUGE);
|
|
86
|
+
expect(otel.dataPoints.map((p) => [p.attributes, p.value])).toEqual([
|
|
87
|
+
[{ kind: 'ok' }, 5],
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('не экспортирует метрику, у которой не осталось точек', async () => {
|
|
92
|
+
new Gauge({ name: 'empty', help: 'empty', registers: [registry] }).set(
|
|
93
|
+
Number.NaN,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const { metrics } = await collect(registry);
|
|
97
|
+
|
|
98
|
+
expect(metrics).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('переводит кумулятивные бакеты histogram в счетчики бакетов', async () => {
|
|
102
|
+
const histogram = new Histogram({
|
|
103
|
+
name: 'duration',
|
|
104
|
+
help: 'duration',
|
|
105
|
+
labelNames: ['route'],
|
|
106
|
+
buckets: [1, 5, 10],
|
|
107
|
+
registers: [registry],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for (const v of [0.5, 3, 4, 7, 20]) histogram.observe({ route: '/a' }, v);
|
|
111
|
+
histogram.observe({ route: '/b' }, 2);
|
|
112
|
+
|
|
113
|
+
const { metrics } = await collect(registry);
|
|
114
|
+
const otel = byName<HistogramMetricData>(metrics, 'duration');
|
|
115
|
+
const [a, b] = otel.dataPoints;
|
|
116
|
+
|
|
117
|
+
expect(metrics.map((m) => m.descriptor.name)).toEqual(['duration']);
|
|
118
|
+
expect(otel.dataPointType).toBe(DataPointType.HISTOGRAM);
|
|
119
|
+
expect(otel.dataPoints).toHaveLength(2);
|
|
120
|
+
expect(a.attributes).toEqual({ route: '/a' });
|
|
121
|
+
expect(a.value).toEqual<OtelHistogram>({
|
|
122
|
+
count: 5,
|
|
123
|
+
sum: 34.5,
|
|
124
|
+
buckets: { boundaries: [1, 5, 10], counts: [1, 2, 1, 1] },
|
|
125
|
+
});
|
|
126
|
+
expect(b.attributes).toEqual({ route: '/b' });
|
|
127
|
+
expect(b.value.buckets.counts).toEqual([0, 1, 0, 0]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('раскладывает summary на квантили, _sum и _count', async () => {
|
|
131
|
+
const summary = new Summary({
|
|
132
|
+
name: 'request',
|
|
133
|
+
help: 'request',
|
|
134
|
+
labelNames: ['route'],
|
|
135
|
+
percentiles: [0.5, 0.9],
|
|
136
|
+
registers: [registry],
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
for (const v of [1, 2, 3]) summary.observe({ route: '/a' }, v);
|
|
140
|
+
|
|
141
|
+
const { metrics } = await collect(registry);
|
|
142
|
+
const quantiles = byName<GaugeMetricData>(metrics, 'request');
|
|
143
|
+
const sum = byName<SumMetricData>(metrics, 'request_sum');
|
|
144
|
+
const count = byName<SumMetricData>(metrics, 'request_count');
|
|
145
|
+
|
|
146
|
+
expect(quantiles.dataPointType).toBe(DataPointType.GAUGE);
|
|
147
|
+
expect(quantiles.dataPoints.map((p) => p.attributes)).toEqual([
|
|
148
|
+
{ quantile: 0.5, route: '/a' },
|
|
149
|
+
{ quantile: 0.9, route: '/a' },
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
expect(sum.isMonotonic).toBe(false);
|
|
153
|
+
expect(sum.dataPoints.map((p) => [p.attributes, p.value])).toEqual([
|
|
154
|
+
[{ route: '/a' }, 6],
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
expect(count.isMonotonic).toBe(true);
|
|
158
|
+
expect(count.dataPoints.map((p) => [p.attributes, p.value])).toEqual([
|
|
159
|
+
[{ route: '/a' }, 3],
|
|
160
|
+
]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('добавляет default labels registry', async () => {
|
|
164
|
+
registry.setDefaultLabels({ app: 'example' });
|
|
165
|
+
new Counter({ name: 'c_total', help: 'c', registers: [registry] }).inc();
|
|
166
|
+
|
|
167
|
+
const { metrics } = await collect(registry);
|
|
168
|
+
|
|
169
|
+
expect(metrics[0].dataPoints[0].attributes).toEqual({ app: 'example' });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('ставит всем точкам одно время сбора', async () => {
|
|
173
|
+
new Counter({ name: 'a_total', help: 'a', registers: [registry] }).inc();
|
|
174
|
+
new Gauge({ name: 'b', help: 'b', registers: [registry] }).set(1);
|
|
175
|
+
|
|
176
|
+
const { metrics } = await collect(registry);
|
|
177
|
+
const [first, second] = metrics.map((m) => m.dataPoints[0]);
|
|
178
|
+
|
|
179
|
+
expect(first.endTime).toEqual(second.endTime);
|
|
180
|
+
expect(first.startTime).toEqual(second.startTime);
|
|
181
|
+
expect(first.startTime[0]).toBeLessThanOrEqual(first.endTime[0]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('не бросает, если сбор метрик в registry упал', async () => {
|
|
185
|
+
new Gauge({
|
|
186
|
+
name: 'broken',
|
|
187
|
+
help: 'broken',
|
|
188
|
+
registers: [registry],
|
|
189
|
+
collect(): void {
|
|
190
|
+
throw new Error('collect failed');
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const { metrics, errors } = await collect(registry);
|
|
195
|
+
|
|
196
|
+
expect(metrics).toEqual([]);
|
|
197
|
+
expect(errors).toEqual([new Error('collect failed')]);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('экспортирует остальные метрики, если одна не сконвертировалась', async () => {
|
|
201
|
+
const counter = new Counter({
|
|
202
|
+
name: 'ok_total',
|
|
203
|
+
help: 'ok',
|
|
204
|
+
registers: [],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
counter.inc();
|
|
208
|
+
const fakeRegistry = {
|
|
209
|
+
getMetricsAsJSON: async () => [
|
|
210
|
+
{ name: 'broken', help: 'broken', type: 'histogram', values: null },
|
|
211
|
+
await counter.get(),
|
|
212
|
+
],
|
|
213
|
+
} as unknown as Registry;
|
|
214
|
+
|
|
215
|
+
const { metrics, errors } = await collect(fakeRegistry);
|
|
216
|
+
|
|
217
|
+
expect(metrics.map((m) => m.descriptor.name)).toEqual(['ok_total']);
|
|
218
|
+
expect(errors).toHaveLength(1);
|
|
219
|
+
});
|
|
220
|
+
});
|