@blaxel/telemetry 0.2.0-dev3 → 0.2.0-dev5

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 CHANGED
@@ -1,3 +1,2 @@
1
- import { originalLogger } from "./logger";
2
1
  import { blaxelTelemetry } from "./telemetry";
3
- export { blaxelTelemetry, originalLogger };
2
+ export { blaxelTelemetry };
package/dist/index.js CHANGED
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.originalLogger = exports.blaxelTelemetry = void 0;
4
- const logger_1 = require("./logger");
5
- Object.defineProperty(exports, "originalLogger", { enumerable: true, get: function () { return logger_1.originalLogger; } });
3
+ exports.blaxelTelemetry = void 0;
4
+ const core_1 = require("@blaxel/core");
5
+ const json_logger_1 = require("./json_logger");
6
+ const legacy_logger_1 = require("./legacy_logger");
6
7
  const telemetry_1 = require("./telemetry");
7
8
  Object.defineProperty(exports, "blaxelTelemetry", { enumerable: true, get: function () { return telemetry_1.blaxelTelemetry; } });
8
9
  telemetry_1.blaxelTelemetry.initialize();
10
+ if (core_1.env.BL_LOGGER === "legacy") {
11
+ (0, legacy_logger_1.setLegacyLogger)();
12
+ }
13
+ else if (core_1.env.BL_LOGGER === "json") {
14
+ (0, json_logger_1.setJsonLogger)();
15
+ }
@@ -0,0 +1,15 @@
1
+ export declare function setJsonLogger(): void;
2
+ export declare const originalLogger: {
3
+ info: (message?: any, ...optionalParams: any[]) => void;
4
+ error: (message?: any, ...optionalParams: any[]) => void;
5
+ warn: (message?: any, ...optionalParams: any[]) => void;
6
+ debug: (message?: any, ...optionalParams: any[]) => void;
7
+ log: (message?: any, ...optionalParams: any[]) => void;
8
+ };
9
+ /**
10
+ * Stringify an object with a limited depth
11
+ * @param obj The object to stringify
12
+ * @param maxDepth Maximum depth (default: 1)
13
+ * @param depth Current depth (internal use)
14
+ */
15
+ export declare function stringify<T>(obj: T, maxDepth?: number, depth?: number): string;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /* eslint-disable no-console */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.originalLogger = void 0;
5
+ exports.setJsonLogger = setJsonLogger;
6
+ exports.stringify = stringify;
7
+ const core_1 = require("@blaxel/core");
8
+ function setJsonLogger() {
9
+ console.debug = (message, ...args) => {
10
+ const msg = formatLogMessage("DEBUG", message, args);
11
+ exports.originalLogger.log(msg);
12
+ };
13
+ console.log = (message, ...args) => {
14
+ const msg = formatLogMessage("INFO", message, args);
15
+ exports.originalLogger.log(msg);
16
+ };
17
+ console.info = (message, ...args) => {
18
+ const msg = formatLogMessage("INFO", message, args);
19
+ exports.originalLogger.log(msg);
20
+ };
21
+ console.warn = (message, ...args) => {
22
+ const msg = formatLogMessage("WARN", message, args);
23
+ exports.originalLogger.log(msg);
24
+ };
25
+ console.error = (message, ...args) => {
26
+ const msg = formatLogMessage("ERROR", message, args);
27
+ exports.originalLogger.log(msg);
28
+ };
29
+ }
30
+ exports.originalLogger = {
31
+ info: console.info,
32
+ error: console.error,
33
+ warn: console.warn,
34
+ debug: console.debug,
35
+ log: console.log,
36
+ };
37
+ /**
38
+ * Stringify an object with a limited depth
39
+ * @param obj The object to stringify
40
+ * @param maxDepth Maximum depth (default: 1)
41
+ * @param depth Current depth (internal use)
42
+ */
43
+ function stringify(obj, maxDepth = 1, depth = 0) {
44
+ if (obj instanceof Error)
45
+ return obj.stack || obj.message;
46
+ if (obj === null)
47
+ return 'null';
48
+ if (obj === undefined)
49
+ return 'undefined';
50
+ // If we've reached max depth or it's not an object
51
+ if (depth >= maxDepth || typeof obj !== 'object') {
52
+ return typeof obj === 'object' ? `[${Array.isArray(obj) ? 'Array' : 'object'}]` :
53
+ typeof obj === 'string' ? `"${obj}"` : String(obj);
54
+ }
55
+ // Handle arrays
56
+ if (Array.isArray(obj)) {
57
+ return `[${obj.map(item => stringify(item, maxDepth, depth + 1)).join(', ')}]`;
58
+ }
59
+ // Handle objects
60
+ const pairs = Object.entries(obj).map(([key, val]) => `"${key}": ${stringify(val, maxDepth, depth + 1)}`);
61
+ return `{${pairs.join(', ')}}`;
62
+ }
63
+ // Format a log message with appropriate color and prefix
64
+ function formatLogMessage(severity, message, args) {
65
+ const messageStr = typeof message === "string" ? message : stringify(message, 2);
66
+ const argsStr = args.map(arg => typeof arg === "string" ? arg : stringify(arg, 2)).join(" ");
67
+ let msg = `${messageStr}${argsStr ? " " + argsStr : ""}`;
68
+ return JSON.stringify({
69
+ message: msg,
70
+ severity,
71
+ labels: getLabels()
72
+ });
73
+ }
74
+ function getLabels() {
75
+ return {
76
+ "blaxel-workspace": core_1.settings.workspace,
77
+ "blaxel-name": core_1.settings.name,
78
+ "blaxel-type": core_1.settings.type,
79
+ };
80
+ }
@@ -0,0 +1,15 @@
1
+ export declare function setLegacyLogger(): void;
2
+ export declare const originalLogger: {
3
+ info: (message?: any, ...optionalParams: any[]) => void;
4
+ error: (message?: any, ...optionalParams: any[]) => void;
5
+ warn: (message?: any, ...optionalParams: any[]) => void;
6
+ debug: (message?: any, ...optionalParams: any[]) => void;
7
+ log: (message?: any, ...optionalParams: any[]) => void;
8
+ };
9
+ /**
10
+ * Stringify an object with a limited depth
11
+ * @param obj The object to stringify
12
+ * @param maxDepth Maximum depth (default: 1)
13
+ * @param depth Current depth (internal use)
14
+ */
15
+ export declare function stringify<T>(obj: T, maxDepth?: number, depth?: number): string;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.originalLogger = void 0;
4
+ exports.setLegacyLogger = setLegacyLogger;
5
+ exports.stringify = stringify;
6
+ /* eslint-disable no-console */
7
+ const api_logs_1 = require("@opentelemetry/api-logs");
8
+ const telemetry_1 = require("./telemetry");
9
+ function setLegacyLogger() {
10
+ console.debug = (message, ...args) => {
11
+ const msg = formatLogMessage(message, args);
12
+ exports.originalLogger.log(msg);
13
+ emitLogSync(api_logs_1.SeverityNumber.DEBUG, msg);
14
+ };
15
+ console.log = (message, ...args) => {
16
+ const msg = formatLogMessage(message, args);
17
+ exports.originalLogger.log(msg);
18
+ emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
19
+ };
20
+ console.info = (message, ...args) => {
21
+ const msg = formatLogMessage(message, args);
22
+ exports.originalLogger.log(msg);
23
+ emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
24
+ };
25
+ console.error = (message, ...args) => {
26
+ const msg = formatLogMessage(message, args);
27
+ exports.originalLogger.log(msg);
28
+ emitLogSync(api_logs_1.SeverityNumber.ERROR, msg);
29
+ };
30
+ console.warn = (message, ...args) => {
31
+ const msg = formatLogMessage(message, args);
32
+ exports.originalLogger.log(msg);
33
+ emitLogSync(api_logs_1.SeverityNumber.WARN, msg);
34
+ };
35
+ }
36
+ exports.originalLogger = {
37
+ info: console.info,
38
+ error: console.error,
39
+ warn: console.warn,
40
+ debug: console.debug,
41
+ log: console.log,
42
+ };
43
+ /**
44
+ * Stringify an object with a limited depth
45
+ * @param obj The object to stringify
46
+ * @param maxDepth Maximum depth (default: 1)
47
+ * @param depth Current depth (internal use)
48
+ */
49
+ function stringify(obj, maxDepth = 1, depth = 0) {
50
+ if (obj instanceof Error)
51
+ return obj.stack || obj.message;
52
+ if (obj === null)
53
+ return 'null';
54
+ if (obj === undefined)
55
+ return 'undefined';
56
+ // If we've reached max depth or it's not an object
57
+ if (depth >= maxDepth || typeof obj !== 'object') {
58
+ return typeof obj === 'object' ? `[${Array.isArray(obj) ? 'Array' : 'object'}]` :
59
+ typeof obj === 'string' ? `"${obj}"` : String(obj);
60
+ }
61
+ // Handle arrays
62
+ if (Array.isArray(obj)) {
63
+ return `[${obj.map(item => stringify(item, maxDepth, depth + 1)).join(', ')}]`;
64
+ }
65
+ // Handle objects
66
+ const pairs = Object.entries(obj).map(([key, val]) => `"${key}": ${stringify(val, maxDepth, depth + 1)}`);
67
+ return `{${pairs.join(', ')}}`;
68
+ }
69
+ // Format a log message with appropriate color and prefix
70
+ function formatLogMessage(message, args) {
71
+ const messageStr = typeof message === "string" ? message : stringify(message, 2);
72
+ const argsStr = args.map(arg => typeof arg === "string" ? arg : stringify(arg, 2)).join(" ");
73
+ return `${messageStr}${argsStr ? " " + argsStr : ""}`;
74
+ }
75
+ async function emitLog(severityNumber, message) {
76
+ const loggerInstance = await telemetry_1.blaxelTelemetry.getLogger();
77
+ loggerInstance.emit({
78
+ severityNumber: severityNumber,
79
+ body: message,
80
+ });
81
+ }
82
+ function emitLogSync(severityNumber, message) {
83
+ emitLog(severityNumber, message).catch(() => { });
84
+ }
package/dist/logger.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare function overrideConsole(): void;
1
2
  export declare const originalLogger: {
2
3
  info: (message?: any, ...optionalParams: any[]) => void;
3
4
  error: (message?: any, ...optionalParams: any[]) => void;
package/dist/logger.js CHANGED
@@ -1,10 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.originalLogger = void 0;
4
+ exports.overrideConsole = overrideConsole;
4
5
  exports.stringify = stringify;
5
6
  /* eslint-disable no-console */
6
7
  const api_logs_1 = require("@opentelemetry/api-logs");
7
8
  const telemetry_1 = require("./telemetry");
9
+ function overrideConsole() {
10
+ console.debug = (message, ...args) => {
11
+ const msg = formatLogMessage(message, args);
12
+ exports.originalLogger.log(msg);
13
+ emitLogSync(api_logs_1.SeverityNumber.DEBUG, msg);
14
+ };
15
+ console.log = (message, ...args) => {
16
+ const msg = formatLogMessage(message, args);
17
+ exports.originalLogger.log(msg);
18
+ emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
19
+ };
20
+ console.info = (message, ...args) => {
21
+ const msg = formatLogMessage(message, args);
22
+ exports.originalLogger.log(msg);
23
+ emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
24
+ };
25
+ console.error = (message, ...args) => {
26
+ const msg = formatLogMessage(message, args);
27
+ exports.originalLogger.log(msg);
28
+ emitLogSync(api_logs_1.SeverityNumber.ERROR, msg);
29
+ };
30
+ console.warn = (message, ...args) => {
31
+ const msg = formatLogMessage(message, args);
32
+ exports.originalLogger.log(msg);
33
+ emitLogSync(api_logs_1.SeverityNumber.WARN, msg);
34
+ };
35
+ }
8
36
  exports.originalLogger = {
9
37
  info: console.info,
10
38
  error: console.error,
@@ -54,28 +82,3 @@ async function emitLog(severityNumber, message) {
54
82
  function emitLogSync(severityNumber, message) {
55
83
  emitLog(severityNumber, message).catch(() => { });
56
84
  }
57
- console.debug = (message, ...args) => {
58
- const msg = formatLogMessage(message, args);
59
- exports.originalLogger.log(msg);
60
- emitLogSync(api_logs_1.SeverityNumber.DEBUG, msg);
61
- };
62
- console.log = (message, ...args) => {
63
- const msg = formatLogMessage(message, args);
64
- exports.originalLogger.log(msg);
65
- emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
66
- };
67
- console.info = (message, ...args) => {
68
- const msg = formatLogMessage(message, args);
69
- exports.originalLogger.log(msg);
70
- emitLogSync(api_logs_1.SeverityNumber.INFO, msg);
71
- };
72
- console.error = (message, ...args) => {
73
- const msg = formatLogMessage(message, args);
74
- exports.originalLogger.log(msg);
75
- emitLogSync(api_logs_1.SeverityNumber.ERROR, msg);
76
- };
77
- console.warn = (message, ...args) => {
78
- const msg = formatLogMessage(message, args);
79
- exports.originalLogger.log(msg);
80
- emitLogSync(api_logs_1.SeverityNumber.WARN, msg);
81
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.0-dev3",
3
+ "version": "0.2.0-dev5",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -71,7 +71,7 @@
71
71
  "@opentelemetry/sdk-trace-base": "^2.0.0",
72
72
  "@opentelemetry/sdk-trace-node": "^2.0.0",
73
73
  "ai": "^4.3.13",
74
- "@blaxel/core": "0.2.0-dev3"
74
+ "@blaxel/core": "0.2.0-dev5"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",