@blaxel/telemetry 0.2.0-dev4 → 0.2.0-dev6
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 -2
- package/dist/index.js +8 -6
- package/dist/json_logger.d.ts +15 -0
- package/dist/json_logger.js +83 -0
- package/dist/legacy_logger.d.ts +15 -0
- package/dist/legacy_logger.js +84 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.blaxelTelemetry = void 0;
|
|
4
4
|
const core_1 = require("@blaxel/core");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "overrideConsole", { enumerable: true, get: function () { return logger_1.overrideConsole; } });
|
|
5
|
+
const json_logger_1 = require("./json_logger");
|
|
6
|
+
const legacy_logger_1 = require("./legacy_logger");
|
|
8
7
|
const telemetry_1 = require("./telemetry");
|
|
9
8
|
Object.defineProperty(exports, "blaxelTelemetry", { enumerable: true, get: function () { return telemetry_1.blaxelTelemetry; } });
|
|
10
9
|
telemetry_1.blaxelTelemetry.initialize();
|
|
11
|
-
if (core_1.env.
|
|
12
|
-
(0,
|
|
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)();
|
|
13
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,83 @@
|
|
|
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 api_1 = require("@opentelemetry/api");
|
|
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
|
+
const currentSpan = api_1.trace.getActiveSpan();
|
|
76
|
+
if (currentSpan) {
|
|
77
|
+
const { traceId, spanId } = currentSpan.spanContext();
|
|
78
|
+
return {
|
|
79
|
+
"trace-id": traceId,
|
|
80
|
+
"span-id": spanId
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/telemetry",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-dev6",
|
|
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-
|
|
74
|
+
"@blaxel/core": "0.2.0-dev6"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/js": "^9.26.0",
|