@rsdk/cli.cmd.start 5.0.0-next.1 → 5.0.0-next.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.0.0-next.3](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.2...v5.0.0-next.3) (2024-07-11)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * generalize tracing headers (#247)
11
+
12
+ ### Features
13
+
14
+ * generalize tracing headers ([#247](https://github.com/R-Vision/rsdk/issues/247)) ([cee2ea6](https://github.com/R-Vision/rsdk/commit/cee2ea65c964705faf133397e285c051672c7512)), closes [#2](https://github.com/R-Vision/rsdk/issues/2) [#3](https://github.com/R-Vision/rsdk/issues/3) [#4](https://github.com/R-Vision/rsdk/issues/4) [#5](https://github.com/R-Vision/rsdk/issues/5)
15
+
16
+ ## [5.0.0-next.2](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.1...v5.0.0-next.2) (2024-07-10)
17
+
18
+ **Note:** Version bump only for package @rsdk/cli.cmd.start
19
+
6
20
  ## [5.0.0-next.1](https://github.com/R-Vision/rsdk/compare/v5.0.0-next.0...v5.0.0-next.1) (2024-07-10)
7
21
 
8
22
  **Note:** Version bump only for package @rsdk/cli.cmd.start
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const api_1 = require("@opentelemetry/api");
4
+ const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
5
+ const core_1 = require("@opentelemetry/core");
6
+ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
7
+ const propagator_b3_1 = require("@opentelemetry/propagator-b3");
8
+ const resource_detector_container_1 = require("@opentelemetry/resource-detector-container");
9
+ const resources_1 = require("@opentelemetry/resources");
10
+ const sdk_node_1 = require("@opentelemetry/sdk-node");
11
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
12
+ const node_http_1 = require("node:http");
13
+ const node_path_1 = require("node:path");
14
+ const node_process_1 = require("node:process");
15
+ const otelDiagLogLevel = process.env.OTEL_DIAG_LOG_LEVEL;
16
+ if (otelDiagLogLevel) {
17
+ console.log('telemetry diag enabled:', otelDiagLogLevel);
18
+ api_1.diag.setLogger(new api_1.DiagConsoleLogger(),
19
+ // @ts-expect-error sdsd
20
+ api_1.DiagLogLevel[otelDiagLogLevel]);
21
+ }
22
+ else {
23
+ console.log('telemetry debug disabled');
24
+ }
25
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
26
+ const manifestData = require((0, node_path_1.resolve)((0, node_process_1.cwd)(), 'package.json'));
27
+ const autoInstumentationOptions = (0, auto_instrumentations_node_1.getNodeAutoInstrumentations)({
28
+ '@opentelemetry/instrumentation-fs': {
29
+ // only instrument fs if it is part of another trace
30
+ requireParentSpan: true,
31
+ },
32
+ '@opentelemetry/instrumentation-aws-sdk': {
33
+ enabled: true,
34
+ responseHook: (span, { response }) => {
35
+ if (response.request.commandInput?.Bucket) {
36
+ span.setAttribute('s3.bucket.name', response.request.commandInput?.Bucket);
37
+ }
38
+ },
39
+ },
40
+ '@opentelemetry/instrumentation-graphql': {
41
+ allowValues: true,
42
+ },
43
+ '@opentelemetry/instrumentation-http': {
44
+ // не работает с connectionParams
45
+ enabled: true,
46
+ requestHook: (span, request) => {
47
+ if (request instanceof node_http_1.ClientRequest) {
48
+ console.log(request.req.url);
49
+ console.log(request.req.method);
50
+ }
51
+ if (request instanceof node_http_1.IncomingMessage) {
52
+ if (request.method && request.url) {
53
+ span.updateName(`${request.method} ${request.url}`);
54
+ }
55
+ }
56
+ else if (request instanceof node_http_1.ClientRequest &&
57
+ request.req.method &&
58
+ request.req.url) {
59
+ console.log('cr:', request.req.url, request.req.url);
60
+ span.updateName(`${request.req.method} ${request.req.url}`);
61
+ }
62
+ },
63
+ },
64
+ '@opentelemetry/instrumentation-pg': {
65
+ enhancedDatabaseReporting: true,
66
+ },
67
+ '@opentelemetry/instrumentation-pino': {
68
+ enabled: true,
69
+ logHook(_span, record) {
70
+ record['resource.service.name'] = otelServiceName;
71
+ },
72
+ },
73
+ '@opentelemetry/instrumentation-grpc': {
74
+ enabled: true,
75
+ },
76
+ '@opentelemetry/instrumentation-nestjs-core': {
77
+ enabled: true,
78
+ },
79
+ });
80
+ const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter();
81
+ const otelServiceName = process.env.OTEL_SERVICE_NAME ?? manifestData.name;
82
+ const sdk = new sdk_node_1.NodeSDK({
83
+ serviceName: otelServiceName,
84
+ instrumentations: [autoInstumentationOptions],
85
+ resource: new resources_1.Resource({
86
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: otelServiceName,
87
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_VERSION]: manifestData.version,
88
+ }),
89
+ traceExporter: exporter,
90
+ textMapPropagator: new core_1.CompositePropagator({
91
+ propagators: [
92
+ new propagator_b3_1.B3Propagator(),
93
+ new propagator_b3_1.B3Propagator({
94
+ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER,
95
+ }),
96
+ ],
97
+ }),
98
+ resourceDetectors: [
99
+ resource_detector_container_1.containerDetector,
100
+ resources_1.envDetector,
101
+ resources_1.hostDetector,
102
+ resources_1.osDetector,
103
+ resources_1.processDetector,
104
+ ],
105
+ });
106
+ sdk.start();
107
+ console.log('Tracing sdk started');
108
+ const signals = ['SIGTERM', 'SIGINT'];
109
+ const listener = async () => {
110
+ try {
111
+ console.log('[SIGTERM] Tracing terminating...');
112
+ await sdk.shutdown();
113
+ console.log('Tracing terminated');
114
+ }
115
+ catch (error) {
116
+ console.log('Error terminating tracing', error);
117
+ // eslint-disable-next-line unicorn/no-process-exit
118
+ process.exit(1);
119
+ }
120
+ finally {
121
+ // eslint-disable-next-line unicorn/no-process-exit
122
+ process.exit(0);
123
+ }
124
+ };
125
+ for (const signal of signals) {
126
+ process.on(signal, listener);
127
+ }
128
+ //# sourceMappingURL=opentelemetry.init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opentelemetry.init.js","sourceRoot":"","sources":["../../src/opentelemetry/opentelemetry.init.ts"],"names":[],"mappings":";;AAEA,4CAA2E;AAC3E,0FAAwF;AACxF,8CAA0D;AAC1D,sFAA4E;AAC5E,gEAA8E;AAC9E,4FAA+E;AAC/E,wDAMkC;AAClC,sDAAkD;AAClD,8EAAiF;AACjF,yCAA2D;AAC3D,yCAAoC;AACpC,+CAAmC;AAEnC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;AACzD,IAAI,gBAAgB,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,CAAC;IACzD,UAAI,CAAC,SAAS,CACZ,IAAI,uBAAiB,EAAE;IACvB,wBAAwB;IACxB,kBAAY,CAAC,gBAAgB,CAAC,CAC/B,CAAC;AACJ,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAC1C,CAAC;AAED,8DAA8D;AAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,IAAA,mBAAO,EAAC,IAAA,kBAAG,GAAE,EAAE,cAAc,CAAC,CAAC,CAAC;AAC7D,MAAM,yBAAyB,GAAU,IAAA,wDAA2B,EAAC;IACnE,mCAAmC,EAAE;QACnC,oDAAoD;QACpD,iBAAiB,EAAE,IAAI;KACxB;IACD,wCAAwC,EAAE;QACxC,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;YACnC,IAAI,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;gBAC1C,IAAI,CAAC,YAAY,CACf,gBA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,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;QAChD,mDAAmD;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,mDAAmD;QACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Path to file that should be required to enable opentelemetry tracing
3
+ */
4
+ export declare const OPENTELEMETRY_INIT_PATH: string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPENTELEMETRY_INIT_PATH = void 0;
4
+ const node_path_1 = require("node:path");
5
+ /**
6
+ * Path to file that should be required to enable opentelemetry tracing
7
+ */
8
+ exports.OPENTELEMETRY_INIT_PATH = (0, node_path_1.join)(__dirname, 'opentelemetry.init.js');
9
+ //# sourceMappingURL=opentelemetry.path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opentelemetry.path.js","sourceRoot":"","sources":["../../src/opentelemetry/opentelemetry.path.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC;;GAEG;AACU,QAAA,uBAAuB,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export declare class StartDevCmd {
2
2
  static logger: import("@rsdk/logging").ILogger;
3
- handle(tracing: boolean, pretty: boolean): Promise<void>;
3
+ handle(otel: boolean, pretty: boolean): Promise<void>;
4
4
  }
@@ -20,13 +20,13 @@ const cli_common_1 = require("@rsdk/cli.common");
20
20
  const logging_1 = require("@rsdk/logging");
21
21
  const execa_1 = __importDefault(require("execa"));
22
22
  const node_path_1 = require("node:path");
23
- const tracing_cfg_1 = require("./tracing/tracing.cfg");
23
+ const opentelemetry_path_1 = require("./opentelemetry/opentelemetry.path");
24
24
  class StartDevCmd {
25
25
  static logger = logging_1.LoggerFactory.create(StartDevCmd);
26
- async handle(tracing, pretty) {
27
- const tracingPart = [`-r`, tracing_cfg_1.tracingFilePath];
26
+ async handle(otel, pretty) {
27
+ const tracingPart = [`-r`, opentelemetry_path_1.OPENTELEMETRY_INIT_PATH];
28
28
  const command = [`--watch`];
29
- if (tracing) {
29
+ if (otel) {
30
30
  command.push(...tracingPart);
31
31
  }
32
32
  command.push('-r', 'ts-node/register', 'src/main.ts');
@@ -61,7 +61,7 @@ class StartDevCmd {
61
61
  exports.StartDevCmd = StartDevCmd;
62
62
  __decorate([
63
63
  (0, cli_common_1.SubCmd)('start:dev', 'Start app with watch mode'),
64
- __param(0, (0, cli_common_1.Option)('tracing', 'Enable tracing', Boolean)),
64
+ __param(0, (0, cli_common_1.Option)('otel', 'Enable opentelemetry tracing', Boolean)),
65
65
  __param(1, (0, cli_common_1.Option)('pretty', 'Enable PinoPretty output', String, (v) => v === 'true')),
66
66
  __param(1, (0, cli_common_1.Default)('true')),
67
67
  __metadata("design:type", Function),
@@ -1 +1 @@
1
- {"version":3,"file":"start-dev.cmd.js","sourceRoot":"","sources":["../src/start-dev.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iDAA2D;AAC3D,2CAA8C;AAC9C,kDAA0B;AAC1B,yCAAoC;AAEpC,uDAAwD;AAExD,MAAa,WAAW;IACtB,MAAM,CAAC,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAG5C,AAAN,KAAK,CAAC,MAAM,CAEV,OAAgB,EAGhB,MAAe;QAEf,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,6BAAe,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,CAAC,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AAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,CAAA;IACzE,WAAA,IAAA,oBAAO,EAAC,MAAM,CAAC,CAAA;;;;yCAwCjB"}
@@ -1,4 +1,4 @@
1
1
  export declare class StartCmd {
2
- handle(tracing: boolean): Promise<void>;
3
- private static logger;
2
+ private readonly logger;
3
+ handle(otel: boolean): Promise<void>;
4
4
  }
package/dist/start.cmd.js CHANGED
@@ -16,16 +16,17 @@ exports.StartCmd = void 0;
16
16
  const cli_common_1 = require("@rsdk/cli.common");
17
17
  const logging_1 = require("@rsdk/logging");
18
18
  const node_path_1 = require("node:path");
19
- const tracing_cfg_1 = require("./tracing/tracing.cfg");
19
+ const opentelemetry_path_1 = require("./opentelemetry/opentelemetry.path");
20
20
  class StartCmd {
21
- async handle(tracing) {
22
- StartCmd.logger.trace('execute start command');
21
+ logger = logging_1.LoggerFactory.create(StartCmd);
22
+ async handle(otel) {
23
+ this.logger.trace('execute start command');
23
24
  try {
24
- if (tracing) {
25
- require(tracing_cfg_1.tracingFilePath);
25
+ if (otel) {
26
+ require(opentelemetry_path_1.OPENTELEMETRY_INIT_PATH);
26
27
  }
27
28
  const appFile = (0, node_path_1.resolve)(`dist/app.js`);
28
- StartCmd.logger.trace('resolved appFile', { appFile });
29
+ this.logger.trace('resolved appFile', { appFile });
29
30
  // eslint-disable-next-line @typescript-eslint/no-var-requires
30
31
  const app = require(appFile).app;
31
32
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -35,16 +36,15 @@ class StartCmd {
35
36
  await app.run();
36
37
  }
37
38
  catch (error) {
38
- StartCmd.logger.error(error);
39
+ this.logger.error(error);
39
40
  throw error;
40
41
  }
41
42
  }
42
- static logger = logging_1.LoggerFactory.create(StartCmd);
43
43
  }
44
44
  exports.StartCmd = StartCmd;
45
45
  __decorate([
46
46
  (0, cli_common_1.SubCmd)('start', 'Start built app'),
47
- __param(0, (0, cli_common_1.Option)('tracing', 'Enable tracing', Boolean)),
47
+ __param(0, (0, cli_common_1.Option)('otel', 'Enable opentelemetry tracing', Boolean)),
48
48
  __metadata("design:type", Function),
49
49
  __metadata("design:paramtypes", [Boolean]),
50
50
  __metadata("design:returntype", Promise)
@@ -1 +1 @@
1
- {"version":3,"file":"start.cmd.js","sourceRoot":"","sources":["../src/start.cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAAkD;AAClD,2CAA8C;AAC9C,yCAAoC;AAEpC,uDAAwD;AAExD,MAAa,QAAQ;IAEb,AAAN,KAAK,CAAC,MAAM,CACoC,OAAgB;QAE9D,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAE/C,IAAI,CAAC;YACH,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,6BAAe,CAAC,CAAC;YAC3B,CAAC;YAED,MAAM,OAAO,GAAG,IAAA,mBAAO,EAAC,aAAa,CAAC,CAAC;YAEvC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YACvD,8DAA8D;YAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC;YACjC,8DAA8D;YAC9D,IAAI,CAAC,CAAC,GAAG,YAAY,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;gBACxD,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAc,CAAC,CAAC;YACtC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;;AA5BzD,4BA6BC;AA3BO;IADL,IAAA,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C;IAEhC,WAAA,IAAA,mBAAM,EAAC,MAAM,EAAE,8BAA8B,EAAE,OAAO,CAAC,CAAA;;;;sCAuBzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/cli.cmd.start",
3
- "version": "5.0.0-next.1",
3
+ "version": "5.0.0-next.3",
4
4
  "description": "Start command for rsdk cli",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -18,13 +18,59 @@
18
18
  "commander": "^12.0.0",
19
19
  "dotenv": "^16.3.1",
20
20
  "execa": "^5.1.1",
21
- "listr2": "^6.6.1",
22
21
  "yaml": "^2.3.1"
23
22
  },
24
23
  "peerDependencies": {
24
+ "@nestjs/common": "^10.0.0",
25
+ "@nestjs/core": "^10.0.0",
26
+ "@opentelemetry/api": "1.7.0",
27
+ "@opentelemetry/auto-instrumentations-node": "0.40.2",
28
+ "@opentelemetry/core": "1.18.1",
29
+ "@opentelemetry/exporter-trace-otlp-http": "0.45.1",
30
+ "@opentelemetry/propagator-b3": "1.18.1",
31
+ "@opentelemetry/resource-detector-container": "^0.3.11",
32
+ "@opentelemetry/resources": "1.18.1",
33
+ "@opentelemetry/sdk-node": "0.45.1",
34
+ "@opentelemetry/sdk-trace-node": "1.18.1",
35
+ "@opentelemetry/semantic-conventions": "1.18.1",
36
+ "@rsdk/actx": "*",
25
37
  "@rsdk/cli.common": "*",
26
38
  "@rsdk/core": "*",
27
- "@rsdk/logging": "*"
39
+ "@rsdk/logging": "*",
40
+ "reflect-metadata": "^0.1.12 || ^0.2.0",
41
+ "rxjs": "^7.8.1"
28
42
  },
29
- "gitHead": "782da71b758d4e477d970b285774a435580b4dc2"
43
+ "peerDependenciesMeta": {
44
+ "@opentelemetry/api": {
45
+ "optional": true
46
+ },
47
+ "@opentelemetry/auto-instrumentations-node": {
48
+ "optional": true
49
+ },
50
+ "@opentelemetry/core": {
51
+ "optional": true
52
+ },
53
+ "@opentelemetry/exporter-trace-otlp-http": {
54
+ "optional": true
55
+ },
56
+ "@opentelemetry/propagator-b3": {
57
+ "optional": true
58
+ },
59
+ "@opentelemetry/resource-detector-container": {
60
+ "optional": true
61
+ },
62
+ "@opentelemetry/resources": {
63
+ "optional": true
64
+ },
65
+ "@opentelemetry/sdk-node": {
66
+ "optional": true
67
+ },
68
+ "@opentelemetry/sdk-trace-node": {
69
+ "optional": true
70
+ },
71
+ "@opentelemetry/semantic-conventions": {
72
+ "optional": true
73
+ }
74
+ },
75
+ "gitHead": "c75ce1d8983ba69a6f855ba19536d28be0a9c519"
30
76
  }
@@ -0,0 +1,144 @@
1
+ /*instrumentation.ts*/
2
+ import type { Span } from '@opentelemetry/api';
3
+ import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
4
+ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
5
+ import { CompositePropagator } from '@opentelemetry/core';
6
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
7
+ import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';
8
+ import { containerDetector } from '@opentelemetry/resource-detector-container';
9
+ import {
10
+ envDetector,
11
+ hostDetector,
12
+ osDetector,
13
+ processDetector,
14
+ Resource,
15
+ } from '@opentelemetry/resources';
16
+ import { NodeSDK } from '@opentelemetry/sdk-node';
17
+ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
18
+ import { ClientRequest, IncomingMessage } from 'node:http';
19
+ import { resolve } from 'node:path';
20
+ import { cwd } from 'node:process';
21
+
22
+ const otelDiagLogLevel = process.env.OTEL_DIAG_LOG_LEVEL;
23
+ if (otelDiagLogLevel) {
24
+ console.log('telemetry diag enabled:', otelDiagLogLevel);
25
+ diag.setLogger(
26
+ new DiagConsoleLogger(),
27
+ // @ts-expect-error sdsd
28
+ DiagLogLevel[otelDiagLogLevel],
29
+ );
30
+ } else {
31
+ console.log('telemetry debug disabled');
32
+ }
33
+
34
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
35
+ const manifestData = require(resolve(cwd(), 'package.json'));
36
+ const autoInstumentationOptions: any[] = getNodeAutoInstrumentations({
37
+ '@opentelemetry/instrumentation-fs': {
38
+ // only instrument fs if it is part of another trace
39
+ requireParentSpan: true,
40
+ },
41
+ '@opentelemetry/instrumentation-aws-sdk': {
42
+ enabled: true,
43
+ responseHook: (span, { response }) => {
44
+ if (response.request.commandInput?.Bucket) {
45
+ span.setAttribute(
46
+ 's3.bucket.name',
47
+ response.request.commandInput?.Bucket,
48
+ );
49
+ }
50
+ },
51
+ },
52
+ '@opentelemetry/instrumentation-graphql': {
53
+ allowValues: true,
54
+ },
55
+ '@opentelemetry/instrumentation-http': {
56
+ // не работает с connectionParams
57
+ enabled: true,
58
+ requestHook: (span, request) => {
59
+ if (request instanceof ClientRequest) {
60
+ console.log(request.req.url);
61
+ console.log(request.req.method);
62
+ }
63
+ if (request instanceof IncomingMessage) {
64
+ if (request.method && request.url) {
65
+ span.updateName(`${request.method} ${request.url}`);
66
+ }
67
+ } else if (
68
+ request instanceof ClientRequest &&
69
+ request.req.method &&
70
+ request.req.url
71
+ ) {
72
+ console.log('cr:', request.req.url, request.req.url);
73
+ span.updateName(`${request.req.method} ${request.req.url}`);
74
+ }
75
+ },
76
+ },
77
+ '@opentelemetry/instrumentation-pg': {
78
+ enhancedDatabaseReporting: true,
79
+ },
80
+ '@opentelemetry/instrumentation-pino': {
81
+ enabled: true,
82
+ logHook(_span: Span, record: Record<string, any>) {
83
+ record['resource.service.name'] = otelServiceName;
84
+ },
85
+ },
86
+ '@opentelemetry/instrumentation-grpc': {
87
+ enabled: true,
88
+ },
89
+ '@opentelemetry/instrumentation-nestjs-core': {
90
+ enabled: true,
91
+ },
92
+ });
93
+
94
+ const exporter = new OTLPTraceExporter();
95
+ const otelServiceName = process.env.OTEL_SERVICE_NAME ?? manifestData.name;
96
+
97
+ const sdk = new NodeSDK({
98
+ serviceName: otelServiceName,
99
+ instrumentations: [autoInstumentationOptions],
100
+ resource: new Resource({
101
+ [SemanticResourceAttributes.SERVICE_NAME]: otelServiceName,
102
+ [SemanticResourceAttributes.SERVICE_VERSION]: manifestData.version,
103
+ }),
104
+ traceExporter: exporter,
105
+ textMapPropagator: new CompositePropagator({
106
+ propagators: [
107
+ new B3Propagator(),
108
+ new B3Propagator({
109
+ injectEncoding: B3InjectEncoding.MULTI_HEADER,
110
+ }),
111
+ ],
112
+ }),
113
+ resourceDetectors: [
114
+ containerDetector,
115
+ envDetector,
116
+ hostDetector,
117
+ osDetector,
118
+ processDetector,
119
+ ],
120
+ });
121
+
122
+ sdk.start();
123
+ console.log('Tracing sdk started');
124
+
125
+ const signals = ['SIGTERM', 'SIGINT'] as const;
126
+
127
+ const listener: any = async () => {
128
+ try {
129
+ console.log('[SIGTERM] Tracing terminating...');
130
+ await sdk.shutdown();
131
+ console.log('Tracing terminated');
132
+ } catch (error) {
133
+ console.log('Error terminating tracing', error);
134
+ // eslint-disable-next-line unicorn/no-process-exit
135
+ process.exit(1);
136
+ } finally {
137
+ // eslint-disable-next-line unicorn/no-process-exit
138
+ process.exit(0);
139
+ }
140
+ };
141
+
142
+ for (const signal of signals) {
143
+ process.on(signal, listener);
144
+ }
@@ -0,0 +1,6 @@
1
+ import { join } from 'node:path';
2
+
3
+ /**
4
+ * Path to file that should be required to enable opentelemetry tracing
5
+ */
6
+ export const OPENTELEMETRY_INIT_PATH = join(__dirname, 'opentelemetry.init.js');
@@ -3,22 +3,22 @@ import { LoggerFactory } from '@rsdk/logging';
3
3
  import execa from 'execa';
4
4
  import { resolve } from 'node:path';
5
5
 
6
- import { tracingFilePath } from './tracing/tracing.cfg';
6
+ import { OPENTELEMETRY_INIT_PATH } from './opentelemetry/opentelemetry.path';
7
7
 
8
8
  export class StartDevCmd {
9
9
  static logger = LoggerFactory.create(StartDevCmd);
10
10
 
11
11
  @SubCmd('start:dev', 'Start app with watch mode')
12
12
  async handle(
13
- @Option('tracing', 'Enable tracing', Boolean)
14
- tracing: boolean,
13
+ @Option('otel', 'Enable opentelemetry tracing', Boolean)
14
+ otel: boolean,
15
15
  @Option('pretty', 'Enable PinoPretty output', String, (v) => v === 'true')
16
16
  @Default('true')
17
17
  pretty: boolean,
18
18
  ): Promise<void> {
19
- const tracingPart = [`-r`, tracingFilePath];
19
+ const tracingPart = [`-r`, OPENTELEMETRY_INIT_PATH];
20
20
  const command = [`--watch`];
21
- if (tracing) {
21
+ if (otel) {
22
22
  command.push(...tracingPart);
23
23
  }
24
24
  command.push('-r', 'ts-node/register', 'src/main.ts');
package/src/start.cmd.ts CHANGED
@@ -2,23 +2,25 @@ import { Option, SubCmd } from '@rsdk/cli.common';
2
2
  import { LoggerFactory } from '@rsdk/logging';
3
3
  import { resolve } from 'node:path';
4
4
 
5
- import { tracingFilePath } from './tracing/tracing.cfg';
5
+ import { OPENTELEMETRY_INIT_PATH } from './opentelemetry/opentelemetry.path';
6
6
 
7
7
  export class StartCmd {
8
+ private readonly logger = LoggerFactory.create(StartCmd);
9
+
8
10
  @SubCmd('start', 'Start built app')
9
11
  async handle(
10
- @Option('tracing', 'Enable tracing', Boolean) tracing: boolean,
12
+ @Option('otel', 'Enable opentelemetry tracing', Boolean) otel: boolean,
11
13
  ): Promise<void> {
12
- StartCmd.logger.trace('execute start command');
14
+ this.logger.trace('execute start command');
13
15
 
14
16
  try {
15
- if (tracing) {
16
- require(tracingFilePath);
17
+ if (otel) {
18
+ require(OPENTELEMETRY_INIT_PATH);
17
19
  }
18
20
 
19
21
  const appFile = resolve(`dist/app.js`);
20
22
 
21
- StartCmd.logger.trace('resolved appFile', { appFile });
23
+ this.logger.trace('resolved appFile', { appFile });
22
24
  // eslint-disable-next-line @typescript-eslint/no-var-requires
23
25
  const app = require(appFile).app;
24
26
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -27,10 +29,8 @@ export class StartCmd {
27
29
  }
28
30
  await app.run();
29
31
  } catch (error) {
30
- StartCmd.logger.error(error as Error);
32
+ this.logger.error(error as Error);
31
33
  throw error;
32
34
  }
33
35
  }
34
-
35
- private static logger = LoggerFactory.create(StartCmd);
36
36
  }
@@ -1 +0,0 @@
1
- export declare const tracingFilePath: string;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tracingFilePath = void 0;
4
- exports.tracingFilePath = require.resolve('@rsdk/tracing/dist/tracing.js');
5
- //# sourceMappingURL=tracing.cfg.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracing.cfg.js","sourceRoot":"","sources":["../../src/tracing/tracing.cfg.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export const tracingFilePath = require.resolve('@rsdk/tracing/dist/tracing.js');