@edirect/trace 1.0.18 → 9.0.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.
@@ -1,4 +1,4 @@
1
- declare const _default: {
2
- X_CORRELATION_ID: string;
3
- };
4
- export default _default;
1
+ declare const _default: {
2
+ X_CORRELATION_ID: string;
3
+ };
4
+ export default _default;
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- X_CORRELATION_ID: 'x-correlation-id',
5
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ X_CORRELATION_ID: 'x-correlation-id',
5
+ };
6
6
  //# sourceMappingURL=headers.js.map
@@ -1,2 +1,2 @@
1
- export { default as HEADERS } from './headers';
2
- export { default as TRACE_SERVER } from './servers';
1
+ export { default as HEADERS } from './headers';
2
+ export { default as TRACE_SERVER } from './servers';
@@ -1,11 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TRACE_SERVER = exports.HEADERS = void 0;
7
- var headers_1 = require("./headers");
8
- Object.defineProperty(exports, "HEADERS", { enumerable: true, get: function () { return __importDefault(headers_1).default; } });
9
- var servers_1 = require("./servers");
10
- Object.defineProperty(exports, "TRACE_SERVER", { enumerable: true, get: function () { return __importDefault(servers_1).default; } });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TRACE_SERVER = exports.HEADERS = void 0;
7
+ var headers_1 = require("./headers");
8
+ Object.defineProperty(exports, "HEADERS", { enumerable: true, get: function () { return __importDefault(headers_1).default; } });
9
+ var servers_1 = require("./servers");
10
+ Object.defineProperty(exports, "TRACE_SERVER", { enumerable: true, get: function () { return __importDefault(servers_1).default; } });
11
11
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- declare const _default: {
2
- JAEGER: string;
3
- ELASTIC_APM: string;
4
- OTLP: string;
5
- };
6
- export default _default;
1
+ declare const _default: {
2
+ JAEGER: string;
3
+ ELASTIC_APM: string;
4
+ OTLP: string;
5
+ };
6
+ export default _default;
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- JAEGER: 'JAEGER',
5
- ELASTIC_APM: 'ELASTIC_APM',
6
- OTLP: 'OTLP',
7
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ JAEGER: 'JAEGER',
5
+ ELASTIC_APM: 'ELASTIC_APM',
6
+ OTLP: 'OTLP',
7
+ };
8
8
  //# sourceMappingURL=servers.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * as middlewares from './middlewares';
2
- export * as utils from './utils';
3
- export * as constants from './constants';
4
- export * as services from './services';
1
+ export * as middlewares from './middlewares';
2
+ export * as utils from './utils';
3
+ export * as constants from './constants';
4
+ export * as services from './services';
package/dist/index.js CHANGED
@@ -1,27 +1,31 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.services = exports.constants = exports.utils = exports.middlewares = void 0;
23
- exports.middlewares = __importStar(require("./middlewares"));
24
- exports.utils = __importStar(require("./utils"));
25
- exports.constants = __importStar(require("./constants"));
26
- exports.services = __importStar(require("./services"));
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.services = exports.constants = exports.utils = exports.middlewares = void 0;
27
+ exports.middlewares = __importStar(require("./middlewares"));
28
+ exports.utils = __importStar(require("./utils"));
29
+ exports.constants = __importStar(require("./constants"));
30
+ exports.services = __importStar(require("./services"));
27
31
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA6C;AAC7C,iDAAiC;AACjC,yDAAyC;AACzC,uDAAuC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA6C;AAC7C,iDAAiC;AACjC,yDAAyC;AACzC,uDAAuC"}
@@ -1,5 +1,5 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- declare class CLS {
3
- static middleware(req: Request, res: Response, next: NextFunction): void;
4
- }
5
- export default CLS;
1
+ import { Request, Response, NextFunction } from 'express';
2
+ declare class CLS {
3
+ static middleware(req: Request, res: Response, next: NextFunction): void;
4
+ }
5
+ export default CLS;
@@ -1,30 +1,34 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const cls = __importStar(require("cls-hooked"));
23
- class CLS {
24
- static middleware(req, res, next) {
25
- const nameSpace = cls.createNamespace('trace');
26
- nameSpace.run(() => next());
27
- }
28
- }
29
- exports.default = CLS;
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const cls = __importStar(require("cls-hooked"));
27
+ class CLS {
28
+ static middleware(req, res, next) {
29
+ const nameSpace = cls.createNamespace('trace');
30
+ nameSpace.run(() => next());
31
+ }
32
+ }
33
+ exports.default = CLS;
30
34
  //# sourceMappingURL=CLS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CLS.js","sourceRoot":"","sources":["../../src/middlewares/CLS.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAGlC,MAAM,GAAG;IAOP,MAAM,CAAC,UAAU,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/C,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"CLS.js","sourceRoot":"","sources":["../../src/middlewares/CLS.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAGlC,MAAM,GAAG;IAOP,MAAM,CAAC,UAAU,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/C,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,kBAAe,GAAG,CAAC"}
@@ -1,5 +1,5 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- declare class Body {
3
- body: (req: Request, _: Response, next: NextFunction) => void;
4
- }
5
- export default Body;
1
+ import { NextFunction, Request, Response } from 'express';
2
+ declare class Body {
3
+ body: (req: Request, _: Response, next: NextFunction) => void;
4
+ }
5
+ export default Body;
@@ -1,28 +1,28 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const api_1 = __importDefault(require("@opentelemetry/api"));
7
- class Body {
8
- constructor() {
9
- this.body = (req, _, next) => {
10
- let span = api_1.default.trace.getSpan(api_1.default.context.active());
11
- if (!span)
12
- span = api_1.default.trace.getTracer("edirect/trace", "1").startSpan(req.originalUrl.split('?').shift());
13
- const bodyString = JSON.stringify(req.body);
14
- const charsLength = bodyString.length;
15
- const chunks = [];
16
- for (let i = 0; i < charsLength; i += 1000) {
17
- chunks.push(bodyString.substring(i, i + 1000));
18
- }
19
- span.setAttribute('http_request_body', chunks);
20
- if (req.query)
21
- span.setAttribute('http_request_url_query', new URLSearchParams(req.query).toString());
22
- span.setAttribute('http_request_url_full', req.originalUrl);
23
- next();
24
- };
25
- }
26
- }
27
- exports.default = Body;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const api_1 = __importDefault(require("@opentelemetry/api"));
7
+ class Body {
8
+ constructor() {
9
+ this.body = (req, _, next) => {
10
+ let span = api_1.default.trace.getSpan(api_1.default.context.active());
11
+ if (!span)
12
+ span = api_1.default.trace.getTracer("edirect/trace", "1").startSpan(req.originalUrl.split('?').shift());
13
+ const bodyString = JSON.stringify(req.body);
14
+ const charsLength = bodyString.length;
15
+ const chunks = [];
16
+ for (let i = 0; i < charsLength; i += 1000) {
17
+ chunks.push(bodyString.substring(i, i + 1000));
18
+ }
19
+ span.setAttribute('http_request_body', chunks);
20
+ if (req.query)
21
+ span.setAttribute('http_request_url_query', new URLSearchParams(req.query).toString());
22
+ span.setAttribute('http_request_url_full', req.originalUrl);
23
+ next();
24
+ };
25
+ }
26
+ }
27
+ exports.default = Body;
28
28
  //# sourceMappingURL=body.js.map
@@ -1,3 +1,3 @@
1
- export { default as Trace } from './trace';
2
- export { default as CLS } from './CLS';
3
- export { default as Body } from './body';
1
+ export { default as Trace } from './trace';
2
+ export { default as CLS } from './CLS';
3
+ export { default as Body } from './body';
@@ -1,13 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Body = exports.CLS = exports.Trace = void 0;
7
- var trace_1 = require("./trace");
8
- Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return __importDefault(trace_1).default; } });
9
- var CLS_1 = require("./CLS");
10
- Object.defineProperty(exports, "CLS", { enumerable: true, get: function () { return __importDefault(CLS_1).default; } });
11
- var body_1 = require("./body");
12
- Object.defineProperty(exports, "Body", { enumerable: true, get: function () { return __importDefault(body_1).default; } });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Body = exports.CLS = exports.Trace = void 0;
7
+ var trace_1 = require("./trace");
8
+ Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return __importDefault(trace_1).default; } });
9
+ var CLS_1 = require("./CLS");
10
+ Object.defineProperty(exports, "CLS", { enumerable: true, get: function () { return __importDefault(CLS_1).default; } });
11
+ var body_1 = require("./body");
12
+ Object.defineProperty(exports, "Body", { enumerable: true, get: function () { return __importDefault(body_1).default; } });
13
13
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- declare class Trace {
3
- static trace(req: Request, res: Response, next: NextFunction): void;
4
- }
5
- export default Trace;
1
+ import { Request, Response, NextFunction } from 'express';
2
+ declare class Trace {
3
+ static trace(req: Request, res: Response, next: NextFunction): void;
4
+ }
5
+ export default Trace;
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const constants_1 = require("../constants");
4
- const uuid_1 = require("uuid");
5
- const utils_1 = require("../utils");
6
- class Trace {
7
- static trace(req, res, next) {
8
- let cid = (0, uuid_1.v4)();
9
- try {
10
- if (req.headers[constants_1.HEADERS.X_CORRELATION_ID]) {
11
- cid = req.headers[constants_1.HEADERS.X_CORRELATION_ID];
12
- }
13
- else {
14
- req.headers[constants_1.HEADERS.X_CORRELATION_ID] = cid;
15
- }
16
- }
17
- catch (error) {
18
- console.log(error);
19
- }
20
- finally {
21
- utils_1.Trace.setCID(cid);
22
- return next();
23
- }
24
- }
25
- }
26
- exports.default = Trace;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const uuid_1 = require("uuid");
5
+ const utils_1 = require("../utils");
6
+ class Trace {
7
+ static trace(req, res, next) {
8
+ let cid = (0, uuid_1.v4)();
9
+ try {
10
+ if (req.headers[constants_1.HEADERS.X_CORRELATION_ID]) {
11
+ cid = req.headers[constants_1.HEADERS.X_CORRELATION_ID];
12
+ }
13
+ else {
14
+ req.headers[constants_1.HEADERS.X_CORRELATION_ID] = cid;
15
+ }
16
+ }
17
+ catch (error) {
18
+ console.log(error);
19
+ }
20
+ finally {
21
+ utils_1.Trace.setCID(cid);
22
+ return next();
23
+ }
24
+ }
25
+ }
26
+ exports.default = Trace;
27
27
  //# sourceMappingURL=trace.js.map
@@ -1,10 +1,10 @@
1
- declare class APM {
2
- serviceName: string;
3
- serverUrl: string;
4
- traceServer: string;
5
- constructor(serviceName?: string, serverUrl?: string, traceServer?: string);
6
- private startElastic;
7
- private startOtlp;
8
- startTrace(): void;
9
- }
10
- export default APM;
1
+ declare class APM {
2
+ serviceName: string;
3
+ serverUrl: string;
4
+ traceServer: string;
5
+ constructor(serviceName?: string, serverUrl?: string, traceServer?: string);
6
+ private startElastic;
7
+ private startOtlp;
8
+ startTrace(): void;
9
+ }
10
+ export default APM;
@@ -1,79 +1,79 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
7
- const config_1 = require("@edirect/config");
8
- const constants_1 = require("../constants");
9
- const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
10
- const exporter_otlp_http_1 = require("@opentelemetry/exporter-otlp-http");
11
- const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
12
- const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
13
- const resources_1 = require("@opentelemetry/resources");
14
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
15
- const instrumentation_1 = require("@opentelemetry/instrumentation");
16
- const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
17
- const instrumentation_express_1 = require("@opentelemetry/instrumentation-express");
18
- const config = new config_1.ConfigService(`.${process.env.NODE_ENV || 'development'}.env`);
19
- const env = config.getConfig();
20
- class APM {
21
- constructor(serviceName, serverUrl, traceServer) {
22
- this.serviceName = serviceName || env.APM_SERVICE_NAME || 'service-test';
23
- this.serverUrl = serverUrl || env.APM_SERVER_URL || 'localhost';
24
- this.traceServer = traceServer || env.TRACE_SERVER || '';
25
- }
26
- startElastic() {
27
- elastic_apm_node_1.default.start({
28
- serviceName: this.serviceName,
29
- serverUrl: this.serverUrl,
30
- logUncaughtExceptions: true,
31
- useElasticTraceparentHeader: true,
32
- usePathAsTransactionName: true,
33
- captureBody: 'all',
34
- captureExceptions: true,
35
- sanitizeFieldNames: [],
36
- });
37
- return;
38
- }
39
- startOtlp() {
40
- let exporter;
41
- switch (this.traceServer) {
42
- case constants_1.TRACE_SERVER.JAEGER:
43
- exporter = new exporter_jaeger_1.JaegerExporter({ host: this.serverUrl });
44
- break;
45
- case constants_1.TRACE_SERVER.OTLP:
46
- exporter = new exporter_otlp_http_1.OTLPTraceExporter({ url: this.serverUrl });
47
- break;
48
- default:
49
- return;
50
- }
51
- const provider = new sdk_trace_node_1.NodeTracerProvider({
52
- resource: new resources_1.Resource({
53
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: this.serviceName,
54
- }),
55
- });
56
- provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
57
- provider.register();
58
- (0, instrumentation_1.registerInstrumentations)({
59
- instrumentations: [
60
- new instrumentation_http_1.HttpInstrumentation(),
61
- new instrumentation_express_1.ExpressInstrumentation({ ignoreLayers: ['healthcheck'] }),
62
- ],
63
- });
64
- return;
65
- }
66
- startTrace() {
67
- switch (this.traceServer) {
68
- case constants_1.TRACE_SERVER.ELASTIC_APM:
69
- this.startElastic();
70
- break;
71
- default:
72
- this.startOtlp();
73
- break;
74
- }
75
- return;
76
- }
77
- }
78
- exports.default = APM;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
7
+ const config_1 = require("@edirect/config");
8
+ const constants_1 = require("../constants");
9
+ const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
10
+ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
11
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
12
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
13
+ const resources_1 = require("@opentelemetry/resources");
14
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
15
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
16
+ const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
17
+ const instrumentation_express_1 = require("@opentelemetry/instrumentation-express");
18
+ const config = new config_1.ConfigService(`.${process.env.NODE_ENV || 'development'}.env`);
19
+ const env = config.getConfig();
20
+ class APM {
21
+ constructor(serviceName, serverUrl, traceServer) {
22
+ this.serviceName = serviceName || env.APM_SERVICE_NAME || 'service-test';
23
+ this.serverUrl = serverUrl || env.APM_SERVER_URL || 'localhost';
24
+ this.traceServer = traceServer || env.TRACE_SERVER || '';
25
+ }
26
+ startElastic() {
27
+ elastic_apm_node_1.default.start({
28
+ serviceName: this.serviceName,
29
+ serverUrl: this.serverUrl,
30
+ logUncaughtExceptions: true,
31
+ useElasticTraceparentHeader: true,
32
+ usePathAsTransactionName: true,
33
+ captureBody: 'all',
34
+ captureExceptions: true,
35
+ sanitizeFieldNames: [],
36
+ });
37
+ return;
38
+ }
39
+ startOtlp() {
40
+ let exporter;
41
+ switch (this.traceServer) {
42
+ case constants_1.TRACE_SERVER.JAEGER:
43
+ exporter = new exporter_jaeger_1.JaegerExporter({ host: this.serverUrl });
44
+ break;
45
+ case constants_1.TRACE_SERVER.OTLP:
46
+ exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: this.serverUrl });
47
+ break;
48
+ default:
49
+ return;
50
+ }
51
+ const provider = new sdk_trace_node_1.NodeTracerProvider({
52
+ resource: new resources_1.Resource({
53
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: this.serviceName,
54
+ }),
55
+ });
56
+ provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
57
+ provider.register();
58
+ (0, instrumentation_1.registerInstrumentations)({
59
+ instrumentations: [
60
+ new instrumentation_http_1.HttpInstrumentation({ ignoreIncomingPaths: ['/healthcheck', 'healthcheck'] }),
61
+ new instrumentation_express_1.ExpressInstrumentation({ ignoreLayers: ['/healthcheck', 'healthcheck'] }),
62
+ ],
63
+ });
64
+ return;
65
+ }
66
+ startTrace() {
67
+ switch (this.traceServer) {
68
+ case constants_1.TRACE_SERVER.ELASTIC_APM:
69
+ this.startElastic();
70
+ break;
71
+ default:
72
+ this.startOtlp();
73
+ break;
74
+ }
75
+ return;
76
+ }
77
+ }
78
+ exports.default = APM;
79
79
  //# sourceMappingURL=APM.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"APM.js","sourceRoot":"","sources":["../../src/services/APM.ts"],"names":[],"mappings":";;;;;AAAA,wEAAmC;AACnC,4CAAgD;AAChD,4CAA4C;AAC5C,oEAAgE;AAChE,0EAAsE;AACtE,kEAAoE;AACpE,kEAAmE;AACnE,wDAAoD;AACpD,8EAAiF;AACjF,oEAA0E;AAC1E,8EAA0E;AAC1E,oFAAgF;AAEhF,MAAM,MAAM,GAAG,IAAI,sBAAa,CAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,MAAM,CAChD,CAAC;AACF,MAAM,GAAG,GAA2B,MAAM,CAAC,SAAS,EAAE,CAAC;AAEvD,MAAM,GAAG;IAKP,YAAY,WAAoB,EAAE,SAAkB,EAAE,WAAoB;QACxE,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,GAAG,CAAC,gBAAgB,IAAI,cAAc,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,GAAG,CAAC,cAAc,IAAI,WAAW,CAAC;QAChE,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,GAAG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"}
@@ -1 +1 @@
1
- export { default as APM } from './APM';
1
+ export { default as APM } from './APM';
@@ -1,9 +1,9 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.APM = void 0;
7
- var APM_1 = require("./APM");
8
- Object.defineProperty(exports, "APM", { enumerable: true, get: function () { return __importDefault(APM_1).default; } });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.APM = void 0;
7
+ var APM_1 = require("./APM");
8
+ Object.defineProperty(exports, "APM", { enumerable: true, get: function () { return __importDefault(APM_1).default; } });
9
9
  //# sourceMappingURL=index.js.map