@blaxel/telemetry 0.2.18-dev.157 → 0.2.18

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/dist/telemetry.js CHANGED
@@ -195,7 +195,6 @@ class TelemetryManager {
195
195
  core_1.telemetryRegistry.registerProvider(new telemetry_provider_1.OtelTelemetryProvider());
196
196
  const httpInstrumentation = new instrumentation_http_1.HttpInstrumentation({
197
197
  requireParentforOutgoingSpans: true,
198
- requireParentforIncomingSpans: true,
199
198
  });
200
199
  (0, instrumentation_1.registerInstrumentations)({
201
200
  instrumentations: [httpInstrumentation],
@@ -1,5 +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;
4
6
  flush(): Promise<void>;
5
7
  }
@@ -5,6 +5,7 @@ const api_1 = require("@opentelemetry/api");
5
5
  const telemetry_1 = require("./telemetry");
6
6
  class OtelSpan {
7
7
  span;
8
+ closed = false;
8
9
  constructor(span) {
9
10
  this.span = span;
10
11
  }
@@ -20,11 +21,12 @@ class OtelSpan {
20
21
  }
21
22
  setStatus(status, message) {
22
23
  this.span.setStatus({
23
- code: status === "ok" ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
24
+ code: status === 'ok' ? api_1.SpanStatusCode.OK : api_1.SpanStatusCode.ERROR,
24
25
  message,
25
26
  });
26
27
  }
27
28
  end() {
29
+ this.closed = true;
28
30
  this.span.end();
29
31
  }
30
32
  getContext() {
@@ -32,22 +34,26 @@ class OtelSpan {
32
34
  }
33
35
  }
34
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
+ }
35
47
  startSpan(name, options) {
36
- // Use the tracer from the registered NodeTracerProvider
37
48
  const tracer = api_1.trace.getTracer("blaxel");
38
- // Prepare OpenTelemetry span options
39
49
  const otelOptions = {
40
50
  attributes: options?.attributes,
41
51
  root: options?.isRoot,
42
52
  };
43
- // Handle parent context if provided
44
- let ctx = api_1.context.active();
45
- if (options?.parentContext) {
46
- ctx = options.parentContext;
47
- }
48
- // Start the span
49
- const span = tracer.startSpan(name, otelOptions, ctx);
50
- return new OtelSpan(span);
53
+ const ctx = this.retrieveActiveSpanContext();
54
+ const span = new OtelSpan(tracer.startSpan(name, otelOptions, ctx));
55
+ this.spans.push(span);
56
+ return span;
51
57
  }
52
58
  async flush() {
53
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.18-dev.157",
3
+ "version": "0.2.18",
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.18-dev.157"
74
+ "@blaxel/core": "0.2.18"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",