@blaxel/telemetry 0.2.16 → 0.2.17-dev.107

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.
@@ -1,7 +1,5 @@
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
4
  flush(): Promise<void>;
7
5
  }
@@ -5,7 +5,6 @@ const api_1 = require("@opentelemetry/api");
5
5
  const telemetry_1 = require("./telemetry");
6
6
  class OtelSpan {
7
7
  span;
8
- closed = false;
9
8
  constructor(span) {
10
9
  this.span = span;
11
10
  }
@@ -21,12 +20,11 @@ class OtelSpan {
21
20
  }
22
21
  setStatus(status, message) {
23
22
  this.span.setStatus({
24
- code: status === 'ok' ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
23
+ code: status === "ok" ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
25
24
  message,
26
25
  });
27
26
  }
28
27
  end() {
29
- this.closed = true;
30
28
  this.span.end();
31
29
  }
32
30
  getContext() {
@@ -34,26 +32,28 @@ class OtelSpan {
34
32
  }
35
33
  }
36
34
  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
35
  startSpan(name, options) {
36
+ // Use the tracer from the registered NodeTracerProvider
48
37
  const tracer = api_1.trace.getTracer("blaxel");
38
+ // Prepare OpenTelemetry span options
49
39
  const otelOptions = {
50
40
  attributes: options?.attributes,
51
41
  root: options?.isRoot,
52
42
  };
53
- const ctx = this.retrieveActiveSpanContext();
54
- const span = new OtelSpan(tracer.startSpan(name, otelOptions, ctx));
55
- this.spans.push(span);
56
- return span;
43
+ // Handle parent context properly
44
+ let ctx = api_1.context.active();
45
+ if (options?.parentContext) {
46
+ // If explicit parent context is provided, use it
47
+ ctx = api_1.trace.setSpanContext(api_1.ROOT_CONTEXT, options.parentContext);
48
+ }
49
+ else if (options?.isRoot) {
50
+ // If explicitly marked as root, use ROOT_CONTEXT
51
+ ctx = api_1.ROOT_CONTEXT;
52
+ }
53
+ // Otherwise, use the active context (default behavior)
54
+ // Start the span with proper context
55
+ const span = tracer.startSpan(name, otelOptions, ctx);
56
+ return new OtelSpan(span);
57
57
  }
58
58
  async flush() {
59
59
  await telemetry_1.blaxelTelemetry.flush();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.16",
3
+ "version": "0.2.17-dev.107",
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.16"
74
+ "@blaxel/core": "0.2.17-dev.107"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",