@codefresh-io/cf-telemetry 1.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.
Files changed (44) hide show
  1. package/README.md +23 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.js +59 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/logger/config.d.ts +4 -0
  6. package/dist/logger/config.js +14 -0
  7. package/dist/logger/config.js.map +1 -0
  8. package/dist/logger/index.d.ts +1 -0
  9. package/dist/logger/index.js +6 -0
  10. package/dist/logger/index.js.map +1 -0
  11. package/dist/logger/logger.d.ts +90 -0
  12. package/dist/logger/logger.js +123 -0
  13. package/dist/logger/logger.js.map +1 -0
  14. package/dist/logger/types.d.ts +30 -0
  15. package/dist/logger/types.js +7 -0
  16. package/dist/logger/types.js.map +1 -0
  17. package/dist/metrics/mongodb/index.d.ts +1 -0
  18. package/dist/metrics/mongodb/index.js +6 -0
  19. package/dist/metrics/mongodb/index.js.map +1 -0
  20. package/dist/metrics/mongodb/monitor-mongodb-client.d.ts +13 -0
  21. package/dist/metrics/mongodb/monitor-mongodb-client.js +51 -0
  22. package/dist/metrics/mongodb/monitor-mongodb-client.js.map +1 -0
  23. package/dist/metrics/prometheus/client.d.ts +3 -0
  24. package/dist/metrics/prometheus/client.js +18 -0
  25. package/dist/metrics/prometheus/client.js.map +1 -0
  26. package/dist/metrics/prometheus/config.d.ts +7 -0
  27. package/dist/metrics/prometheus/config.js +11 -0
  28. package/dist/metrics/prometheus/config.js.map +1 -0
  29. package/dist/metrics/prometheus/index.d.ts +3 -0
  30. package/dist/metrics/prometheus/index.js +43 -0
  31. package/dist/metrics/prometheus/index.js.map +1 -0
  32. package/dist/metrics/prometheus/init-prometheus.d.ts +2 -0
  33. package/dist/metrics/prometheus/init-prometheus.js +38 -0
  34. package/dist/metrics/prometheus/init-prometheus.js.map +1 -0
  35. package/dist/metrics/prometheus/metrics.d.ts +22 -0
  36. package/dist/metrics/prometheus/metrics.js +29 -0
  37. package/dist/metrics/prometheus/metrics.js.map +1 -0
  38. package/dist/profiles/config.d.ts +6 -0
  39. package/dist/profiles/config.js +18 -0
  40. package/dist/profiles/config.js.map +1 -0
  41. package/dist/profiles/index.d.ts +2 -0
  42. package/dist/profiles/index.js +21 -0
  43. package/dist/profiles/index.js.map +1 -0
  44. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # cf-monitoring
2
+
3
+ Base utils for monitoring.
4
+
5
+ Includes:
6
+
7
+ * [Logger](./src/logger/README.md).
8
+ * [Prometheus](./src/metrics/prometheus/README.md) server and custom metrics.
9
+ * [MongoDB](./src//metrics/mongodb/README.md) client monitoring.
10
+ * [Pyroscope](./src/profiles/README.md) to profile CPU and memory.
11
+
12
+ ## Usage
13
+
14
+ Call `init()` function at the very bootstrap of the app.
15
+
16
+ Please refer to the separate docs above for further configuration and usage details.
17
+
18
+ ```TS
19
+ // index.ts
20
+ import { init } from '@codefresh-io/cf-monitoring';
21
+
22
+ await init();
23
+ ```
@@ -0,0 +1,13 @@
1
+ import * as log from './logger';
2
+ import * as prom from './metrics/prometheus';
3
+ export declare const init: () => Promise<void>;
4
+ export declare const prometheus: {
5
+ register: prom.client.Registry<"text/plain; version=0.0.4; charset=utf-8">;
6
+ metrics: typeof prom.metrics;
7
+ };
8
+ export declare const mongodb: {
9
+ monitorMongoDBClient: (client: import("mongodb").MongoClient, connectionPool?: string) => void;
10
+ };
11
+ export declare const logs: {
12
+ Logger: typeof log.Logger;
13
+ };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.logs = exports.mongodb = exports.prometheus = exports.init = void 0;
37
+ const log = __importStar(require("./logger"));
38
+ const mongo = __importStar(require("./metrics/mongodb"));
39
+ const prom = __importStar(require("./metrics/prometheus"));
40
+ const pyroscope = __importStar(require("./profiles"));
41
+ const init = async () => {
42
+ const logger = new log.Logger('monitoring');
43
+ logger.info('Initializing monitoring');
44
+ prom.initPrometheus(logger).catch(logger.error);
45
+ pyroscope.initPyroscope(logger).catch(logger.error);
46
+ logger.info('Monitoring initialized');
47
+ };
48
+ exports.init = init;
49
+ exports.prometheus = {
50
+ register: prom.register,
51
+ metrics: prom.metrics,
52
+ };
53
+ exports.mongodb = {
54
+ monitorMongoDBClient: mongo.monitorMongoDBClient,
55
+ };
56
+ exports.logs = {
57
+ Logger: log.Logger,
58
+ };
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAgC;AAChC,yDAA2C;AAC3C,2DAA6C;AAC7C,sDAAwC;AAEjC,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;IAC5C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACvC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC;AANW,QAAA,IAAI,QAMf;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;CACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const config: {
2
+ readonly level: "debug" | "info" | "warn" | "error";
3
+ readonly shouldPrettify: boolean;
4
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = void 0;
4
+ const types_1 = require("./types");
5
+ const detectedLevel = process.env['CF_TELEMETRY_LOGS_LEVEL'] ?? 'info';
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ const isKnownLevel = types_1.Level.includes(detectedLevel);
8
+ if (!isKnownLevel)
9
+ console.warn(`Unknown log level: ${detectedLevel}. Defaulting to 'info'.`);
10
+ exports.config = {
11
+ level: isKnownLevel ? detectedLevel : 'info',
12
+ shouldPrettify: process.env['CF_TELEMETRY_LOGS_PRETTIFY'] === 'true',
13
+ };
14
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/logger/config.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,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;CAC5D,CAAC"}
@@ -0,0 +1 @@
1
+ export { Logger } from './logger';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ var logger_1 = require("./logger");
5
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
@@ -0,0 +1,90 @@
1
+ import type { Logger as ILogger, LoggerOptions, Scope } from './types';
2
+ export declare class Logger implements ILogger {
3
+ #private;
4
+ /**
5
+ * Logger constructor.
6
+ * @param scope Scope of the logger. Will be prepended to all log messages.
7
+ * @param options Logger options.
8
+ * @param options.attributes Additional attributes to be added to each log line.
9
+ */
10
+ constructor(scope?: Scope, options?: LoggerOptions);
11
+ /**
12
+ * Debug log level.
13
+ * @param data Additional data to log. Might be omitted.
14
+ * @param msg Message string to log. The message string may contain a printf style string
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.
24
+ */
25
+ debug(msg: string, ...interpolationValues: unknown[]): void;
26
+ debug(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
27
+ /**
28
+ * Info log level.
29
+ * @param data Additional data to log. Might be omitted.
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.
40
+ */
41
+ info(msg: string, ...interpolationValues: unknown[]): void;
42
+ info(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
43
+ /**
44
+ * Alias for `info` log level.
45
+ */
46
+ log: {
47
+ (msg: string, ...interpolationValues: unknown[]): void;
48
+ (data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
49
+ };
50
+ /**
51
+ * Warn log level.
52
+ * @param data Additional data to log. Might be omitted.
53
+ * @param msg Message string to log. The message string may contain a printf style string
54
+ * with support for the following placeholders:
55
+ * `%s` – string placeholder
56
+ * `%d` – digit placeholder
57
+ * `%O`, `%o`, and `%j` – object placeholder.
58
+ * Values supplied as additional arguments to the logger method after message string
59
+ * will then be interpolated accordingly.
60
+ * @param interpolationValues All arguments supplied after `msg` are serialized and interpolated
61
+ * according to any supplied printf-style placeholders (`%s`, `%d`, `%o|%O|%j`)
62
+ * to form the final output msg value for the JSON log line.
63
+ */
64
+ warn(msg: string, ...interpolationValues: unknown[]): void;
65
+ warn(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
66
+ /**
67
+ * Error log level.
68
+ * @param data Additional data to log. Might be omitted.
69
+ * @param msg Message string to log. The message string may contain a printf style string
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.
79
+ */
80
+ error(msg: string, ...interpolationValues: unknown[]): void;
81
+ error(data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
82
+ /**
83
+ * 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
+ * @returns Child logger
88
+ */
89
+ child(scope?: Scope, options?: LoggerOptions): Logger;
90
+ }
@@ -0,0 +1,123 @@
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.Logger = void 0;
7
+ const change_case_all_1 = require("change-case-all");
8
+ const pino_1 = __importDefault(require("pino"));
9
+ const config_1 = require("./config");
10
+ class Logger {
11
+ #options;
12
+ #scope;
13
+ #baseLogger;
14
+ /**
15
+ * Logger constructor.
16
+ * @param scope Scope of the logger. Will be prepended to all log messages.
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;
26
+ this.#baseLogger = (0, pino_1.default)({
27
+ level: config_1.config.level,
28
+ base: {
29
+ scope_name: this.#scope,
30
+ ...this.#options.attributes,
31
+ },
32
+ formatters: {
33
+ level: label => ({ level: label }),
34
+ },
35
+ ...config_1.config.shouldPrettify && {
36
+ transport: {
37
+ target: 'pino-pretty',
38
+ options: {
39
+ colorize: true,
40
+ translateTime: 'UTC:yyyy-mm-dd HH:MM:ss.l o',
41
+ },
42
+ },
43
+ },
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 };
57
+ }
58
+ #getChildScope(childScope) {
59
+ if (!this.#scope)
60
+ return childScope;
61
+ return `${this.#scope}${childScope ? `:${childScope}` : ''}`;
62
+ }
63
+ #write(level, ...args) {
64
+ const body = {};
65
+ if (this.#options.useLastArgAsScope === true
66
+ && !this.#scope
67
+ && args.length > 1
68
+ && typeof args.at(-1) === 'string') {
69
+ body['scope_name'] = this.#getChildScope(args.pop());
70
+ }
71
+ const [msg, ...interpolationValues] = args;
72
+ if (typeof msg === 'object') {
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
+ }
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
+ return this.#baseLogger[level](body, ...interpolationValues);
84
+ }
85
+ return 'scope_name' in body
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);
90
+ }
91
+ debug(data, msg, ...interpolationValues) {
92
+ this.#write('debug', data, msg, ...interpolationValues);
93
+ }
94
+ info(data, msg, ...interpolationValues) {
95
+ this.#write('info', data, msg, ...interpolationValues);
96
+ }
97
+ /**
98
+ * Alias for `info` log level.
99
+ */
100
+ log = this.info;
101
+ warn(data, msg, ...interpolationValues) {
102
+ this.#write('warn', data, msg, ...interpolationValues);
103
+ }
104
+ error(data, msg, ...interpolationValues) {
105
+ this.#write('error', data, msg, ...interpolationValues);
106
+ }
107
+ /**
108
+ * 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
+ * @returns Child logger
113
+ */
114
+ child(scope, options = {}) {
115
+ const { attributes: childAttributes = {} } = options;
116
+ const childScope = this.#getChildScope(scope);
117
+ return new Logger(childScope, {
118
+ attributes: this.#mergeAttributes(this.#options.attributes, this.#prepareAttributes(childAttributes)),
119
+ });
120
+ }
121
+ }
122
+ exports.Logger = Logger;
123
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAuC;AACvC,gDAAwB;AACxB,qCAAkC;AAGlC,MAAa,MAAM;IACjB,QAAQ,CAA6C;IACrD,MAAM,CAAoB;IAC1B,WAAW,CAAc;IAEzB;;;;;OAKG;IACH,YAAY,KAAa,EAAE,UAAyB,EAAE;QACpD,IAAI,CAAC,QAAQ,GAAG;YACd,GAAG,OAAO;YACV,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;SAC9D,CAAC;QACF,IAAI,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];
2
+ export type Level = (typeof Level[number]);
3
+ export type Attributes = Record<string, string>;
4
+ export type Scope = string;
5
+ export interface LoggerOptions {
6
+ /**
7
+ * Additional attributes to be added to each log line.
8
+ * @default {}
9
+ */
10
+ attributes?: Attributes;
11
+ /**
12
+ * If scope was not set during logger creation, last argument will be used as scope value.
13
+ * _Recommended to use only in NestJS for app logger (`app.useLogger()`)_.
14
+ * @default false
15
+ */
16
+ useLastArgAsScope?: boolean;
17
+ }
18
+ export interface LogFn {
19
+ (data: unknown, msg?: string, ...interpolationValues: unknown[]): void;
20
+ (msg: string, ...interpolationValues: unknown[]): void;
21
+ }
22
+ export declare class Logger {
23
+ constructor(scope?: Scope, options?: LoggerOptions);
24
+ debug: LogFn;
25
+ info: LogFn;
26
+ warn: LogFn;
27
+ error: LogFn;
28
+ log: LogFn;
29
+ child: (scope: Scope, options?: LoggerOptions) => Logger;
30
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Level = void 0;
4
+ exports.Level = ['debug', 'info', 'warn', 'error'];
5
+ ;
6
+ ;
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/logger/types.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAsBhE,CAAC;AAYD,CAAC"}
@@ -0,0 +1 @@
1
+ export { monitorMongoDBClient } from './monitor-mongodb-client';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.monitorMongoDBClient = void 0;
4
+ var monitor_mongodb_client_1 = require("./monitor-mongodb-client");
5
+ Object.defineProperty(exports, "monitorMongoDBClient", { enumerable: true, get: function () { return monitor_mongodb_client_1.monitorMongoDBClient; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metrics/mongodb/index.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,13 @@
1
+ import type { MongoClient } from 'mongodb';
2
+ /**
3
+ * Enable monitoring of a MongoDB client. Call this function _before_ the client is connected,
4
+ * to ensure that initialization events are not missed.
5
+ *
6
+ * Set `monitorCommands: true` in the client options to monitor command execution.
7
+ *
8
+ * Multiple calls with the same client will be ignored.
9
+ *
10
+ * @param client MongoDB client to monitor
11
+ * @param [connectionPool] Unique per application connection pool name, default is `"main"`. Required if you have multiple clients to monitor.
12
+ */
13
+ export declare const monitorMongoDBClient: (client: MongoClient, connectionPool?: string) => void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.monitorMongoDBClient = void 0;
4
+ const mongodb_driver_prometheus_exporter_1 = require("@christiangalsterer/mongodb-driver-prometheus-exporter");
5
+ const logger_1 = require("../../logger");
6
+ const prometheus_1 = require("../prometheus");
7
+ const WarningCauses = {
8
+ AlreadyMonitored: 'client_already_monitored',
9
+ MultipleClientsForPool: 'multiple_clients_for_pool',
10
+ };
11
+ const instrumentationWarnings = new prometheus_1.metrics.Counter({
12
+ name: 'codefresh_mongodb_instrumentation_warnings_total',
13
+ help: 'Total number of warnings emitted by MongoDB instrumentation',
14
+ labelNames: ['cause', 'connection_pool'],
15
+ });
16
+ const monitoredClients = new WeakSet();
17
+ const monitoredClientsByPool = new Map();
18
+ /**
19
+ * Enable monitoring of a MongoDB client. Call this function _before_ the client is connected,
20
+ * to ensure that initialization events are not missed.
21
+ *
22
+ * Set `monitorCommands: true` in the client options to monitor command execution.
23
+ *
24
+ * Multiple calls with the same client will be ignored.
25
+ *
26
+ * @param client MongoDB client to monitor
27
+ * @param [connectionPool] Unique per application connection pool name, default is `"main"`. Required if you have multiple clients to monitor.
28
+ */
29
+ const monitorMongoDBClient = (client, connectionPool = 'main') => {
30
+ const logger = new logger_1.Logger('monitoring:mongodb');
31
+ logger.info(`Initializing MongoDB monitoring for connection pool: ${connectionPool}`);
32
+ if (monitoredClients.has(client)) {
33
+ instrumentationWarnings.inc({ cause: WarningCauses.AlreadyMonitored, connection_pool: connectionPool });
34
+ logger.warn(`Client is already being monitored, skipping. Connection pool: ${connectionPool}`);
35
+ return;
36
+ }
37
+ const isOtherClientMonitoredForPool = !!monitoredClientsByPool.get(connectionPool)?.deref();
38
+ if (isOtherClientMonitoredForPool) {
39
+ instrumentationWarnings.inc({ cause: WarningCauses.MultipleClientsForPool, connection_pool: connectionPool });
40
+ logger.warn(`Metrics may be incorrect: it is possible that multiple clients are emitting metrics with the same label "connection_pool=${connectionPool}"`);
41
+ }
42
+ monitoredClientsByPool.set(connectionPool, new WeakRef(client));
43
+ monitoredClients.add(client);
44
+ (0, mongodb_driver_prometheus_exporter_1.monitorMongoDBDriver)(client, prometheus_1.register, {
45
+ defaultLabels: { connection_pool: connectionPool },
46
+ logger,
47
+ });
48
+ logger.info(`MongoDB monitoring initialized for connection pool: ${connectionPool}`);
49
+ };
50
+ exports.monitorMongoDBClient = monitorMongoDBClient;
51
+ //# sourceMappingURL=monitor-mongodb-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor-mongodb-client.js","sourceRoot":"","sources":["../../../src/metrics/mongodb/monitor-mongodb-client.ts"],"names":[],"mappings":";;;AAAA,+GAA8F;AAE9F,yCAAsC;AACtC,8CAAkD;AAElD,MAAM,aAAa,GAAG;IACpB,gBAAgB,EAAE,0BAA0B;IAC5C,sBAAsB,EAAE,2BAA2B;CAC3C,CAAC;AAEX,MAAM,uBAAuB,GAAG,IAAI,oBAAO,CAAC,OAAO,CAAC;IAClD,IAAI,EAAE,kDAAkD;IACxD,IAAI,EAAE,6DAA6D;IACnE,UAAU,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACzC,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAA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zBW,QAAA,oBAAoB,wBAyB/B"}
@@ -0,0 +1,3 @@
1
+ import client from 'prom-client';
2
+ declare const register: client.Registry<"text/plain; version=0.0.4; charset=utf-8">;
3
+ export { client, register, };
@@ -0,0 +1,18 @@
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.register = exports.client = void 0;
7
+ const prom_client_1 = __importDefault(require("prom-client"));
8
+ exports.client = prom_client_1.default;
9
+ const config_1 = require("./config");
10
+ const DEFAULT_LABELS = {};
11
+ const register = prom_client_1.default.register;
12
+ exports.register = register;
13
+ register.setDefaultLabels(DEFAULT_LABELS);
14
+ if (config_1.config.useOpenMetrics) {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ (prom_client_1.default.register).setContentType(prom_client_1.default.Registry.OPENMETRICS_CONTENT_TYPE);
17
+ }
18
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/client.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAc/B,iBAdK,qBAAM,CAcL;AAbR,qCAAkC;AAElC,MAAM,cAAc,GAA2B,EAAE,CAAC;AAElD,MAAM,QAAQ,GAAG,qBAAM,CAAC,QAAQ,CAAC;AAU/B,4BAAQ;AATV,QAAQ,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAE1C,IAAI,eAAM,CAAC,cAAc,EAAE,CAAC;IAC1B,8DAA8D;IAC9D,CAAC,qBAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,qBAAM,CAAC,QAAQ,CAAC,wBAA+B,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const config: {
2
+ readonly enabled: boolean;
3
+ readonly shouldCollectProcessMetrics: boolean;
4
+ readonly host: string;
5
+ readonly port: number;
6
+ readonly useOpenMetrics: boolean;
7
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = void 0;
4
+ exports.config = {
5
+ enabled: process.env['CF_TELEMETRY_PROMETHEUS_ENABLE'] === 'true',
6
+ shouldCollectProcessMetrics: process.env['CF_TELEMETRY_PROMETHEUS_ENABLE_PROCESS_METRICS'] === 'true',
7
+ host: process.env['CF_TELEMETRY_PROMETHEUS_HOST'] ?? '0.0.0.0',
8
+ port: Number.parseInt(process.env['CF_TELEMETRY_PROMETHEUS_PORT'] ?? '9100', 10),
9
+ useOpenMetrics: process.env['CF_TELEMETRY_PROMETHEUS_USE_OPEN_METRICS'] === 'true',
10
+ };
11
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/config.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,KAAK,MAAM;IACjE,2BAA2B,EAAE,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,KAAK,MAAM;IACrG,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,IAAI,SAAS;IAC9D,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,IAAI,MAAM,EAAE,EAAE,CAAC;IAChF,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,KAAK,MAAM;CAC1E,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { client, register } from './client';
2
+ export { initPrometheus } from './init-prometheus';
3
+ export * as metrics from './metrics';
@@ -0,0 +1,43 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.metrics = exports.initPrometheus = exports.register = exports.client = void 0;
37
+ var client_1 = require("./client");
38
+ Object.defineProperty(exports, "client", { enumerable: true, get: function () { return client_1.client; } });
39
+ Object.defineProperty(exports, "register", { enumerable: true, get: function () { return client_1.register; } });
40
+ var init_prometheus_1 = require("./init-prometheus");
41
+ Object.defineProperty(exports, "initPrometheus", { enumerable: true, get: function () { return init_prometheus_1.initPrometheus; } });
42
+ exports.metrics = __importStar(require("./metrics"));
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACzB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,qDAAqC"}
@@ -0,0 +1,2 @@
1
+ import type { Logger } from '../../logger';
2
+ export declare const initPrometheus: (logger: Logger) => Promise<void>;
@@ -0,0 +1,38 @@
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.initPrometheus = void 0;
7
+ const fastify_1 = __importDefault(require("fastify"));
8
+ const client_1 = require("./client");
9
+ const config_1 = require("./config");
10
+ const initPrometheus = async (logger) => {
11
+ logger = logger.child('prometheus');
12
+ if (config_1.config.enabled === false) {
13
+ logger.info('Prometheus server is disabled. Set CF_TELEMETRY_PROMETHEUS_ENABLE=true to enable it');
14
+ return;
15
+ }
16
+ ;
17
+ try {
18
+ logger.info({ config: config_1.config }, 'Initializing Prometheus');
19
+ if (config_1.config.shouldCollectProcessMetrics)
20
+ client_1.client.collectDefaultMetrics();
21
+ const metricsServer = (0, fastify_1.default)();
22
+ metricsServer.get('/metrics', async (_request, reply) => {
23
+ reply.type(client_1.register.contentType);
24
+ return client_1.register.metrics();
25
+ });
26
+ const address = await metricsServer.listen({
27
+ host: config_1.config.host,
28
+ port: config_1.config.port,
29
+ });
30
+ logger.info(`Prometheus server listening on ${address}`);
31
+ logger.info('Prometheus initialized');
32
+ }
33
+ catch (exception) {
34
+ logger.error(exception, 'Failed to initialize Prometheus');
35
+ }
36
+ };
37
+ exports.initPrometheus = initPrometheus;
38
+ //# sourceMappingURL=init-prometheus.js.map
@@ -0,0 +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,EAAE,yBAAyB,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,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC,CAAC;AAxBW,QAAA,cAAc,kBAwBzB"}
@@ -0,0 +1,22 @@
1
+ import type { CounterConfiguration as CounterConfigurationOriginal, GaugeConfiguration as GaugeConfigurationOriginal, HistogramConfiguration as HistogramConfigurationOriginal, MetricConfiguration as MetricConfigurationOriginal, SummaryConfiguration as SummaryConfigurationOriginal } from 'prom-client';
2
+ import { Counter as CounterOriginal, Gauge as GaugeOriginal, Histogram as HistogramOriginal, Summary as SummaryOriginal } from 'prom-client';
3
+ export type MetricConfiguration<T extends string> = MetricConfigurationOriginal<T> & {
4
+ name: `codefresh_${string}`;
5
+ };
6
+ export type CounterConfiguration<T extends string> = CounterConfigurationOriginal<T> & MetricConfiguration<T>;
7
+ export declare class Counter<T extends string> extends CounterOriginal<T> {
8
+ constructor(config: CounterConfiguration<T>);
9
+ }
10
+ export type GaugeConfiguration<T extends string> = GaugeConfigurationOriginal<T> & MetricConfiguration<T>;
11
+ export declare class Gauge<T extends string> extends GaugeOriginal<T> {
12
+ constructor(config: GaugeConfiguration<T>);
13
+ }
14
+ export type HistogramConfiguration<T extends string> = HistogramConfigurationOriginal<T> & MetricConfiguration<T>;
15
+ export declare class Histogram<T extends string> extends HistogramOriginal<T> {
16
+ constructor(config: HistogramConfiguration<T>);
17
+ }
18
+ export type SummaryConfiguration<T extends string> = SummaryConfigurationOriginal<T> & MetricConfiguration<T>;
19
+ export declare class Summary<T extends string> extends SummaryOriginal<T> {
20
+ constructor(config: SummaryConfiguration<T>);
21
+ }
22
+ export type Metric<T extends string> = Counter<T> | Gauge<T> | Histogram<T> | Summary<T>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Summary = exports.Histogram = exports.Gauge = exports.Counter = void 0;
4
+ const prom_client_1 = require("prom-client");
5
+ class Counter extends prom_client_1.Counter {
6
+ constructor(config) {
7
+ super(config);
8
+ }
9
+ }
10
+ exports.Counter = Counter;
11
+ class Gauge extends prom_client_1.Gauge {
12
+ constructor(config) {
13
+ super(config);
14
+ }
15
+ }
16
+ exports.Gauge = Gauge;
17
+ class Histogram extends prom_client_1.Histogram {
18
+ constructor(config) {
19
+ super(config);
20
+ }
21
+ }
22
+ exports.Histogram = Histogram;
23
+ class Summary extends prom_client_1.Summary {
24
+ constructor(config) {
25
+ super(config);
26
+ }
27
+ }
28
+ exports.Summary = Summary;
29
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/metrics/prometheus/metrics.ts"],"names":[],"mappings":";;;AAOA,6CAKqB;AAKrB,MAAa,OAA0B,SAAQ,qBAAkB;IAC/D,YAAY,MAA+B;QACzC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF;AAJD,0BAIC;AAGD,MAAa,KAAwB,SAAQ,mBAAgB;IAC3D,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF;AAJD,sBAIC;AAGD,MAAa,SAA4B,SAAQ,uBAAoB;IACnE,YAAY,MAAiC;QAC3C,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF;AAJD,8BAIC;AAGD,MAAa,OAA0B,SAAQ,qBAAkB;IAC/D,YAAY,MAA+B;QACzC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF;AAJD,0BAIC"}
@@ -0,0 +1,6 @@
1
+ export declare const config: {
2
+ readonly enabled: boolean;
3
+ readonly config: {
4
+ tags: Record<string, string> | undefined;
5
+ };
6
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.config = void 0;
4
+ exports.config = {
5
+ enabled: process.env['CF_TELEMETRY_PYROSCOPE_ENABLE'] === 'true',
6
+ config: {
7
+ tags: process.env['CF_TELEMETRY_PYROSCOPE_TAGS']
8
+ ? process.env['CF_TELEMETRY_PYROSCOPE_TAGS'].split(',').reduce((acc, pair) => {
9
+ const [key, value] = pair.split('=');
10
+ if (!key || !value)
11
+ return acc;
12
+ acc[key] = value;
13
+ return acc;
14
+ }, {})
15
+ : undefined,
16
+ },
17
+ };
18
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/profiles/config.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,KAAK,MAAM;IAChE,MAAM,EAAE;QACN,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;YAC9C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACzE,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;oBAAE,OAAO,GAAG,CAAC;gBAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACjB,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAA4B,CAAC;YAClC,CAAC,CAAC,SAAS;KACY;CACnB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Logger } from '../logger';
2
+ export declare const initPyroscope: (logger: Logger) => Promise<void>;
@@ -0,0 +1,21 @@
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.initPyroscope = void 0;
7
+ const nodejs_1 = __importDefault(require("@pyroscope/nodejs"));
8
+ const config_1 = require("./config");
9
+ const initPyroscope = async (logger) => {
10
+ logger = logger.child('pyroscope');
11
+ if (!config_1.config.enabled) {
12
+ logger.info('Pyroscope is disabled. Set CF_TELEMETRY_PYROSCOPE_ENABLE=true to enable it');
13
+ return;
14
+ }
15
+ logger.info({ config: config_1.config.config }, 'Initializing Pyroscope');
16
+ nodejs_1.default.init(config_1.config.config);
17
+ nodejs_1.default.start();
18
+ logger.info('Pyroscope initialized');
19
+ };
20
+ exports.initPyroscope = initPyroscope;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,EAAE,wBAAwB,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 ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@codefresh-io/cf-telemetry",
3
+ "version": "1.0.1",
4
+ "main": "dist/index.js",
5
+ "files": [
6
+ "dist/**/*"
7
+ ],
8
+ "packageManager": "yarn@4.5.2",
9
+ "scripts": {
10
+ "build": "rimraf ./dist && tsc --project tsconfig.build.json",
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest",
15
+ "test:cov": "vitest run --coverage"
16
+ },
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "devDependencies": {
21
+ "@eslint/js": "^9.18.0",
22
+ "@stylistic/eslint-plugin": "^2.12.1",
23
+ "@types/node": "^22.10.5",
24
+ "eslint": "^9.18.0",
25
+ "mongodb": "^6.12.0",
26
+ "pino-pretty": "^13.0.0",
27
+ "rimraf": "^6.0.1",
28
+ "typescript": "^5.7.3",
29
+ "typescript-eslint": "^8.19.1",
30
+ "vitest": "^2.1.8"
31
+ },
32
+ "dependencies": {
33
+ "@christiangalsterer/mongodb-driver-prometheus-exporter": "^2.3.0",
34
+ "@pyroscope/nodejs": "^0.4.3",
35
+ "change-case-all": "^2.1.0",
36
+ "fastify": "^5.2.1",
37
+ "pino": "^9.6.0",
38
+ "prom-client": "^15.1.3"
39
+ },
40
+ "peerDependencies": {
41
+ "mongodb": "^6.9.0"
42
+ }
43
+ }