@blaxel/telemetry 0.2.17 → 0.2.18-dev.136

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
  }
@@ -21,7 +21,7 @@ class OtelSpan {
21
21
  }
22
22
  setStatus(status, message) {
23
23
  this.span.setStatus({
24
- code: status === 'ok' ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
24
+ code: status === "ok" ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
25
25
  message,
26
26
  });
27
27
  }
@@ -34,25 +34,39 @@ class OtelSpan {
34
34
  }
35
35
  }
36
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
- }
47
37
  startSpan(name, options) {
48
38
  const tracer = api_1.trace.getTracer("blaxel");
39
+ // Get the current active context - this will include any traceparent propagation
40
+ const activeContext = api_1.context.active();
41
+ const activeSpan = api_1.trace.getActiveSpan();
42
+ // Debug logging to help understand context propagation
43
+ console.log("=== CREATING NEW SPAN ===");
44
+ console.log("Span name:", name);
45
+ console.log("Active context span:", activeSpan
46
+ ? {
47
+ traceId: activeSpan.spanContext().traceId,
48
+ spanId: activeSpan.spanContext().spanId,
49
+ traceFlags: activeSpan.spanContext().traceFlags,
50
+ }
51
+ : "null");
52
+ // Check if there's a span context in the active context (from traceparent headers)
53
+ const spanContext = api_1.trace.getSpanContext(activeContext);
54
+ if (spanContext) {
55
+ console.log("Span context from active context:", {
56
+ traceId: spanContext.traceId,
57
+ spanId: spanContext.spanId,
58
+ traceFlags: spanContext.traceFlags,
59
+ });
60
+ }
49
61
  const otelOptions = {
50
62
  attributes: options?.attributes,
51
63
  root: options?.isRoot,
52
64
  };
53
- const ctx = this.retrieveActiveSpanContext();
54
- const span = new OtelSpan(tracer.startSpan(name, otelOptions, ctx));
55
- this.spans.push(span);
65
+ // Use the active context unless explicitly requesting a root span
66
+ const contextToUse = options?.isRoot ? api_1.ROOT_CONTEXT : activeContext;
67
+ const span = new OtelSpan(tracer.startSpan(name, otelOptions, contextToUse));
68
+ console.log("Created span context:", span.getContext());
69
+ console.log("=== END CREATING NEW SPAN ===");
56
70
  return span;
57
71
  }
58
72
  async flush() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.17",
3
+ "version": "0.2.18-dev.136",
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.17"
74
+ "@blaxel/core": "0.2.18-dev.136"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",