@blaxel/telemetry 0.2.0-dev9 → 0.2.0-preview2

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.
@@ -6,10 +6,3 @@ export declare const originalLogger: {
6
6
  debug: (message?: any, ...optionalParams: any[]) => void;
7
7
  log: (message?: any, ...optionalParams: any[]) => void;
8
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;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.originalLogger = void 0;
5
5
  exports.setJsonLogger = setJsonLogger;
6
- exports.stringify = stringify;
6
+ const core_1 = require("@blaxel/core");
7
7
  const api_1 = require("@opentelemetry/api");
8
8
  function setJsonLogger() {
9
9
  console.debug = (message, ...args) => {
@@ -34,36 +34,10 @@ exports.originalLogger = {
34
34
  debug: console.debug,
35
35
  log: console.log,
36
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
37
  // Format a log message with appropriate color and prefix
64
38
  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(" ");
39
+ const messageStr = typeof message === "string" ? message : (0, core_1.stringify)(message, 2);
40
+ const argsStr = args.map(arg => typeof arg === "string" ? arg : (0, core_1.stringify)(arg, 2)).join(" ");
67
41
  let msg = `${messageStr}${argsStr ? " " + argsStr : ""}`;
68
42
  return JSON.stringify({
69
43
  message: msg,
@@ -6,10 +6,3 @@ export declare const originalLogger: {
6
6
  debug: (message?: any, ...optionalParams: any[]) => void;
7
7
  log: (message?: any, ...optionalParams: any[]) => void;
8
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;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.originalLogger = void 0;
4
4
  exports.setLegacyLogger = setLegacyLogger;
5
- exports.stringify = stringify;
6
5
  /* eslint-disable no-console */
6
+ const core_1 = require("@blaxel/core");
7
7
  const api_logs_1 = require("@opentelemetry/api-logs");
8
8
  const telemetry_1 = require("./telemetry");
9
9
  function setLegacyLogger() {
@@ -40,36 +40,10 @@ exports.originalLogger = {
40
40
  debug: console.debug,
41
41
  log: console.log,
42
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
43
  // Format a log message with appropriate color and prefix
70
44
  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(" ");
45
+ const messageStr = typeof message === "string" ? message : (0, core_1.stringify)(message, 2);
46
+ const argsStr = args.map(arg => typeof arg === "string" ? arg : (0, core_1.stringify)(arg, 2)).join(" ");
73
47
  return `${messageStr}${argsStr ? " " + argsStr : ""}`;
74
48
  }
75
49
  async function emitLog(severityNumber, message) {
package/dist/telemetry.js CHANGED
@@ -83,7 +83,7 @@ class TelemetryManager {
83
83
  this.setupSignalHandler();
84
84
  this.initialized = true;
85
85
  this.setConfiguration().catch((error) => {
86
- console.error("Error setting configuration:", error);
86
+ core_1.logger.error("Error setting configuration:", error);
87
87
  });
88
88
  }
89
89
  async setConfiguration() {
@@ -93,7 +93,7 @@ class TelemetryManager {
93
93
  await (0, core_1.authenticate)();
94
94
  this.setExporters();
95
95
  this.otelLogger = api_logs_1.logs.getLogger("blaxel");
96
- console.debug("Telemetry ready");
96
+ core_1.logger.debug("Telemetry ready");
97
97
  this.configured = true;
98
98
  }
99
99
  get enabled() {
@@ -124,10 +124,10 @@ class TelemetryManager {
124
124
  for (const signal of signals) {
125
125
  process.on(signal, (error) => {
126
126
  if (signal !== "exit") {
127
- core_1.logger.error(error.stack);
127
+ core_1.logger.error(error);
128
128
  }
129
129
  this.shutdownApp().catch((error) => {
130
- console.debug("Fatal error during shutdown:", error);
130
+ core_1.logger.debug("Fatal error during shutdown:", error);
131
131
  process.exit(0);
132
132
  });
133
133
  });
@@ -236,28 +236,28 @@ class TelemetryManager {
236
236
  if (this.nodeTracerProvider) {
237
237
  shutdownPromises.push(this.nodeTracerProvider
238
238
  .shutdown()
239
- .catch((error) => console.debug("Error shutting down tracer provider:", error)));
239
+ .catch((error) => core_1.logger.debug("Error shutting down tracer provider:", error)));
240
240
  }
241
241
  if (this.meterProvider) {
242
242
  shutdownPromises.push(this.meterProvider
243
243
  .shutdown()
244
- .catch((error) => console.debug("Error shutting down meter provider:", error)));
244
+ .catch((error) => core_1.logger.debug("Error shutting down meter provider:", error)));
245
245
  }
246
246
  if (this.loggerProvider) {
247
247
  shutdownPromises.push(this.loggerProvider
248
248
  .shutdown()
249
- .catch((error) => console.debug("Error shutting down logger provider:", error)));
249
+ .catch((error) => core_1.logger.debug("Error shutting down logger provider:", error)));
250
250
  }
251
251
  // Wait for all providers to shutdown with a timeout
252
252
  await Promise.race([
253
253
  Promise.all(shutdownPromises),
254
254
  new Promise((resolve) => setTimeout(resolve, 5000)), // 5 second timeout
255
255
  ]);
256
- console.debug("Instrumentation shutdown complete");
256
+ core_1.logger.debug("Instrumentation shutdown complete");
257
257
  process.exit(0);
258
258
  }
259
259
  catch (error) {
260
- console.error("Error during shutdown:", error);
260
+ core_1.logger.error("Error during shutdown:", error);
261
261
  process.exit(1);
262
262
  }
263
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.0-dev9",
3
+ "version": "0.2.0-preview2",
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-dev9"
74
+ "@blaxel/core": "0.2.0-preview2"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",
@@ -1 +0,0 @@
1
- export {};
@@ -1,88 +0,0 @@
1
- "use strict";
2
- // export type InstrumentationInfo = {
3
- // modulePath: string;
4
- // className: string;
5
- // requiredPackages: string[]; // At least one package is required
6
- // ignoreIfPackages?: string[];
7
- // init?: (instrumentor: any) => void;
8
- // };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- // export const instrumentationMap: Record<string, InstrumentationInfo> = {
11
- // express: {
12
- // modulePath: "@opentelemetry/instrumentation-express",
13
- // className: "ExpressInstrumentation",
14
- // requiredPackages: ["express"],
15
- // ignoreIfPackages: ["fastify"],
16
- // },
17
- // fastify: {
18
- // modulePath: "@opentelemetry/instrumentation-fastify",
19
- // className: "FastifyInstrumentation",
20
- // requiredPackages: ["fastify"],
21
- // },
22
- // anthropic: {
23
- // modulePath: "@traceloop/instrumentation-anthropic",
24
- // className: "AnthropicInstrumentation",
25
- // requiredPackages: ["anthropic-ai/sdk"],
26
- // },
27
- // azure: {
28
- // modulePath: "@traceloop/instrumentation-azure",
29
- // className: "AzureInstrumentation",
30
- // requiredPackages: ["azure/openai"],
31
- // },
32
- // bedrock: {
33
- // modulePath: "@traceloop/instrumentation-bedrock",
34
- // className: "BedrockInstrumentation",
35
- // requiredPackages: ["aws-sdk/client-bedrock-runtime"],
36
- // },
37
- // chromadb: {
38
- // modulePath: "@traceloop/instrumentation-chromadb",
39
- // className: "ChromaDBInstrumentation",
40
- // requiredPackages: ["chromadb"],
41
- // },
42
- // cohere: {
43
- // modulePath: "@traceloop/instrumentation-cohere",
44
- // className: "CohereInstrumentation",
45
- // requiredPackages: ["cohere-js"],
46
- // },
47
- // langchain: {
48
- // modulePath: "@traceloop/instrumentation-langchain",
49
- // className: "LangChainInstrumentation",
50
- // requiredPackages: [
51
- // "langchain",
52
- // "@langchain/core",
53
- // "@langchain/community",
54
- // "@langchain/langgraph",
55
- // ],
56
- // init: (instrumentor: any) => {
57
- // // eslint-disable-next-line @typescript-eslint/no-require-imports
58
- // const module = require("./langchain.js") as { [key: string]: any };
59
- // // eslint-disable-next-line @typescript-eslint/no-unsafe-call
60
- // module.langchain(instrumentor);
61
- // },
62
- // },
63
- // llamaindex: {
64
- // modulePath: "@traceloop/instrumentation-llamaindex",
65
- // className: "LlamaIndexInstrumentation",
66
- // requiredPackages: ["llamaindex"],
67
- // },
68
- // openai: {
69
- // modulePath: "@traceloop/instrumentation-openai",
70
- // className: "OpenAIInstrumentation",
71
- // requiredPackages: ["openai"],
72
- // },
73
- // pinecone: {
74
- // modulePath: "@traceloop/instrumentation-pinecone",
75
- // className: "PineconeInstrumentation",
76
- // requiredPackages: ["pinecone-database/pinecone"],
77
- // },
78
- // qdrant: {
79
- // modulePath: "@traceloop/instrumentation-qdrant",
80
- // className: "QdrantInstrumentation",
81
- // requiredPackages: ["qdrant/js-client-rest"],
82
- // },
83
- // vertexai: {
84
- // modulePath: "@traceloop/instrumentation-vertexai",
85
- // className: "VertexAIInstrumentation",
86
- // requiredPackages: ["google-cloud/aiplatform"],
87
- // },
88
- // };
package/dist/intex.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/intex.js DELETED
@@ -1,7 +0,0 @@
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
- const telemetry_1 = __importDefault(require("./telemetry"));
7
- telemetry_1.default.init();
package/dist/logger.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export declare function overrideConsole(): 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;
package/dist/logger.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.originalLogger = void 0;
4
- exports.overrideConsole = overrideConsole;
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 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
- }
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
- }