@blaxel/core 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.
@@ -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,15 +34,22 @@ 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;
39
37
  }
40
38
  /**
41
- * Registry for telemetry providers
39
+ * Registry for managing the global telemetry provider
42
40
  */
43
41
  declare class TelemetryRegistry {
42
+ private static instance;
44
43
  private provider;
44
+ private constructor();
45
+ static getInstance(): TelemetryRegistry;
46
+ /**
47
+ * Register a telemetry provider implementation
48
+ */
45
49
  registerProvider(provider: BlaxelTelemetryProvider): void;
50
+ /**
51
+ * Get the current telemetry provider
52
+ */
46
53
  getProvider(): BlaxelTelemetryProvider;
47
54
  }
48
55
  export declare const telemetryRegistry: TelemetryRegistry;
@@ -51,18 +58,5 @@ export declare const telemetryRegistry: TelemetryRegistry;
51
58
  */
52
59
  export declare function startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
53
60
  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
- */
67
61
  export declare function flush(): Promise<void>;
68
62
  export {};
@@ -4,8 +4,6 @@ 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;
9
7
  exports.flush = flush;
10
8
  /**
11
9
  * No-operation implementation of Span
@@ -16,9 +14,7 @@ class NoopSpan {
16
14
  recordException() { }
17
15
  setStatus() { }
18
16
  end() { }
19
- getContext() {
20
- return null;
21
- }
17
+ getContext() { return null; }
22
18
  }
23
19
  /**
24
20
  * No-operation implementation of TelemetryProvider
@@ -27,25 +23,38 @@ class NoopTelemetryProvider {
27
23
  startSpan() {
28
24
  return new NoopSpan();
29
25
  }
30
- async flush() { }
31
- extractContextFromHeaders() {
32
- return null;
26
+ flush() {
27
+ return Promise.resolve();
33
28
  }
34
29
  }
35
30
  /**
36
- * Registry for telemetry providers
31
+ * Registry for managing the global telemetry provider
37
32
  */
38
33
  class TelemetryRegistry {
34
+ static instance;
39
35
  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
+ */
40
46
  registerProvider(provider) {
41
47
  this.provider = provider;
42
48
  }
49
+ /**
50
+ * Get the current telemetry provider
51
+ */
43
52
  getProvider() {
44
53
  return this.provider;
45
54
  }
46
55
  }
47
- // Global instance
48
- exports.telemetryRegistry = new TelemetryRegistry();
56
+ // Export singleton instance
57
+ exports.telemetryRegistry = TelemetryRegistry.getInstance();
49
58
  // Convenience functions that delegate to the provider
50
59
  /**
51
60
  * Create a span with the registered provider
@@ -66,31 +75,6 @@ async function withSpan(name, fn, options) {
66
75
  throw error;
67
76
  }
68
77
  }
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
- */
94
78
  async function flush() {
95
- return exports.telemetryRegistry.getProvider().flush();
79
+ await exports.telemetryRegistry.getProvider().flush();
96
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.18-dev.157",
3
+ "version": "0.2.18",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",