@blaxel/telemetry 0.2.6 → 0.2.7-preview.7

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/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Blaxel Typescript SDK
2
+
3
+ <p align="center">
4
+ <img src="https://blaxel.ai/logo.png" alt="Blaxel"/>
5
+ </p>
6
+
7
+ **Blaxel is a computing platform for AI agent builders, with all the services and infrastructure to build and deploy agents efficiently.** This repository contains the TypeScript SDK to enable our integrated telemetry.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Installation](#installation)
12
+ - [Features](#features)
13
+
14
+
15
+
16
+ ## Installation
17
+
18
+ Install Blaxel telemetry SDK, which lets you enable telemetry.
19
+
20
+ ```bash
21
+ ## npm
22
+ npm install @blaxel/telemetry
23
+
24
+ ## pnpm
25
+ pnpm i @blaxel/telemetry
26
+
27
+ ## yarn
28
+ yarn add @blaxel/telemetry
29
+ ```
30
+
31
+
32
+ ## Features
33
+ - Enable tracing : Trace are automatically sampled at 10%, and can be retrieved from the Blaxel console.
34
+
35
+
36
+ Instrumentation happens automatically when workloads run on Blaxel. To enable telemetry, simply require the SDK in your project's entry point.
37
+ ```ts
38
+ import "@blaxel/telemetry";
39
+ ```
40
+
41
+
42
+
43
+ ## Contributing
44
+
45
+ Contributions are welcome! Please feel free to submit a Pull Request.
46
+
47
+
48
+
49
+ ## License
50
+
51
+ This project is licensed under the MIT License - see the LICENSE file for details.
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blaxelTelemetry = void 0;
4
+ const core_1 = require("@blaxel/core");
5
+ const json_logger_1 = require("./json_logger");
4
6
  const legacy_logger_1 = require("./legacy_logger");
5
7
  const telemetry_1 = require("./telemetry");
6
8
  Object.defineProperty(exports, "blaxelTelemetry", { enumerable: true, get: function () { return telemetry_1.blaxelTelemetry; } });
7
9
  telemetry_1.blaxelTelemetry.initialize();
8
- // if (settings.loggerType === "http") {
9
- (0, legacy_logger_1.setLegacyLogger)();
10
+ if (core_1.settings.loggerType === "http") {
11
+ (0, legacy_logger_1.setLegacyLogger)();
12
+ }
13
+ else if (core_1.settings.loggerType === "json") {
14
+ (0, json_logger_1.setJsonLogger)();
15
+ }
@@ -38,6 +38,7 @@ 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>;
41
42
  getLogger(): Promise<Logger>;
42
43
  setupSignalHandler(): void;
43
44
  /**
package/dist/telemetry.js CHANGED
@@ -112,6 +112,17 @@ 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
+ }
115
126
  async getLogger() {
116
127
  if (!this.otelLogger) {
117
128
  await this.sleep(100);
@@ -1,4 +1,7 @@
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;
3
5
  startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
6
+ flush(): Promise<void>;
4
7
  }
@@ -2,8 +2,10 @@
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");
5
6
  class OtelSpan {
6
7
  span;
8
+ closed = false;
7
9
  constructor(span) {
8
10
  this.span = span;
9
11
  }
@@ -24,6 +26,7 @@ class OtelSpan {
24
26
  });
25
27
  }
26
28
  end() {
29
+ this.closed = true;
27
30
  this.span.end();
28
31
  }
29
32
  getContext() {
@@ -31,22 +34,29 @@ class OtelSpan {
31
34
  }
32
35
  }
33
36
  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
+ }
34
47
  startSpan(name, options) {
35
- // Use the tracer from the registered NodeTracerProvider
36
48
  const tracer = api_1.trace.getTracer("blaxel");
37
- // Prepare OpenTelemetry span options
38
49
  const otelOptions = {
39
50
  attributes: options?.attributes,
40
51
  root: options?.isRoot,
41
52
  };
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);
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();
50
60
  }
51
61
  }
52
62
  exports.OtelTelemetryProvider = OtelTelemetryProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.6",
3
+ "version": "0.2.7-preview.7",
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.6"
74
+ "@blaxel/core": "0.2.7-preview.7"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",