@blaxel/telemetry 0.2.4-dev.73 → 0.2.4-dev2

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,88 @@
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
+ // };
@@ -0,0 +1 @@
1
+ export {};
package/dist/intex.js ADDED
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,15 @@
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 ADDED
@@ -0,0 +1,84 @@
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
+ }
@@ -38,7 +38,6 @@ declare class TelemetryManager {
38
38
  get enabled(): boolean;
39
39
  get authHeaders(): Record<string, string>;
40
40
  sleep(ms: number): Promise<unknown>;
41
- flush(): Promise<void>;
42
41
  getLogger(): Promise<Logger>;
43
42
  setupSignalHandler(): void;
44
43
  /**
package/dist/telemetry.js CHANGED
@@ -112,17 +112,6 @@ class TelemetryManager {
112
112
  async sleep(ms) {
113
113
  return new Promise((resolve) => setTimeout(resolve, ms));
114
114
  }
115
- async flush() {
116
- if (this.nodeTracerProvider) {
117
- await this.nodeTracerProvider.shutdown();
118
- }
119
- if (this.meterProvider) {
120
- await this.meterProvider.shutdown();
121
- }
122
- if (this.loggerProvider) {
123
- await this.loggerProvider.shutdown();
124
- }
125
- }
126
115
  async getLogger() {
127
116
  if (!this.otelLogger) {
128
117
  await this.sleep(100);
@@ -1,7 +1,4 @@
1
1
  import { BlaxelSpan, BlaxelSpanOptions, BlaxelTelemetryProvider } from "@blaxel/core";
2
2
  export declare class OtelTelemetryProvider implements BlaxelTelemetryProvider {
3
- private spans;
4
- retrieveActiveSpanContext(): import("@opentelemetry/api").Context;
5
3
  startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
6
- flush(): Promise<void>;
7
4
  }
@@ -2,10 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OtelTelemetryProvider = void 0;
4
4
  const api_1 = require("@opentelemetry/api");
5
- const telemetry_1 = require("./telemetry");
6
5
  class OtelSpan {
7
6
  span;
8
- closed = false;
9
7
  constructor(span) {
10
8
  this.span = span;
11
9
  }
@@ -26,7 +24,6 @@ class OtelSpan {
26
24
  });
27
25
  }
28
26
  end() {
29
- this.closed = true;
30
27
  this.span.end();
31
28
  }
32
29
  getContext() {
@@ -34,29 +31,22 @@ class OtelSpan {
34
31
  }
35
32
  }
36
33
  class OtelTelemetryProvider {
37
- spans = [];
38
- retrieveActiveSpanContext() {
39
- for (let i = this.spans.length - 1; i >= 0; i--) {
40
- const span = this.spans[i];
41
- if (!span.closed) {
42
- return api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, span.getContext());
43
- }
44
- }
45
- return api_1.context.active();
46
- }
47
34
  startSpan(name, options) {
35
+ // Use the tracer from the registered NodeTracerProvider
48
36
  const tracer = api_1.trace.getTracer("blaxel");
37
+ // Prepare OpenTelemetry span options
49
38
  const otelOptions = {
50
39
  attributes: options?.attributes,
51
40
  root: options?.isRoot,
52
41
  };
53
- let ctx = this.retrieveActiveSpanContext();
54
- let span = new OtelSpan(tracer.startSpan(name, otelOptions, ctx));
55
- this.spans.push(span);
56
- return span;
57
- }
58
- async flush() {
59
- await telemetry_1.blaxelTelemetry.flush();
42
+ // Handle parent context if provided
43
+ let ctx = api_1.context.active();
44
+ if (options?.parentContext) {
45
+ ctx = options.parentContext;
46
+ }
47
+ // Start the span
48
+ const span = tracer.startSpan(name, otelOptions, ctx);
49
+ return new OtelSpan(span);
60
50
  }
61
51
  }
62
52
  exports.OtelTelemetryProvider = OtelTelemetryProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.4-dev.73",
3
+ "version": "0.2.4-dev2",
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.4-dev.73"
74
+ "@blaxel/core": "0.2.4-dev2"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",