@blaxel/core 0.2.18-dev.142 → 0.2.18-dev.145

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.
@@ -20,7 +20,7 @@ export interface BlaxelSpan {
20
20
  /** Record an error on the span */
21
21
  recordException(error: Error): void;
22
22
  /** Set the status of the span */
23
- setStatus(status: 'ok' | 'error', message?: string): void;
23
+ setStatus(status: "ok" | "error", message?: string): void;
24
24
  /** End the span */
25
25
  end(): void;
26
26
  /** Get the span context (for passing to child spans) */
@@ -34,22 +34,15 @@ export interface BlaxelTelemetryProvider {
34
34
  startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
35
35
  /** Flush the telemetry provider */
36
36
  flush(): Promise<void>;
37
+ /** Extract context from headers for manual context propagation */
38
+ extractContextFromHeaders?(headers: Record<string, string | string[]>): unknown;
37
39
  }
38
40
  /**
39
- * Registry for managing the global telemetry provider
41
+ * Registry for telemetry providers
40
42
  */
41
43
  declare class TelemetryRegistry {
42
- private static instance;
43
44
  private provider;
44
- private constructor();
45
- static getInstance(): TelemetryRegistry;
46
- /**
47
- * Register a telemetry provider implementation
48
- */
49
45
  registerProvider(provider: BlaxelTelemetryProvider): void;
50
- /**
51
- * Get the current telemetry provider
52
- */
53
46
  getProvider(): BlaxelTelemetryProvider;
54
47
  }
55
48
  export declare const telemetryRegistry: TelemetryRegistry;
@@ -58,5 +51,18 @@ export declare const telemetryRegistry: TelemetryRegistry;
58
51
  */
59
52
  export declare function startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
60
53
  export declare function withSpan<T>(name: string, fn: () => Promise<T>, options?: BlaxelSpanOptions): Promise<T>;
54
+ /**
55
+ * Extract context from headers - useful for manual context propagation
56
+ * when you have traceparent headers but no active span
57
+ */
58
+ export declare function extractContextFromHeaders(headers: Record<string, string | string[]>): unknown;
59
+ /**
60
+ * Create a span with extracted context from headers
61
+ * This is useful when you need to manually establish trace context
62
+ */
63
+ export declare function startSpanWithHeaders(name: string, headers: Record<string, string | string[]>, options?: Omit<BlaxelSpanOptions, "parentContext">): BlaxelSpan;
64
+ /**
65
+ * Flush the telemetry provider
66
+ */
61
67
  export declare function flush(): Promise<void>;
62
68
  export {};
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.telemetryRegistry = void 0;
5
5
  exports.startSpan = startSpan;
6
6
  exports.withSpan = withSpan;
7
+ exports.extractContextFromHeaders = extractContextFromHeaders;
8
+ exports.startSpanWithHeaders = startSpanWithHeaders;
7
9
  exports.flush = flush;
8
10
  /**
9
11
  * No-operation implementation of Span
@@ -14,7 +16,9 @@ class NoopSpan {
14
16
  recordException() { }
15
17
  setStatus() { }
16
18
  end() { }
17
- getContext() { return null; }
19
+ getContext() {
20
+ return null;
21
+ }
18
22
  }
19
23
  /**
20
24
  * No-operation implementation of TelemetryProvider
@@ -23,38 +27,25 @@ class NoopTelemetryProvider {
23
27
  startSpan() {
24
28
  return new NoopSpan();
25
29
  }
26
- flush() {
27
- return Promise.resolve();
30
+ async flush() { }
31
+ extractContextFromHeaders() {
32
+ return null;
28
33
  }
29
34
  }
30
35
  /**
31
- * Registry for managing the global telemetry provider
36
+ * Registry for telemetry providers
32
37
  */
33
38
  class TelemetryRegistry {
34
- static instance;
35
39
  provider = new NoopTelemetryProvider();
36
- constructor() { }
37
- static getInstance() {
38
- if (!TelemetryRegistry.instance) {
39
- TelemetryRegistry.instance = new TelemetryRegistry();
40
- }
41
- return TelemetryRegistry.instance;
42
- }
43
- /**
44
- * Register a telemetry provider implementation
45
- */
46
40
  registerProvider(provider) {
47
41
  this.provider = provider;
48
42
  }
49
- /**
50
- * Get the current telemetry provider
51
- */
52
43
  getProvider() {
53
44
  return this.provider;
54
45
  }
55
46
  }
56
- // Export singleton instance
57
- exports.telemetryRegistry = TelemetryRegistry.getInstance();
47
+ // Global instance
48
+ exports.telemetryRegistry = new TelemetryRegistry();
58
49
  // Convenience functions that delegate to the provider
59
50
  /**
60
51
  * Create a span with the registered provider
@@ -75,6 +66,31 @@ async function withSpan(name, fn, options) {
75
66
  throw error;
76
67
  }
77
68
  }
69
+ /**
70
+ * Extract context from headers - useful for manual context propagation
71
+ * when you have traceparent headers but no active span
72
+ */
73
+ function extractContextFromHeaders(headers) {
74
+ const provider = exports.telemetryRegistry.getProvider();
75
+ if (provider.extractContextFromHeaders) {
76
+ return provider.extractContextFromHeaders(headers);
77
+ }
78
+ return null;
79
+ }
80
+ /**
81
+ * Create a span with extracted context from headers
82
+ * This is useful when you need to manually establish trace context
83
+ */
84
+ function startSpanWithHeaders(name, headers, options) {
85
+ const extractedContext = extractContextFromHeaders(headers);
86
+ return startSpan(name, {
87
+ ...options,
88
+ parentContext: extractedContext || undefined,
89
+ });
90
+ }
91
+ /**
92
+ * Flush the telemetry provider
93
+ */
78
94
  async function flush() {
79
- await exports.telemetryRegistry.getProvider().flush();
95
+ return exports.telemetryRegistry.getProvider().flush();
80
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.18-dev.142",
3
+ "version": "0.2.18-dev.145",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",