@blaxel/core 0.2.18-dev.145 → 0.2.18-dev.146
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/telemetry.d.ts +10 -16
- package/dist/telemetry/telemetry.js +20 -34
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
@@ -27,25 +25,38 @@ class NoopTelemetryProvider {
|
|
|
27
25
|
startSpan() {
|
|
28
26
|
return new NoopSpan();
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return null;
|
|
28
|
+
flush() {
|
|
29
|
+
return Promise.resolve();
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
36
|
-
* Registry for telemetry
|
|
33
|
+
* Registry for managing the global telemetry provider
|
|
37
34
|
*/
|
|
38
35
|
class TelemetryRegistry {
|
|
36
|
+
static instance;
|
|
39
37
|
provider = new NoopTelemetryProvider();
|
|
38
|
+
constructor() { }
|
|
39
|
+
static getInstance() {
|
|
40
|
+
if (!TelemetryRegistry.instance) {
|
|
41
|
+
TelemetryRegistry.instance = new TelemetryRegistry();
|
|
42
|
+
}
|
|
43
|
+
return TelemetryRegistry.instance;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register a telemetry provider implementation
|
|
47
|
+
*/
|
|
40
48
|
registerProvider(provider) {
|
|
41
49
|
this.provider = provider;
|
|
42
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the current telemetry provider
|
|
53
|
+
*/
|
|
43
54
|
getProvider() {
|
|
44
55
|
return this.provider;
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
|
-
//
|
|
48
|
-
exports.telemetryRegistry =
|
|
58
|
+
// Export singleton instance
|
|
59
|
+
exports.telemetryRegistry = TelemetryRegistry.getInstance();
|
|
49
60
|
// Convenience functions that delegate to the provider
|
|
50
61
|
/**
|
|
51
62
|
* Create a span with the registered provider
|
|
@@ -66,31 +77,6 @@ async function withSpan(name, fn, options) {
|
|
|
66
77
|
throw error;
|
|
67
78
|
}
|
|
68
79
|
}
|
|
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
80
|
async function flush() {
|
|
95
|
-
|
|
81
|
+
await exports.telemetryRegistry.getProvider().flush();
|
|
96
82
|
}
|