@autofleet/outbreak 1.0.4 → 2.0.1
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/config.d.ts +16 -0
- package/dist/{src/config.js → config.js} +4 -6
- package/dist/config.js.map +1 -0
- package/dist/const.d.ts +6 -0
- package/dist/const.js +9 -0
- package/dist/const.js.map +1 -0
- package/dist/http_wrapper.d.ts +2 -0
- package/dist/{src/http_wrapper.js → http_wrapper.js} +40 -27
- package/dist/http_wrapper.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/tracer.d.ts +18 -0
- package/dist/{src/tracer.js → tracer.js} +13 -9
- package/dist/tracer.js.map +1 -0
- package/package.json +49 -32
- package/readme.md +1 -1
- package/dist/src/config.d.ts +0 -18
- package/dist/src/config.js.map +0 -1
- package/dist/src/example.d.ts +0 -1
- package/dist/src/example.js +0 -46
- package/dist/src/example.js.map +0 -1
- package/dist/src/http_wrapper.d.ts +0 -1
- package/dist/src/http_wrapper.js.map +0 -1
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -55
- package/dist/src/index.js.map +0 -1
- package/dist/src/tracer.d.ts +0 -10
- package/dist/src/tracer.js.map +0 -1
- package/dist/tests/http-wrapper.test.d.ts +0 -1
- package/dist/tests/http-wrapper.test.js +0 -202
- package/dist/tests/http-wrapper.test.js.map +0 -1
- package/examples/example.ts +0 -39
- package/jest.config.js +0 -14
- package/nodemon.json +0 -6
- package/src/config.ts +0 -58
- package/src/example.ts +0 -39
- package/src/http_wrapper.ts +0 -114
- package/src/index.ts +0 -59
- package/src/tracer.ts +0 -77
- package/tests/http-wrapper.test.ts +0 -206
- package/tsconfig.json +0 -30
package/dist/config.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
interface Overrides {
|
2
|
+
setAndPropagateCorrelationId?: boolean;
|
3
|
+
propagateInResponses?: boolean;
|
4
|
+
headersToPropagate?: string[];
|
5
|
+
headersPrefix?: string;
|
6
|
+
}
|
7
|
+
export interface LoadedConfig extends Required<Pick<Overrides, 'setAndPropagateCorrelationId' | 'propagateInResponses' | 'headersPrefix'>> {
|
8
|
+
correlationIdHeader: string;
|
9
|
+
headersToCollect: string[];
|
10
|
+
headersToInject: string[];
|
11
|
+
}
|
12
|
+
declare const _default: {
|
13
|
+
load: (overrides?: Overrides) => LoadedConfig;
|
14
|
+
correlationIdHeader: string;
|
15
|
+
};
|
16
|
+
export default _default;
|
@@ -18,16 +18,14 @@ const load = (overrides = {}) => {
|
|
18
18
|
'x-variant-id',
|
19
19
|
], headersPrefix = 'x-af-', } = overrides;
|
20
20
|
validateHeaderList(headersToPropagate);
|
21
|
-
const
|
22
|
-
|
23
|
-
|
24
|
-
headersToInject = [correlationIdHeader].concat(headersToCollect);
|
25
|
-
}
|
21
|
+
const headersToInject = setAndPropagateCorrelationId === true
|
22
|
+
? [correlationIdHeader, ...headersToPropagate]
|
23
|
+
: headersToPropagate;
|
26
24
|
return {
|
27
25
|
setAndPropagateCorrelationId,
|
28
26
|
propagateInResponses,
|
29
27
|
correlationIdHeader,
|
30
|
-
headersToCollect,
|
28
|
+
headersToCollect: headersToPropagate,
|
31
29
|
headersToInject,
|
32
30
|
headersPrefix,
|
33
31
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAAA,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC,MAAM,kBAAkB,GAAG,CAAC,OAAiB,EAAQ,EAAE;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,iEAAiE;IACjE,MAAM,eAAe,GAAG,iBAAiB,CAAC;IAE1C,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhG,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,yCAAyC,cAAc,EAAE,CAAC,CAAC;KAC5E;AACH,CAAC,CAAC;AAeF,MAAM,IAAI,GAAG,CAAC,YAAuB,EAAE,EAAgB,EAAE;IACvD,MAAM,EACJ,4BAA4B,GAAG,IAAI,EACnC,oBAAoB,GAAG,KAAK,EAC5B,kBAAkB,GAAG;QACnB,cAAc;QACd,cAAc;KACf,EACD,aAAa,GAAG,OAAO,GACxB,GAAG,SAAS,CAAC;IAEd,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IAEvC,MAAM,eAAe,GAAG,4BAA4B,KAAK,IAAI;QAC3D,CAAC,CAAC,CAAC,mBAAmB,EAAE,GAAG,kBAAkB,CAAC;QAC9C,CAAC,CAAC,kBAAkB,CAAC;IAEvB,OAAO;QACL,4BAA4B;QAC5B,oBAAoB;QACpB,mBAAmB;QACnB,gBAAgB,EAAE,kBAAkB;QACpC,eAAe;QACf,aAAa;KACd,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe;IACb,IAAI;IACJ,mBAAmB;CACpB,CAAC"}
|
package/dist/const.d.ts
ADDED
package/dist/const.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACxB,YAAY,EAAE,aAAa;IAC3B,UAAU,EAAE,WAAW;IACvB,MAAM,EAAE,QAAQ;CACR,CAAC"}
|
@@ -1,27 +1,41 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
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
|
+
});
|
5
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
6
19
|
if (mod && mod.__esModule) return mod;
|
7
20
|
var result = {};
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
9
|
-
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);
|
10
23
|
return result;
|
11
24
|
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
12
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
|
14
|
-
const
|
15
|
-
const shortid_1 = __importDefault(require("shortid"));
|
29
|
+
const node_http_1 = __importDefault(require("node:http"));
|
30
|
+
const node_crypto_1 = require("node:crypto");
|
16
31
|
const tracer_1 = __importStar(require("./tracer"));
|
17
|
-
const
|
18
|
-
const
|
19
|
-
const
|
32
|
+
const const_1 = require("./const");
|
33
|
+
const generateShortId = () => (0, node_crypto_1.randomUUID)().split('-')[0];
|
34
|
+
const originalHttpCreateServer = node_http_1.default.createServer;
|
35
|
+
const originalRequest = node_http_1.default.request;
|
36
|
+
const originalGet = node_http_1.default.get;
|
20
37
|
function setAndCollectCorrelationId(config, req, res) {
|
21
|
-
|
22
|
-
if (typeof correlationId === 'undefined') {
|
23
|
-
correlationId = shortid_1.default.generate();
|
24
|
-
}
|
38
|
+
const correlationId = req.headers[config.correlationIdHeader] ?? generateShortId();
|
25
39
|
tracer_1.default.currentTrace.context.set(config.correlationIdHeader, correlationId);
|
26
40
|
res.setHeader(config.correlationIdHeader, correlationId);
|
27
41
|
}
|
@@ -43,8 +57,9 @@ function injectInResponse(response, headers) {
|
|
43
57
|
}
|
44
58
|
}
|
45
59
|
function wrappedListener(config, listener) {
|
60
|
+
// @ts-expect-error we add next and error which don't exist on the original type
|
46
61
|
return (req, res, next, error) => {
|
47
|
-
tracer_1.newTrace(
|
62
|
+
(0, tracer_1.newTrace)(const_1.traceTypes.HTTP_REQUEST);
|
48
63
|
if (config.setAndPropagateCorrelationId === true) {
|
49
64
|
setAndCollectCorrelationId(config, req, res);
|
50
65
|
}
|
@@ -52,23 +67,21 @@ function wrappedListener(config, listener) {
|
|
52
67
|
if (config.propagateInResponses) {
|
53
68
|
injectInResponse(res, [config.correlationIdHeader]);
|
54
69
|
}
|
70
|
+
// @ts-expect-error we add next and error which don't exist on the original type
|
55
71
|
listener(req, res, next, error);
|
56
72
|
};
|
57
73
|
}
|
58
74
|
function wrapHttpCreateServer(config) {
|
59
|
-
|
60
|
-
|
75
|
+
function wrappedHttpCreateServer(options, listener) {
|
76
|
+
listener = listener || options;
|
61
77
|
return originalHttpCreateServer(wrappedListener(config, listener));
|
62
|
-
}
|
78
|
+
}
|
79
|
+
return wrappedHttpCreateServer;
|
63
80
|
}
|
64
81
|
function inject(options) {
|
65
82
|
if (tracer_1.default.currentTrace) {
|
66
|
-
|
67
|
-
// eslint-disable-next-line no-param-reassign
|
68
|
-
options.headers = {};
|
69
|
-
}
|
83
|
+
options.headers || (options.headers = {});
|
70
84
|
[...(tracer_1.default.currentTrace.context.keys())].forEach((header) => {
|
71
|
-
// eslint-disable-next-line no-param-reassign
|
72
85
|
options.headers[header] = tracer_1.default.currentTrace.context.get(header);
|
73
86
|
});
|
74
87
|
}
|
@@ -97,9 +110,9 @@ function wrapHttpRequest(originalMethod) {
|
|
97
110
|
return wrappedHttpRequest;
|
98
111
|
}
|
99
112
|
function wrapHttp(config) {
|
100
|
-
|
101
|
-
|
102
|
-
|
113
|
+
node_http_1.default.createServer = wrapHttpCreateServer(config);
|
114
|
+
node_http_1.default.request = wrapHttpRequest(originalRequest);
|
115
|
+
node_http_1.default.get = wrapHttpRequest(originalGet);
|
103
116
|
}
|
104
117
|
exports.default = wrapHttp;
|
105
118
|
//# sourceMappingURL=http_wrapper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"http_wrapper.js","sourceRoot":"","sources":["../src/http_wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA6B;AAC7B,6CAAyC;AAEzC,mDAA4C;AAE5C,mCAAqC;AAErC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,IAAA,wBAAU,GAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzD,MAAM,wBAAwB,GAAG,mBAAI,CAAC,YAAY,CAAC;AACnD,MAAM,eAAe,GAAG,mBAAI,CAAC,OAAO,CAAC;AACrC,MAAM,WAAW,GAAG,mBAAI,CAAC,GAAG,CAAC;AAE7B,SAAS,0BAA0B,CAAC,MAAoB,EAAE,GAAyB,EAAE,GAA8C;IACjI,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,eAAe,EAAE,CAAC;IACnF,gBAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,EAAE,aAAuB,CAAC,CAAC;IACrF,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,OAAO,CAAC,GAAy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AC,CAAC;QAEhB,OAAO,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;IAID,SAAS,kBAAkB,CAAC,GAAG,IAAI;QACjC,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,GAAiB,CAAC;QACtB,IAAI,QAAQ,CAAC;QAEb,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC;YAChC,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SACzC;QACD,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC;QAC3B,OAAO,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAwB,QAAQ,CAAC,MAAoB;IACnD,mBAAI,CAAC,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACjD,mBAAI,CAAC,OAAO,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,mBAAI,CAAC,GAAG,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC;AAJD,2BAIC"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import winston from 'winston';
|
2
|
+
import * as tracer from './tracer';
|
3
|
+
export { traceTypes } from './const';
|
4
|
+
interface Options {
|
5
|
+
winstonLogger?: winston.Logger;
|
6
|
+
loggerTraceKey?: string;
|
7
|
+
headersPrefix?: string;
|
8
|
+
setAndPropagateCorrelationId?: boolean;
|
9
|
+
headersToPropagate?: string[];
|
10
|
+
}
|
11
|
+
export default function outbreakInitialize(options: Options): void;
|
12
|
+
export declare const getCurrentContext: () => Partial<tracer.Trace>;
|
13
|
+
export declare const newTrace: (type: import("./const").TraceType) => tracer.Trace;
|
package/dist/index.js
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.newTrace = exports.getCurrentContext = exports.traceTypes = void 0;
|
30
|
+
const winston_1 = require("winston");
|
31
|
+
const http_wrapper_1 = __importDefault(require("./http_wrapper"));
|
32
|
+
const config_1 = __importDefault(require("./config"));
|
33
|
+
const tracer = __importStar(require("./tracer"));
|
34
|
+
var const_1 = require("./const");
|
35
|
+
Object.defineProperty(exports, "traceTypes", { enumerable: true, get: function () { return const_1.traceTypes; } });
|
36
|
+
const addMetadataToLog = (loggerTraceKey) => (0, winston_1.format)((info) => {
|
37
|
+
const currentTrace = tracer.getCurrentTrace();
|
38
|
+
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
40
|
+
info[loggerTraceKey] = currentTrace.context.get(config_1.default.correlationIdHeader);
|
41
|
+
}
|
42
|
+
return info;
|
43
|
+
});
|
44
|
+
function outbreakInitialize(options) {
|
45
|
+
(0, http_wrapper_1.default)(config_1.default.load(options));
|
46
|
+
tracer.enable();
|
47
|
+
if (options.winstonLogger) {
|
48
|
+
const traceKey = options.loggerTraceKey || 'traceId';
|
49
|
+
// eslint-disable-next-line no-param-reassign
|
50
|
+
options.winstonLogger.format = winston_1.format.combine(addMetadataToLog(traceKey)(), options.winstonLogger.format);
|
51
|
+
}
|
52
|
+
// Make an attempt to enable async hooks for bluebird, if available
|
53
|
+
try {
|
54
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
55
|
+
const bluebird = require('bluebird');
|
56
|
+
bluebird.config({ asyncHooks: true });
|
57
|
+
}
|
58
|
+
catch (e) { /* ignore */ }
|
59
|
+
}
|
60
|
+
exports.default = outbreakInitialize;
|
61
|
+
const getCurrentContext = () => tracer.getCurrentTrace();
|
62
|
+
exports.getCurrentContext = getCurrentContext;
|
63
|
+
exports.newTrace = tracer.newTrace;
|
64
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA0C;AAE1C,kEAAyC;AACzC,sDAA8B;AAC9B,iDAAmC;AAEnC,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AAUnB,MAAM,gBAAgB,GAAG,CAAC,cAAsB,EAAE,EAAE,CAAC,IAAA,gBAAM,EAAC,CAAC,IAAI,EAAE,EAAE;IACnE,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC9C,IAAI,YAAY,IAAI,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE;QACpE,6CAA6C;QAC7C,IAAI,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAM,CAAC,mBAAmB,CAAC,CAAC;KAC7E;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,SAAwB,kBAAkB,CAAC,OAAgB;IACzD,IAAA,sBAAW,EAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,EAAE,CAAC;IAEhB,IAAI,OAAO,CAAC,aAAa,EAAE;QACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,IAAI,SAAS,CAAC;QACrD,6CAA6C;QAC7C,OAAO,CAAC,aAAa,CAAC,MAAM,GAAG,gBAAM,CAAC,OAAO,CAC3C,gBAAgB,CAAC,QAAQ,CAAC,EAAE,EAC5B,OAAO,CAAC,aAAa,CAAC,MAAM,CAC7B,CAAC;KACH;IAED,mEAAmE;IACnE,IAAI;QACF,8EAA8E;QAC9E,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;KACvC;IAAC,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE;AAC9B,CAAC;AAnBD,qCAmBC;AAEM,MAAM,iBAAiB,GAAG,GAA0B,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;AAA1E,QAAA,iBAAiB,qBAAyD;AAExE,gBAAQ,GAAK,MAAM,UAAC"}
|
package/dist/tracer.d.ts
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import asyncHooks from 'node:async_hooks';
|
2
|
+
import type { TraceType } from './const';
|
3
|
+
interface Tracer {
|
4
|
+
currentTrace: Trace | null;
|
5
|
+
traces: Record<number, Trace>;
|
6
|
+
}
|
7
|
+
declare const tracer: Tracer;
|
8
|
+
declare class Trace {
|
9
|
+
type: string;
|
10
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
11
|
+
readonly context: Map<string, string>;
|
12
|
+
constructor(type: string);
|
13
|
+
}
|
14
|
+
export type { Trace };
|
15
|
+
export declare const enable: () => asyncHooks.AsyncHook;
|
16
|
+
export declare const newTrace: (type: TraceType) => Trace;
|
17
|
+
export declare const getCurrentTrace: () => Partial<Trace>;
|
18
|
+
export default tracer;
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
|
7
|
-
const
|
6
|
+
exports.getCurrentTrace = exports.newTrace = exports.enable = void 0;
|
7
|
+
const node_async_hooks_1 = __importDefault(require("node:async_hooks"));
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
8
9
|
const prevStates = {};
|
9
10
|
const tracer = {
|
10
11
|
currentTrace: null,
|
@@ -34,18 +35,18 @@ function destroy(asyncId) {
|
|
34
35
|
delete prevStates[asyncId];
|
35
36
|
}
|
36
37
|
}
|
37
|
-
const hook =
|
38
|
+
const hook = node_async_hooks_1.default.createHook({
|
38
39
|
init, before, after, destroy,
|
39
40
|
});
|
40
41
|
class Trace {
|
41
42
|
constructor(type) {
|
42
|
-
this.id = uuid_1.default.v1();
|
43
43
|
this.type = type;
|
44
|
+
this.id = (0, node_crypto_1.randomUUID)();
|
44
45
|
this.context = new Map();
|
45
46
|
}
|
46
47
|
}
|
47
48
|
let isTraceEnabled = false;
|
48
|
-
|
49
|
+
const enable = () => {
|
49
50
|
if (isTraceEnabled) {
|
50
51
|
return hook;
|
51
52
|
}
|
@@ -53,12 +54,15 @@ exports.enable = () => {
|
|
53
54
|
isTraceEnabled = true;
|
54
55
|
return hook;
|
55
56
|
};
|
56
|
-
exports.
|
57
|
-
|
57
|
+
exports.enable = enable;
|
58
|
+
const newTrace = (type) => {
|
59
|
+
(0, exports.enable)();
|
58
60
|
tracer.currentTrace = new Trace(type);
|
59
|
-
tracer.traces[
|
61
|
+
tracer.traces[node_async_hooks_1.default.executionAsyncId()] = tracer.currentTrace;
|
60
62
|
return tracer.currentTrace;
|
61
63
|
};
|
62
|
-
exports.
|
64
|
+
exports.newTrace = newTrace;
|
65
|
+
const getCurrentTrace = () => tracer.currentTrace || {};
|
66
|
+
exports.getCurrentTrace = getCurrentTrace;
|
63
67
|
exports.default = tracer;
|
64
68
|
//# sourceMappingURL=tracer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tracer.js","sourceRoot":"","sources":["../src/tracer.ts"],"names":[],"mappings":";;;;;;AAAA,wEAA0C;AAC1C,6CAAyC;AAQzC,MAAM,UAAU,GAA0B,EAAE,CAAC;AAE7C,MAAM,MAAM,GAAW;IACrB,YAAY,EAAE,IAAI;IAClB,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,SAAS,IAAI,CAAC,OAAe,EAAE,IAAY,EAAE,cAAsB;IACjE,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QACjC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;KACxD;AACH,CAAC;AAED,SAAS,MAAM,CAAC,OAAe;IAC7B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAO;KACR;IACD,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC;IAC1C,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,KAAK,CAAC,OAAe;IAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAO;KACR;IACD,MAAM,CAA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D;AAE/E,kBAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
@@ -1,47 +1,64 @@
|
|
1
1
|
{
|
2
2
|
"name": "@autofleet/outbreak",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.1",
|
4
4
|
"description": "",
|
5
|
-
"main": "dist/
|
6
|
-
"
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"type": "module",
|
7
|
+
"types": "dist/index.d.ts",
|
8
|
+
"files": [
|
9
|
+
"dist",
|
10
|
+
"readme.md"
|
11
|
+
],
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git+https://github.com/Autofleet/outbreak.git"
|
15
|
+
},
|
16
|
+
"bugs": {
|
17
|
+
"url": "https://github.com/Autofleet/outbreak/issues"
|
18
|
+
},
|
19
|
+
"homepage": "https://github.com/Autofleet/outbreak#readme",
|
7
20
|
"scripts": {
|
8
|
-
"build": "rm -rf ./dist && tsc",
|
21
|
+
"build": "rm -rf ./dist && tsc -p tsconfig.build.json",
|
9
22
|
"prepublish": "npm run build",
|
10
|
-
"start": "ts-node src/example.ts",
|
11
|
-
"dev": "
|
12
|
-
"lint": "
|
13
|
-
"test": "
|
14
|
-
"coverage": "
|
23
|
+
"start": "node --loader ts-node/esm src/example.ts",
|
24
|
+
"dev": "node --watch --loader ts-node/esm src/example.ts",
|
25
|
+
"lint": "eslint .",
|
26
|
+
"test": "vitest",
|
27
|
+
"coverage": "vitest run --coverage"
|
15
28
|
},
|
16
29
|
"author": "Dor Shay",
|
17
30
|
"license": "ISC",
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"axios": "^0.19.2",
|
21
|
-
"express": "^4.17.1",
|
22
|
-
"jsonwebtoken": "^8.5.1",
|
23
|
-
"shortid": "^2.2.15",
|
24
|
-
"uuid": "^3.4.0",
|
25
|
-
"winston": "^3.2.1"
|
31
|
+
"engines": {
|
32
|
+
"node": "^18 || ^20 || >=22"
|
26
33
|
},
|
27
34
|
"peerDependencies": {
|
28
|
-
"bluebird": "*"
|
35
|
+
"bluebird": "*",
|
36
|
+
"winston": "^3"
|
37
|
+
},
|
38
|
+
"peerDependenciesMeta": {
|
39
|
+
"bluebird": {
|
40
|
+
"optional": true
|
41
|
+
},
|
42
|
+
"winston": {
|
43
|
+
"optional": true
|
44
|
+
}
|
29
45
|
},
|
30
46
|
"devDependencies": {
|
31
|
-
"@types/
|
32
|
-
"@types/
|
33
|
-
"@
|
34
|
-
"@typescript-eslint/
|
35
|
-
"
|
47
|
+
"@types/axios": "^0.9.36",
|
48
|
+
"@types/express": "^4.17.21",
|
49
|
+
"@types/node": "^18",
|
50
|
+
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
51
|
+
"@typescript-eslint/parser": "^7.16.1",
|
52
|
+
"@vitest/coverage-v8": "^3.0.5",
|
53
|
+
"agentkeepalive": "^4.6.0",
|
54
|
+
"axios": "^0.19.2",
|
36
55
|
"bluebird": "^3.7.2",
|
37
|
-
"eslint": "^
|
38
|
-
"eslint-config-airbnb": "^
|
39
|
-
"eslint-plugin-import": "^2.
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"typescript": "^3.7.5",
|
45
|
-
"typescript-eslint": "0.0.1-alpha.0"
|
56
|
+
"eslint": "^8.57.0",
|
57
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
58
|
+
"eslint-plugin-import": "^2.31.0",
|
59
|
+
"express": "^4.21.1",
|
60
|
+
"ts-node": "^10.9.2",
|
61
|
+
"typescript": "^4.9.5",
|
62
|
+
"vitest": "^3.0.5"
|
46
63
|
}
|
47
64
|
}
|
package/readme.md
CHANGED
package/dist/src/config.d.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
interface Overrides {
|
2
|
-
setAndPropagateCorrelationId?: boolean;
|
3
|
-
propagateInResponses?: boolean;
|
4
|
-
headersToPropagate?: string[];
|
5
|
-
headersPrefix?: string;
|
6
|
-
}
|
7
|
-
declare const _default: {
|
8
|
-
load: (overrides?: Overrides) => {
|
9
|
-
setAndPropagateCorrelationId: boolean;
|
10
|
-
propagateInResponses: boolean;
|
11
|
-
correlationIdHeader: string;
|
12
|
-
headersToCollect: string[];
|
13
|
-
headersToInject: string[];
|
14
|
-
headersPrefix: string;
|
15
|
-
};
|
16
|
-
correlationIdHeader: string;
|
17
|
-
};
|
18
|
-
export default _default;
|
package/dist/src/config.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;AAAA,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAQ,EAAE;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,iEAAiE;IACjE,MAAM,eAAe,GAAG,iBAAiB,CAAC;IAE1C,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhG,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,yCAAyC,cAAc,EAAE,CAAC,CAAC;KAC5E;AACH,CAAC,CAAC;AASF,MAAM,IAAI,GAAG,CAAC,YAAuB,EAAE,EAAE,EAAE;IACzC,MAAM,EACJ,4BAA4B,GAAG,IAAI,EACnC,oBAAoB,GAAG,KAAK,EAC5B,kBAAkB,GAAG;QACnB,cAAc;QACd,cAAc;KACf,EACD,aAAa,GAAG,OAAO,GACxB,GAAG,SAAS,CAAC;IAEd,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IAEvC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;IAE5C,IAAI,eAAe,GAAG,gBAAgB,CAAC;IACvC,IAAI,4BAA4B,KAAK,IAAI,EAAE;QACzC,eAAe,GAAG,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;KAClE;IAED,OAAO;QACL,4BAA4B;QAC5B,oBAAoB;QACpB,mBAAmB;QACnB,gBAAgB;QAChB,eAAe;QACf,aAAa;KACd,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe;IACb,IAAI;IACJ,mBAAmB;CACpB,CAAC"}
|
package/dist/src/example.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/src/example.js
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const express_1 = __importDefault(require("express"));
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
17
|
-
const winston_1 = __importDefault(require("winston"));
|
18
|
-
const index_1 = __importDefault(require("./index"));
|
19
|
-
axios_1.default.defaults.adapter = require('axios/lib/adapters/http');
|
20
|
-
const logger = winston_1.default.createLogger({
|
21
|
-
transports: [
|
22
|
-
new winston_1.default.transports.Console(),
|
23
|
-
],
|
24
|
-
});
|
25
|
-
index_1.default({
|
26
|
-
setAndPropagateCorrelationId: true,
|
27
|
-
headersToPropagate: [
|
28
|
-
'x-text',
|
29
|
-
],
|
30
|
-
headersPrefix: 'x-af-',
|
31
|
-
winstonLogger: logger,
|
32
|
-
});
|
33
|
-
const app = express_1.default();
|
34
|
-
app.all('/', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
35
|
-
const network = axios_1.default.create({ baseURL: 'http://localhost:8080/' });
|
36
|
-
const { data } = yield network.get('/header-parrot');
|
37
|
-
res.json(data);
|
38
|
-
}));
|
39
|
-
app.all('/header-parrot', (req, res) => {
|
40
|
-
logger.info('Test message', { t: 1 });
|
41
|
-
res.json(req.headers);
|
42
|
-
});
|
43
|
-
app.listen(8080, () => {
|
44
|
-
logger.info('App listen');
|
45
|
-
});
|
46
|
-
//# sourceMappingURL=example.js.map
|
package/dist/src/example.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,kDAA0B;AAC1B,sDAA8B;AAE9B,oDAAoC;AAEpC,eAAK,CAAC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAE5D,MAAM,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;IAClC,UAAU,EAAE;QACV,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,EAAE;KACjC;CACF,CAAC,CAAC;AAEH,eAAa,CAAC;IACZ,4BAA4B,EAAE,IAAI;IAClC,kBAAkB,EAAE;QAClB,QAAQ;KACT;IACD,aAAa,EAAE,OAAO;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AAEtB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACpE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACrD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAA,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACrC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACtC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export default function wrapHttp(config: any): void;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"http_wrapper.js","sourceRoot":"","sources":["../../src/http_wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4BAA4B;AAC5B,gDAAwB;AACxB,sDAA8B;AAG9B,mDAA4C;AAE5C,MAAM,wBAAwB,GAAG,cAAI,CAAC,YAAY,CAAC;AACnD,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC;AACrC,MAAM,WAAW,GAAG,cAAI,CAAC,GAAG,CAAC;AAE7B,SAAS,0BAA0B,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG;IAClD,IAAI,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC5D,IAAI,OAAO,aAAa,KAAK,WAAW,EAAE;QACxC,aAAa,GAAG,iBAAO,CAAC,QAAQ,EAAE,CAAC;KACpC;IACD,gBAAM,CAAC,YAAY,CAAC,OA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AAO,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,SAAS,YAAY,CAAC,OAAO,EAAE,EAAE;QAC/B,MAAM,CAAC,OAAO,CAAC,CAAC;QAEhB,OAAO,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;IAID,SAAS,kBAAkB,CAAC,GAAG,IAAI;QACjC,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,GAAG,CAAC;QACR,IAAI,QAAQ,CAAC;QAEb,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC;YAChC,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SACzC;QACD,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC;QAC3B,OAAO,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAwB,QAAQ,CAAC,MAAM;IACrC,cAAI,CAAC,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACjD,cAAI,CAAC,OAAO,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,cAAI,CAAC,GAAG,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC;AAJD,2BAIC"}
|
package/dist/src/index.d.ts
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import winston from 'winston';
|
2
|
-
interface Options {
|
3
|
-
winstonLogger?: winston.Logger;
|
4
|
-
loggerTraceKey?: string;
|
5
|
-
headersPrefix?: string;
|
6
|
-
setAndPropagateCorrelationId?: boolean;
|
7
|
-
headersToPropagate?: string[];
|
8
|
-
}
|
9
|
-
export default function (options: Options): void;
|
10
|
-
export declare const getCurrentContext: () => any;
|
11
|
-
export declare const newTrace: (type: any) => void;
|
12
|
-
export declare const traceTypes: {
|
13
|
-
HTTP_REQUEST: string;
|
14
|
-
WEB_SOCKET: string;
|
15
|
-
RABBIT: string;
|
16
|
-
};
|
17
|
-
export {};
|
package/dist/src/index.js
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
6
|
-
if (mod && mod.__esModule) return mod;
|
7
|
-
var result = {};
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9
|
-
result["default"] = mod;
|
10
|
-
return result;
|
11
|
-
};
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
const winston_1 = require("winston");
|
14
|
-
const http_wrapper_1 = __importDefault(require("./http_wrapper"));
|
15
|
-
const config_1 = __importDefault(require("./config"));
|
16
|
-
const tracer = __importStar(require("./tracer"));
|
17
|
-
const addMetadataToLog = (loggerTraceKey) => winston_1.format((info) => {
|
18
|
-
const currentTrace = tracer.getCurrentTrace();
|
19
|
-
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
20
|
-
// eslint-disable-next-line no-param-reassign
|
21
|
-
info[loggerTraceKey] = currentTrace.context.get(config_1.default.correlationIdHeader);
|
22
|
-
}
|
23
|
-
return info;
|
24
|
-
});
|
25
|
-
function default_1(options) {
|
26
|
-
http_wrapper_1.default(config_1.default.load(options));
|
27
|
-
tracer.enable();
|
28
|
-
if (options.winstonLogger) {
|
29
|
-
const traceKey = options.loggerTraceKey || 'traceId';
|
30
|
-
// eslint-disable-next-line no-param-reassign
|
31
|
-
options.winstonLogger.format = winston_1.format.combine(addMetadataToLog(traceKey)(), options.winstonLogger.format);
|
32
|
-
}
|
33
|
-
try {
|
34
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
35
|
-
const bluebird = require('bluebird');
|
36
|
-
bluebird.config({
|
37
|
-
asyncHooks: true,
|
38
|
-
});
|
39
|
-
}
|
40
|
-
catch (e) {
|
41
|
-
// Do nothing
|
42
|
-
}
|
43
|
-
finally {
|
44
|
-
// Do nothing
|
45
|
-
}
|
46
|
-
}
|
47
|
-
exports.default = default_1;
|
48
|
-
exports.getCurrentContext = () => tracer.getCurrentTrace();
|
49
|
-
exports.newTrace = tracer.newTrace;
|
50
|
-
exports.traceTypes = {
|
51
|
-
HTTP_REQUEST: 'httpRequest',
|
52
|
-
WEB_SOCKET: 'webSocket',
|
53
|
-
RABBIT: 'rabbit',
|
54
|
-
};
|
55
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA0C;AAE1C,kEAAyC;AACzC,sDAA8B;AAC9B,iDAAmC;AAUnC,MAAM,gBAAgB,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC,gBAAM,CAAC,CAAC,IAAI,EAAE,EAAE;IAC3D,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC9C,IAAI,YAAY,IAAI,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE;QACpE,6CAA6C;QAC7C,IAAI,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAM,CAAC,mBAAmB,CAAC,CAAC;KAC7E;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,mBAAyB,OAAgB;IACvC,sBAAW,CAAC,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,EAAE,CAAC;IAEhB,IAAI,OAAO,CAAC,aAAa,EAAE;QACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,IAAI,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