@codefresh-io/cf-telemetry 1.0.3 → 2.0.0-alpha.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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logger/config.d.ts +4 -0
- package/dist/logger/config.js +2 -0
- package/dist/logger/config.js.map +1 -1
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +3 -1
- package/dist/logger/index.js.map +1 -1
- package/dist/logger/logger.d.ts +38 -67
- package/dist/logger/logger.js +48 -74
- package/dist/logger/logger.js.map +1 -1
- package/dist/logger/metadata-storage.d.ts +3 -0
- package/dist/logger/metadata-storage.js +6 -0
- package/dist/logger/metadata-storage.js.map +1 -0
- package/dist/logger/run-in-context.d.ts +9 -0
- package/dist/logger/run-in-context.js +21 -0
- package/dist/logger/run-in-context.js.map +1 -0
- package/dist/logger/types.d.ts +56 -10
- package/dist/logger/types.js +2 -0
- package/dist/logger/types.js.map +1 -1
- package/dist/metrics/prometheus/init-prometheus.js +2 -2
- package/dist/metrics/prometheus/init-prometheus.js.map +1 -1
- package/dist/profiles/index.js +1 -1
- package/dist/profiles/index.js.map +1 -1
- package/package.json +9 -12
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare const mongodb: {
|
|
|
10
10
|
};
|
|
11
11
|
export declare const logs: {
|
|
12
12
|
Logger: typeof log.Logger;
|
|
13
|
+
runInContext: <R, TArgs extends unknown[]>({ initiator, target, account_id }: import("./logger/types").LogMetadata, callback: (...args: TArgs) => R, ...args: TArgs) => R;
|
|
13
14
|
};
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgC;AAChC,yDAA2C;AAC3C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S,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;KACpD,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AAChD,CAAC,CAAC;AARW,QAAA,IAAI,QAQf;AAEW,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ;IACvB,OAAO,EAAE,IAAI,CAAC,OAAO;CACtB,CAAC;AAEW,QAAA,OAAO,GAAG;IACrB,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;CACjD,CAAC;AAEW,QAAA,IAAI,GAAG;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM;IAClB,YAAY,EAAE,GAAG,CAAC,YAAY;CAC/B,CAAC"}
|
package/dist/logger/config.d.ts
CHANGED
package/dist/logger/config.js
CHANGED
|
@@ -10,5 +10,7 @@ if (!isKnownLevel)
|
|
|
10
10
|
exports.config = {
|
|
11
11
|
level: isKnownLevel ? detectedLevel : 'info',
|
|
12
12
|
shouldPrettify: process.env['CF_TELEMETRY_LOGS_PRETTIFY'] === 'true',
|
|
13
|
+
sync: process.env['CF_TELEMETRY_LOGS_SYNC'] === 'true',
|
|
14
|
+
defaultInitiator: { type: 'system' },
|
|
13
15
|
};
|
|
14
16
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/logger/config.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/logger/config.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAE7C,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,IAAI,MAAM,CAAC;AACvE,8DAA8D;AAC9D,MAAM,YAAY,GAAG,aAAK,CAAC,QAAQ,CAAC,aAAoB,CAAC,CAAC;AAC1D,IAAI,CAAC,YAAY;IAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,aAAa,yBAAyB,CAAC,CAAC;AAEjF,QAAA,MAAM,GAAG;IACpB,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,aAAsB,CAAC,CAAC,CAAC,MAAM;IACrD,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,KAAK,MAAM;IACpE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,KAAK,MAAM;IACtD,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAqC;CAC/D,CAAC"}
|
package/dist/logger/index.d.ts
CHANGED
package/dist/logger/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
3
|
+
exports.runInContext = exports.Logger = void 0;
|
|
4
4
|
var logger_1 = require("./logger");
|
|
5
5
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
6
|
+
var run_in_context_1 = require("./run-in-context");
|
|
7
|
+
Object.defineProperty(exports, "runInContext", { enumerable: true, get: function () { return run_in_context_1.runInContext; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/logger/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
|
package/dist/logger/logger.d.ts
CHANGED
|
@@ -1,90 +1,61 @@
|
|
|
1
1
|
import type { Logger as ILogger, LoggerOptions, Scope } from './types';
|
|
2
2
|
export declare class Logger implements ILogger {
|
|
3
3
|
#private;
|
|
4
|
+
constructor(options?: Scope | LoggerOptions);
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param options Logger options.
|
|
8
|
-
* @param options.attributes Additional attributes to be added to each log line.
|
|
6
|
+
* `debug` log level.
|
|
7
|
+
* @param err Error object to log.
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
debug(err: Error): void;
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* with support for the following placeholders:
|
|
16
|
-
* `%s` – string placeholder
|
|
17
|
-
* `%d` – digit placeholder
|
|
18
|
-
* `%O`, `%o`, and `%j` – object placeholder.
|
|
19
|
-
* Values supplied as additional arguments to the logger method after message string
|
|
20
|
-
* will then be interpolated accordingly.
|
|
21
|
-
* @param interpolationValues All arguments supplied after `msg` are serialized and interpolated
|
|
22
|
-
* according to any supplied printf-style placeholders (`%s`, `%d`, `%o|%O|%j`)
|
|
23
|
-
* to form the final output msg value for the JSON log line.
|
|
11
|
+
* `debug` log level.
|
|
12
|
+
* @param msg Message string to log.
|
|
13
|
+
* @param data Optional additional data to log.
|
|
24
14
|
*/
|
|
25
|
-
debug(msg: string,
|
|
26
|
-
debug(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
|
|
15
|
+
debug(msg: string, data?: unknown): void;
|
|
27
16
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param msg Message string to log. The message string may contain a printf style string
|
|
31
|
-
* with support for the following placeholders:
|
|
32
|
-
* `%s` – string placeholder
|
|
33
|
-
* `%d` – digit placeholder
|
|
34
|
-
* `%O`, `%o`, and `%j` – object placeholder.
|
|
35
|
-
* Values supplied as additional arguments to the logger method after message string
|
|
36
|
-
* will then be interpolated accordingly.
|
|
37
|
-
* @param interpolationValues All arguments supplied after `msg` are serialized and interpolated
|
|
38
|
-
* according to any supplied printf-style placeholders (`%s`, `%d`, `%o|%O|%j`)
|
|
39
|
-
* to form the final output msg value for the JSON log line.
|
|
17
|
+
* `info` log level.
|
|
18
|
+
* @param err Error object to log.
|
|
40
19
|
*/
|
|
41
|
-
info(
|
|
42
|
-
|
|
20
|
+
info(err: Error): void;
|
|
21
|
+
/**
|
|
22
|
+
* `info` log level.
|
|
23
|
+
* @param msg Message string to log.
|
|
24
|
+
* @param data Optional additional data to log.
|
|
25
|
+
*/
|
|
26
|
+
info(msg: string, data?: unknown): void;
|
|
43
27
|
/**
|
|
44
28
|
* Alias for `info` log level.
|
|
45
29
|
*/
|
|
46
30
|
log: {
|
|
47
|
-
(
|
|
48
|
-
(
|
|
31
|
+
(err: Error): void;
|
|
32
|
+
(msg: string, data?: unknown): void;
|
|
49
33
|
};
|
|
50
34
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
35
|
+
* `warn` log level.
|
|
36
|
+
* @param err Error object to log.
|
|
37
|
+
*/
|
|
38
|
+
warn(err: Error): void;
|
|
39
|
+
/**
|
|
40
|
+
* `warn` log level.
|
|
41
|
+
* @param msg Message string to log.
|
|
42
|
+
* @param data Optional additional data to log.
|
|
43
|
+
*/
|
|
44
|
+
warn(msg: string, data?: unknown): void;
|
|
45
|
+
/**
|
|
46
|
+
* `error` log level.
|
|
47
|
+
* @param err Error object to log.
|
|
63
48
|
*/
|
|
64
|
-
|
|
65
|
-
warn(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
|
|
49
|
+
error(err: Error): void;
|
|
66
50
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* with support for the following placeholders:
|
|
71
|
-
* `%s` – string placeholder
|
|
72
|
-
* `%d` – digit placeholder
|
|
73
|
-
* `%O`, `%o`, and `%j` – object placeholder.
|
|
74
|
-
* Values supplied as additional arguments to the logger method after message string
|
|
75
|
-
* will then be interpolated accordingly.
|
|
76
|
-
* @param interpolationValues All arguments supplied after `msg` are serialized and interpolated
|
|
77
|
-
* according to any supplied printf-style placeholders (`%s`, `%d`, `%o|%O|%j`)
|
|
78
|
-
* to form the final output msg value for the JSON log line.
|
|
51
|
+
* `error` log level.
|
|
52
|
+
* @param msg Message string to log.
|
|
53
|
+
* @param data Optional additional data to log.
|
|
79
54
|
*/
|
|
80
|
-
error(msg: string,
|
|
81
|
-
error(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
|
|
55
|
+
error(msg: string, data?: unknown): void;
|
|
82
56
|
/**
|
|
83
57
|
* Create child logger.
|
|
84
|
-
* @param scope Scope of the child logger. Will be appended to the parent scope (`parent:child`).
|
|
85
|
-
* @param options Options for the child logger.
|
|
86
|
-
* @param options.attributes Additional attributes to be added to each log line. Will override parent attributes if key the same, otherwise will be added.
|
|
87
58
|
* @returns Child logger
|
|
88
59
|
*/
|
|
89
|
-
child(
|
|
60
|
+
child(options?: Scope | LoggerOptions): Logger;
|
|
90
61
|
}
|
package/dist/logger/logger.js
CHANGED
|
@@ -4,31 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Logger = void 0;
|
|
7
|
-
const change_case_all_1 = require("change-case-all");
|
|
8
7
|
const pino_1 = __importDefault(require("pino"));
|
|
9
8
|
const config_1 = require("./config");
|
|
9
|
+
const metadata_storage_1 = require("./metadata-storage");
|
|
10
10
|
class Logger {
|
|
11
11
|
#options;
|
|
12
|
-
#scope;
|
|
13
12
|
#baseLogger;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @param options Logger options.
|
|
18
|
-
* @param options.attributes Additional attributes to be added to each log line.
|
|
19
|
-
*/
|
|
20
|
-
constructor(scope, options = {}) {
|
|
21
|
-
this.#options = {
|
|
22
|
-
...options,
|
|
23
|
-
attributes: this.#prepareAttributes(options.attributes ?? {}),
|
|
24
|
-
};
|
|
25
|
-
this.#scope = scope;
|
|
13
|
+
#defaultInitiator = config_1.config.defaultInitiator;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.#options = typeof options === 'string' ? { scope: options } : options;
|
|
26
16
|
this.#baseLogger = (0, pino_1.default)({
|
|
27
17
|
level: config_1.config.level,
|
|
28
|
-
base:
|
|
29
|
-
scope_name: this.#scope,
|
|
30
|
-
...this.#options.attributes,
|
|
31
|
-
},
|
|
18
|
+
base: null,
|
|
32
19
|
formatters: {
|
|
33
20
|
level: label => ({ level: label }),
|
|
34
21
|
},
|
|
@@ -41,82 +28,69 @@ class Logger {
|
|
|
41
28
|
},
|
|
42
29
|
},
|
|
43
30
|
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
#prepareAttributes(attributes) {
|
|
47
|
-
return Object.entries(attributes)
|
|
48
|
-
.reduce((acc, [key, value]) => {
|
|
49
|
-
const snakeKey = change_case_all_1.Case.snake(key);
|
|
50
|
-
const prefixedKey = key.startsWith('cf_') ? snakeKey : `cf_${snakeKey}`;
|
|
51
|
-
acc[prefixedKey] = value;
|
|
52
|
-
return acc;
|
|
53
|
-
}, {});
|
|
54
|
-
}
|
|
55
|
-
#mergeAttributes(target, source) {
|
|
56
|
-
return { ...target, ...source };
|
|
31
|
+
}, pino_1.default.destination({ sync: config_1.config.sync }));
|
|
57
32
|
}
|
|
58
33
|
#getChildScope(childScope) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
34
|
+
return this.#options.scope
|
|
35
|
+
? `${this.#options.scope}${childScope ? `:${childScope}` : ''}`
|
|
36
|
+
: childScope;
|
|
37
|
+
}
|
|
38
|
+
#getChildOptions(parentOptions, childOptions) {
|
|
39
|
+
if (typeof childOptions === 'string')
|
|
40
|
+
childOptions = { scope: childOptions };
|
|
41
|
+
return {
|
|
42
|
+
...parentOptions,
|
|
43
|
+
...childOptions,
|
|
44
|
+
scope: this.#getChildScope(childOptions.scope),
|
|
45
|
+
};
|
|
62
46
|
}
|
|
63
47
|
#write(level, ...args) {
|
|
64
|
-
const body = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
const body = {
|
|
49
|
+
msg: undefined,
|
|
50
|
+
data: undefined,
|
|
51
|
+
err: undefined,
|
|
52
|
+
cf: metadata_storage_1.metadataStorage.getStore() ?? {},
|
|
53
|
+
scope_name: this.#options.useLastArgAsScope === true
|
|
54
|
+
&& !this.#options.scope
|
|
55
|
+
&& args.length > 1
|
|
56
|
+
&& typeof args.at(-1) === 'string'
|
|
57
|
+
? args.pop()
|
|
58
|
+
: this.#options.scope,
|
|
59
|
+
};
|
|
60
|
+
body.cf.initiator ??= this.#defaultInitiator;
|
|
61
|
+
const [msgOrErr, data] = args;
|
|
62
|
+
if (msgOrErr instanceof Error) {
|
|
63
|
+
body.err = msgOrErr;
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (msg instanceof Error) {
|
|
74
|
-
body['err'] = msg;
|
|
75
|
-
}
|
|
76
|
-
else if (msg === null) {
|
|
77
|
-
body['msg'] = msg;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
body['data'] = msg;
|
|
81
|
-
}
|
|
65
|
+
else {
|
|
66
|
+
body.msg = msgOrErr;
|
|
82
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
-
|
|
68
|
+
body[data && data instanceof Error ? 'err' : 'data'] = data;
|
|
84
69
|
}
|
|
85
|
-
return
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
-
? this.#baseLogger[level](body, msg, ...interpolationValues)
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
-
: this.#baseLogger[level](msg, ...interpolationValues);
|
|
70
|
+
return this.#baseLogger[level](body);
|
|
90
71
|
}
|
|
91
|
-
debug(
|
|
92
|
-
this.#write('debug',
|
|
72
|
+
debug(...args) {
|
|
73
|
+
this.#write('debug', ...args);
|
|
93
74
|
}
|
|
94
|
-
info(
|
|
95
|
-
this.#write('info',
|
|
75
|
+
info(...args) {
|
|
76
|
+
this.#write('info', ...args);
|
|
96
77
|
}
|
|
97
78
|
/**
|
|
98
79
|
* Alias for `info` log level.
|
|
99
80
|
*/
|
|
100
81
|
log = this.info;
|
|
101
|
-
warn(
|
|
102
|
-
this.#write('warn',
|
|
82
|
+
warn(...args) {
|
|
83
|
+
this.#write('warn', ...args);
|
|
103
84
|
}
|
|
104
|
-
error(
|
|
105
|
-
this.#write('error',
|
|
85
|
+
error(...args) {
|
|
86
|
+
this.#write('error', ...args);
|
|
106
87
|
}
|
|
107
88
|
/**
|
|
108
89
|
* Create child logger.
|
|
109
|
-
* @param scope Scope of the child logger. Will be appended to the parent scope (`parent:child`).
|
|
110
|
-
* @param options Options for the child logger.
|
|
111
|
-
* @param options.attributes Additional attributes to be added to each log line. Will override parent attributes if key the same, otherwise will be added.
|
|
112
90
|
* @returns Child logger
|
|
113
91
|
*/
|
|
114
|
-
child(
|
|
115
|
-
|
|
116
|
-
const childScope = this.#getChildScope(scope);
|
|
117
|
-
return new Logger(childScope, {
|
|
118
|
-
attributes: this.#mergeAttributes(this.#options.attributes, this.#prepareAttributes(childAttributes)),
|
|
119
|
-
});
|
|
92
|
+
child(options = {}) {
|
|
93
|
+
return new Logger(this.#getChildOptions(this.#options, options));
|
|
120
94
|
}
|
|
121
95
|
}
|
|
122
96
|
exports.Logger = Logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,qCAAkC;AAClC,yDAAqD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AM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;IAahB,IAAI,CAAC,GAAG,IAAa;QACnB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/B,CAAC;IAaD,KAAK,CAAC,GAAG,IAAa;QACpB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAiC,EAAE;QACvC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AA/ID,wBA+IC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.metadataStorage = void 0;
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
+
exports.metadataStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
//# sourceMappingURL=metadata-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-storage.js","sourceRoot":"","sources":["../../src/logger/metadata-storage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAGxC,QAAA,eAAe,GAAG,IAAI,oCAAiB,EAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LogMetadata } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Provided metadata will be attached to each log line within the callback.
|
|
4
|
+
* `runInContext` will return the result of the callback.
|
|
5
|
+
* If the callback throws an error, it will be thrown by `runInContext` too.
|
|
6
|
+
*
|
|
7
|
+
* Nested calls of `runInContext` will merge metadata except for `initiator` key which can be provided only once.
|
|
8
|
+
*/
|
|
9
|
+
export declare const runInContext: <R, TArgs extends unknown[]>({ initiator, target, account_id }: LogMetadata, callback: (...args: TArgs) => R, ...args: TArgs) => R;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInContext = void 0;
|
|
4
|
+
const metadata_storage_1 = require("./metadata-storage");
|
|
5
|
+
/**
|
|
6
|
+
* Provided metadata will be attached to each log line within the callback.
|
|
7
|
+
* `runInContext` will return the result of the callback.
|
|
8
|
+
* If the callback throws an error, it will be thrown by `runInContext` too.
|
|
9
|
+
*
|
|
10
|
+
* Nested calls of `runInContext` will merge metadata except for `initiator` key which can be provided only once.
|
|
11
|
+
*/
|
|
12
|
+
const runInContext = ({ initiator, target, account_id }, callback, ...args) => {
|
|
13
|
+
return metadata_storage_1.metadataStorage.run({
|
|
14
|
+
...initiator && { initiator },
|
|
15
|
+
...metadata_storage_1.metadataStorage.getStore(),
|
|
16
|
+
...target && { target },
|
|
17
|
+
...account_id && { account_id },
|
|
18
|
+
}, callback, ...args);
|
|
19
|
+
};
|
|
20
|
+
exports.runInContext = runInContext;
|
|
21
|
+
//# sourceMappingURL=run-in-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-in-context.js","sourceRoot":"","sources":["../../src/logger/run-in-context.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAGrD;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAe,EAC9C,QAA+B,EAC/B,GAAG,IAAW,EACX,EAAE;IACL,OAAO,kCAAe,CAAC,GAAG,CACxB;QACE,GAAG,SAAS,IAAI,EAAE,SAAS,EAAE;QAC7B,GAAG,kCAAe,CAAC,QAAQ,EAAE;QAC7B,GAAG,MAAM,IAAI,EAAE,MAAM,EAAE;QACvB,GAAG,UAAU,IAAI,EAAE,UAAU,EAAE;KAChC,EACD,QAAQ,EACR,GAAG,IAAI,CACR,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB"}
|
package/dist/logger/types.d.ts
CHANGED
|
@@ -1,30 +1,76 @@
|
|
|
1
|
+
import type { LoggerService } from '@nestjs/common';
|
|
1
2
|
export declare const Level: readonly ["debug", "info", "warn", "error"];
|
|
2
3
|
export type Level = (typeof Level[number]);
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Scope name to be used for all log lines.
|
|
6
|
+
*/
|
|
4
7
|
export type Scope = string;
|
|
5
8
|
export interface LoggerOptions {
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @default {}
|
|
10
|
+
* Scope name to be used for all log lines.
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
scope?: Scope;
|
|
11
13
|
/**
|
|
12
|
-
* If scope was not set during logger creation,
|
|
14
|
+
* If scope was not set during logger creation,
|
|
15
|
+
* and more than 1 arg is passed to the logger func,
|
|
16
|
+
* the last argument will be used as scope value.
|
|
13
17
|
* _Recommended to use only in NestJS for app logger (`app.useLogger()`)_.
|
|
14
18
|
* @default false
|
|
15
19
|
*/
|
|
16
20
|
useLastArgAsScope?: boolean;
|
|
17
21
|
}
|
|
22
|
+
export type LogMessage = string;
|
|
23
|
+
export type LogData = unknown;
|
|
24
|
+
export type LogArgs = [LogMessage, LogData?, Scope?] | [Error, Scope?];
|
|
18
25
|
export interface LogFn {
|
|
19
|
-
(
|
|
20
|
-
(msg:
|
|
26
|
+
(err: Error, scope?: Scope): void;
|
|
27
|
+
(msg: LogMessage, data?: LogData, scope?: Scope): void;
|
|
21
28
|
}
|
|
22
|
-
export declare class Logger {
|
|
23
|
-
constructor(
|
|
29
|
+
export declare class Logger implements LoggerService {
|
|
30
|
+
constructor(options?: Scope | LoggerOptions);
|
|
24
31
|
debug: LogFn;
|
|
25
32
|
info: LogFn;
|
|
26
33
|
warn: LogFn;
|
|
27
34
|
error: LogFn;
|
|
28
35
|
log: LogFn;
|
|
29
|
-
child: (
|
|
36
|
+
child: (options?: Scope | LoggerOptions) => Logger;
|
|
37
|
+
}
|
|
38
|
+
export interface LogMetadata {
|
|
39
|
+
/**
|
|
40
|
+
* Initiator of the action. E.g. user, system, etc.
|
|
41
|
+
*/
|
|
42
|
+
initiator?: {
|
|
43
|
+
/**
|
|
44
|
+
* Type of the initiator. E.g. user, system, etc.
|
|
45
|
+
*/
|
|
46
|
+
type: string;
|
|
47
|
+
/**
|
|
48
|
+
* ID of the initiator.
|
|
49
|
+
*/
|
|
50
|
+
id?: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Codefresh business entity affected by the action. E.g. v1_build, v2_runtime, etc.
|
|
54
|
+
*/
|
|
55
|
+
target?: {
|
|
56
|
+
/**
|
|
57
|
+
* Type of the target. E.g. v1_build, v2_runtime, etc.
|
|
58
|
+
*/
|
|
59
|
+
type: string;
|
|
60
|
+
/**
|
|
61
|
+
* ID of the target.
|
|
62
|
+
*/
|
|
63
|
+
id?: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Codefresh Account ID affected by the action.
|
|
67
|
+
*/
|
|
68
|
+
account_id?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface LogBody {
|
|
71
|
+
msg?: LogMessage;
|
|
72
|
+
data?: LogData;
|
|
73
|
+
err?: Error;
|
|
74
|
+
cf: LogMetadata;
|
|
75
|
+
scope_name?: Scope;
|
|
30
76
|
}
|
package/dist/logger/types.js
CHANGED
package/dist/logger/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/logger/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/logger/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,KAAK,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAqBhE,CAAC;AAQD,CAAC;AAWD,CAAC;AAiCD,CAAC"}
|
|
@@ -15,7 +15,7 @@ const initPrometheus = async (logger) => {
|
|
|
15
15
|
}
|
|
16
16
|
;
|
|
17
17
|
try {
|
|
18
|
-
logger.info({ config: config_1.config }
|
|
18
|
+
logger.info('Initializing Prometheus', { config: config_1.config });
|
|
19
19
|
if (config_1.config.shouldCollectProcessMetrics)
|
|
20
20
|
client_1.client.collectDefaultMetrics();
|
|
21
21
|
const metricsServer = (0, fastify_1.default)();
|
|
@@ -31,7 +31,7 @@ const initPrometheus = async (logger) => {
|
|
|
31
31
|
logger.info('Prometheus initialized');
|
|
32
32
|
}
|
|
33
33
|
catch (exception) {
|
|
34
|
-
logger.error(
|
|
34
|
+
logger.error('Failed to initialize Prometheus', exception);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
exports.initPrometheus = initPrometheus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-prometheus.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/init-prometheus.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAE9B,qCAA4C;AAC5C,qCAAkC;AAE3B,MAAM,cAAc,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;IACpE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACpC,IAAI,eAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAC;QACnG,OAAO;IACT,CAAC;IAAA,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAN,eAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"init-prometheus.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/init-prometheus.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAE9B,qCAA4C;AAC5C,qCAAkC;AAE3B,MAAM,cAAc,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;IACpE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACpC,IAAI,eAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAC;QACnG,OAAO;IACT,CAAC;IAAA,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,EAAE,MAAM,EAAN,eAAM,EAAE,CAAC,CAAC;QACnD,IAAI,eAAM,CAAC,2BAA2B;YAAE,eAAM,CAAC,qBAAqB,EAAE,CAAC;QACvE,MAAM,aAAa,GAAG,IAAA,iBAAO,GAAE,CAAC;QAChC,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;YACtD,KAAK,CAAC,IAAI,CAAC,iBAAQ,CAAC,WAAW,CAAC,CAAC;YACjC,OAAO,iBAAQ,CAAC,OAAO,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC;YACzC,IAAI,EAAE,eAAM,CAAC,IAAI;YACjB,IAAI,EAAE,eAAM,CAAC,IAAI;SAClB,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,kCAAkC,OAAO,EAAE,CAAC,CAAC;QACzD,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAxBW,QAAA,cAAc,kBAwBzB"}
|
package/dist/profiles/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const initPyroscope = async (logger) => {
|
|
|
12
12
|
logger.info('Pyroscope is disabled. Set CF_TELEMETRY_PYROSCOPE_ENABLE=true to enable it');
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
logger.info({ config: config_1.config.config }
|
|
15
|
+
logger.info('Initializing Pyroscope', { config: config_1.config.config });
|
|
16
16
|
nodejs_1.default.init(config_1.config.config);
|
|
17
17
|
nodejs_1.default.start();
|
|
18
18
|
logger.info('Pyroscope initialized');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/profiles/index.ts"],"names":[],"mappings":";;;;;;AAAA,+DAA0C;AAE1C,qCAAkC;AAE3B,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;IACnE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACnC,IAAI,CAAC,eAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;QAC1F,OAAO;IACT,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,eAAM,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/profiles/index.ts"],"names":[],"mappings":";;;;;;AAAA,+DAA0C;AAE1C,qCAAkC;AAE3B,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;IACnE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACnC,IAAI,CAAC,eAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;QAC1F,OAAO;IACT,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,MAAM,EAAE,eAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACjE,gBAAS,CAAC,IAAI,CAAC,eAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,gBAAS,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AACvC,CAAC,CAAC;AAXW,QAAA,aAAa,iBAWxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codefresh-io/cf-telemetry",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*"
|
|
@@ -22,26 +22,23 @@
|
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@eslint/js": "^9.
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
25
|
+
"@eslint/js": "^9.19.0",
|
|
26
|
+
"@nestjs/common": "^11.0.7",
|
|
27
|
+
"@stylistic/eslint-plugin": "^3.0.1",
|
|
28
|
+
"@types/node": "^22.12.0",
|
|
29
|
+
"eslint": "^9.19.0",
|
|
30
|
+
"mongodb": "^6.13.0",
|
|
30
31
|
"pino-pretty": "^13.0.0",
|
|
31
32
|
"rimraf": "^6.0.1",
|
|
32
33
|
"typescript": "^5.7.3",
|
|
33
|
-
"typescript-eslint": "^8.
|
|
34
|
-
"vitest": "^
|
|
34
|
+
"typescript-eslint": "^8.22.0",
|
|
35
|
+
"vitest": "^3.0.4"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@christiangalsterer/mongodb-driver-prometheus-exporter": "^2.3.0",
|
|
38
39
|
"@pyroscope/nodejs": "^0.4.3",
|
|
39
|
-
"change-case-all": "^2.1.0",
|
|
40
40
|
"fastify": "^5.2.1",
|
|
41
41
|
"pino": "^9.6.0",
|
|
42
42
|
"prom-client": "^15.1.3"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"mongodb": "^6.9.0"
|
|
46
43
|
}
|
|
47
44
|
}
|