@blaxel/core 0.2.18-preview.39 → 0.2.19-dev.158
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/client/types.gen.d.ts +25 -7
- package/dist/sandbox/client/types.gen.d.ts +36 -35
- package/dist/sandbox/client/types.gen.js +0 -1
- package/dist/sandbox/index.d.ts +2 -1
- package/dist/sandbox/index.js +1 -0
- package/dist/sandbox/process/process.d.ts +1 -1
- package/dist/sandbox/process/process.js +32 -2
- package/dist/sandbox/sandbox.d.ts +3 -3
- package/dist/sandbox/sandbox.js +55 -6
- package/dist/sandbox/types.d.ts +8 -1
- package/dist/sandbox/types.js +27 -0
- package/dist/telemetry/telemetry.d.ts +17 -11
- package/dist/telemetry/telemetry.js +37 -21
- package/package.json +1 -1
|
@@ -733,7 +733,9 @@ export type JobMetrics = {
|
|
|
733
733
|
/**
|
|
734
734
|
* Job specification
|
|
735
735
|
*/
|
|
736
|
-
export type JobSpec = CoreSpec &
|
|
736
|
+
export type JobSpec = CoreSpec & {
|
|
737
|
+
triggers?: Triggers;
|
|
738
|
+
};
|
|
737
739
|
/**
|
|
738
740
|
* Jobs chart
|
|
739
741
|
*/
|
|
@@ -2439,12 +2441,7 @@ export type TraceIdsResponse = {
|
|
|
2439
2441
|
* Trigger configuration
|
|
2440
2442
|
*/
|
|
2441
2443
|
export type Trigger = {
|
|
2442
|
-
|
|
2443
|
-
* The configuration of the trigger
|
|
2444
|
-
*/
|
|
2445
|
-
configuration?: {
|
|
2446
|
-
[key: string]: unknown;
|
|
2447
|
-
};
|
|
2444
|
+
configuration?: TriggerConfiguration;
|
|
2448
2445
|
/**
|
|
2449
2446
|
* The id of the trigger
|
|
2450
2447
|
*/
|
|
@@ -2454,6 +2451,27 @@ export type Trigger = {
|
|
|
2454
2451
|
*/
|
|
2455
2452
|
type?: string;
|
|
2456
2453
|
};
|
|
2454
|
+
/**
|
|
2455
|
+
* Trigger configuration
|
|
2456
|
+
*/
|
|
2457
|
+
export type TriggerConfiguration = {
|
|
2458
|
+
/**
|
|
2459
|
+
* The authentication type of the trigger
|
|
2460
|
+
*/
|
|
2461
|
+
authenticationType?: string;
|
|
2462
|
+
/**
|
|
2463
|
+
* The path of the trigger
|
|
2464
|
+
*/
|
|
2465
|
+
path?: string;
|
|
2466
|
+
/**
|
|
2467
|
+
* The retry of the trigger
|
|
2468
|
+
*/
|
|
2469
|
+
retry?: number;
|
|
2470
|
+
/**
|
|
2471
|
+
* The schedule of the trigger, cron expression * * * * *
|
|
2472
|
+
*/
|
|
2473
|
+
schedule?: string;
|
|
2474
|
+
};
|
|
2457
2475
|
/**
|
|
2458
2476
|
* Triggers to use your agent
|
|
2459
2477
|
*/
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
export type Directory = {
|
|
2
|
-
files
|
|
3
|
-
name
|
|
4
|
-
path
|
|
2
|
+
files: Array<File>;
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
5
|
/**
|
|
6
6
|
* @name Subdirectories
|
|
7
7
|
*/
|
|
8
|
-
subdirectories
|
|
8
|
+
subdirectories: Array<Subdirectory>;
|
|
9
9
|
};
|
|
10
10
|
export type ErrorResponse = {
|
|
11
|
-
error
|
|
11
|
+
error: string;
|
|
12
12
|
};
|
|
13
13
|
export type File = {
|
|
14
|
-
group
|
|
15
|
-
lastModified
|
|
16
|
-
name
|
|
17
|
-
owner
|
|
18
|
-
path
|
|
19
|
-
permissions
|
|
20
|
-
size
|
|
14
|
+
group: string;
|
|
15
|
+
lastModified: string;
|
|
16
|
+
name: string;
|
|
17
|
+
owner: string;
|
|
18
|
+
path: string;
|
|
19
|
+
permissions: string;
|
|
20
|
+
size: number;
|
|
21
21
|
};
|
|
22
22
|
export type FileRequest = {
|
|
23
23
|
content?: string;
|
|
@@ -25,14 +25,14 @@ export type FileRequest = {
|
|
|
25
25
|
permissions?: string;
|
|
26
26
|
};
|
|
27
27
|
export type FileWithContent = {
|
|
28
|
-
content
|
|
29
|
-
group
|
|
30
|
-
lastModified
|
|
31
|
-
name
|
|
32
|
-
owner
|
|
33
|
-
path
|
|
34
|
-
permissions
|
|
35
|
-
size
|
|
28
|
+
content: string;
|
|
29
|
+
group: string;
|
|
30
|
+
lastModified: string;
|
|
31
|
+
name: string;
|
|
32
|
+
owner: string;
|
|
33
|
+
path: string;
|
|
34
|
+
permissions: string;
|
|
35
|
+
size: number;
|
|
36
36
|
};
|
|
37
37
|
export type PortMonitorRequest = {
|
|
38
38
|
/**
|
|
@@ -41,9 +41,9 @@ export type PortMonitorRequest = {
|
|
|
41
41
|
callback?: string;
|
|
42
42
|
};
|
|
43
43
|
export type ProcessLogs = {
|
|
44
|
-
logs
|
|
45
|
-
stderr
|
|
46
|
-
stdout
|
|
44
|
+
logs: string;
|
|
45
|
+
stderr: string;
|
|
46
|
+
stdout: string;
|
|
47
47
|
};
|
|
48
48
|
export type ProcessRequest = {
|
|
49
49
|
command: string;
|
|
@@ -57,22 +57,23 @@ export type ProcessRequest = {
|
|
|
57
57
|
workingDir?: string;
|
|
58
58
|
};
|
|
59
59
|
export type ProcessResponse = {
|
|
60
|
-
command
|
|
61
|
-
completedAt
|
|
62
|
-
exitCode
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
command: string;
|
|
61
|
+
completedAt: string;
|
|
62
|
+
exitCode: number;
|
|
63
|
+
logs: string;
|
|
64
|
+
name: string;
|
|
65
|
+
pid: string;
|
|
66
|
+
startedAt: string;
|
|
67
|
+
status: 'failed' | 'killed' | 'stopped' | 'running' | 'completed';
|
|
68
|
+
workingDir: string;
|
|
68
69
|
};
|
|
69
70
|
export type Subdirectory = {
|
|
70
|
-
name
|
|
71
|
-
path
|
|
71
|
+
name: string;
|
|
72
|
+
path: string;
|
|
72
73
|
};
|
|
73
74
|
export type SuccessResponse = {
|
|
74
|
-
message
|
|
75
|
-
path
|
|
75
|
+
message: string;
|
|
76
|
+
path: string;
|
|
76
77
|
};
|
|
77
78
|
export type DeleteFilesystemByPathData = {
|
|
78
79
|
body?: never;
|
package/dist/sandbox/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Directory, ErrorResponse, File, FileRequest, FileWithContent, PortMonitorRequest, ProcessRequest, ProcessResponse, SuccessResponse, deleteFilesystemByPath, deleteNetworkProcessByPidMonitor, deleteProcessByIdentifier, deleteProcessByIdentifierKill, getFilesystemByPath, getNetworkProcessByPidPorts, getProcess, getProcessByIdentifier, getProcessByIdentifierLogs, getProcessByIdentifierLogsStream, postNetworkProcessByPidMonitor, postProcess, putFilesystemByPath } from "./client/index.js";
|
|
2
2
|
export * from "./filesystem/index.js";
|
|
3
3
|
export * from "./sandbox.js";
|
|
4
|
+
export * from "./types.js";
|
package/dist/sandbox/index.js
CHANGED
|
@@ -32,4 +32,5 @@ Object.defineProperty(exports, "postProcess", { enumerable: true, get: function
|
|
|
32
32
|
Object.defineProperty(exports, "putFilesystemByPath", { enumerable: true, get: function () { return index_js_1.putFilesystemByPath; } });
|
|
33
33
|
__exportStar(require("./filesystem/index.js"), exports);
|
|
34
34
|
__exportStar(require("./sandbox.js"), exports);
|
|
35
|
+
__exportStar(require("./types.js"), exports);
|
|
35
36
|
// Re-export everything from client except ClientOptions to avoid conflict
|
|
@@ -10,7 +10,7 @@ export declare class SandboxProcess extends SandboxAction {
|
|
|
10
10
|
}): {
|
|
11
11
|
close: () => void;
|
|
12
12
|
};
|
|
13
|
-
exec(process: ProcessRequest): Promise<PostProcessResponse>;
|
|
13
|
+
exec(process: ProcessRequest, onLog?: (log: string) => void): Promise<PostProcessResponse>;
|
|
14
14
|
wait(identifier: string, { maxWait, interval }?: {
|
|
15
15
|
maxWait?: number;
|
|
16
16
|
interval?: number;
|
|
@@ -61,14 +61,44 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
61
61
|
close: () => controller.abort(),
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
async exec(process) {
|
|
64
|
+
async exec(process, onLog) {
|
|
65
|
+
// Store original wait_for_completion setting
|
|
66
|
+
const shouldWaitForCompletion = process.waitForCompletion;
|
|
67
|
+
// Always start process without wait_for_completion to avoid server-side blocking
|
|
68
|
+
if (shouldWaitForCompletion && onLog) {
|
|
69
|
+
process.waitForCompletion = false;
|
|
70
|
+
}
|
|
65
71
|
const { response, data, error } = await (0, index_js_1.postProcess)({
|
|
66
72
|
body: process,
|
|
67
73
|
baseUrl: this.url,
|
|
68
74
|
client: this.client,
|
|
69
75
|
});
|
|
70
76
|
this.handleResponseError(response, data, error);
|
|
71
|
-
|
|
77
|
+
let result = data;
|
|
78
|
+
// Handle wait_for_completion with parallel log streaming
|
|
79
|
+
if (shouldWaitForCompletion) {
|
|
80
|
+
let streamControl;
|
|
81
|
+
if (onLog) {
|
|
82
|
+
streamControl = this.streamLogs(result.pid, { onLog });
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
// Wait for process completion
|
|
86
|
+
result = await this.wait(result.pid, { interval: 50 });
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
// Clean up log streaming
|
|
90
|
+
if (streamControl) {
|
|
91
|
+
streamControl.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// For non-blocking execution, set up log streaming immediately if requested
|
|
97
|
+
if (onLog) {
|
|
98
|
+
this.streamLogs(result.pid, { onLog });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
72
102
|
}
|
|
73
103
|
async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
|
|
74
104
|
const startTime = Date.now();
|
|
@@ -4,7 +4,7 @@ import { SandboxNetwork } from "./network/index.js";
|
|
|
4
4
|
import { SandboxPreviews } from "./preview.js";
|
|
5
5
|
import { SandboxProcess } from "./process/index.js";
|
|
6
6
|
import { SandboxSessions } from "./session.js";
|
|
7
|
-
import { SandboxConfiguration, SessionWithToken } from "./types.js";
|
|
7
|
+
import { SandboxConfiguration, SandboxCreateConfiguration, SessionWithToken } from "./types.js";
|
|
8
8
|
export declare class SandboxInstance {
|
|
9
9
|
private sandbox;
|
|
10
10
|
fs: SandboxFileSystem;
|
|
@@ -21,10 +21,10 @@ export declare class SandboxInstance {
|
|
|
21
21
|
maxWait?: number;
|
|
22
22
|
interval?: number;
|
|
23
23
|
}): Promise<void>;
|
|
24
|
-
static create(sandbox
|
|
24
|
+
static create(sandbox?: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
|
|
25
25
|
static get(sandboxName: string): Promise<SandboxInstance>;
|
|
26
26
|
static list(): Promise<SandboxInstance[]>;
|
|
27
27
|
static delete(sandboxName: string): Promise<SandboxModel>;
|
|
28
|
-
static createIfNotExists(sandbox: SandboxModel): Promise<SandboxInstance>;
|
|
28
|
+
static createIfNotExists(sandbox: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
|
|
29
29
|
static fromSession(session: SessionWithToken): Promise<SandboxInstance>;
|
|
30
30
|
}
|
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SandboxInstance = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const index_js_1 = require("../client/index.js");
|
|
5
6
|
const logger_js_1 = require("../common/logger.js");
|
|
6
7
|
const index_js_2 = require("./filesystem/index.js");
|
|
@@ -8,6 +9,7 @@ const index_js_3 = require("./network/index.js");
|
|
|
8
9
|
const preview_js_1 = require("./preview.js");
|
|
9
10
|
const index_js_4 = require("./process/index.js");
|
|
10
11
|
const session_js_1 = require("./session.js");
|
|
12
|
+
const types_js_1 = require("./types.js");
|
|
11
13
|
class SandboxInstance {
|
|
12
14
|
sandbox;
|
|
13
15
|
fs;
|
|
@@ -61,11 +63,45 @@ class SandboxInstance {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
static async create(sandbox) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
|
|
67
|
+
const defaultImage = "blaxel/prod-base:latest";
|
|
68
|
+
const defaultMemory = 4096;
|
|
69
|
+
// Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports keys
|
|
70
|
+
if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox || 'ports' in sandbox) {
|
|
71
|
+
if (!sandbox)
|
|
72
|
+
sandbox = {};
|
|
73
|
+
if (!sandbox.name)
|
|
74
|
+
sandbox.name = defaultName;
|
|
75
|
+
if (!sandbox.image)
|
|
76
|
+
sandbox.image = defaultImage;
|
|
77
|
+
if (!sandbox.memory)
|
|
78
|
+
sandbox.memory = defaultMemory;
|
|
79
|
+
const ports = (0, types_js_1.normalizePorts)(sandbox.ports);
|
|
80
|
+
sandbox = {
|
|
81
|
+
metadata: { name: sandbox.name },
|
|
82
|
+
spec: {
|
|
83
|
+
runtime: {
|
|
84
|
+
image: sandbox.image,
|
|
85
|
+
memory: sandbox.memory,
|
|
86
|
+
ports: ports,
|
|
87
|
+
generation: "mk3"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
68
91
|
}
|
|
92
|
+
sandbox = sandbox;
|
|
93
|
+
if (!sandbox.metadata) {
|
|
94
|
+
sandbox.metadata = { name: crypto.randomUUID().replace(/-/g, '') };
|
|
95
|
+
}
|
|
96
|
+
if (!sandbox.spec) {
|
|
97
|
+
sandbox.spec = { runtime: { image: "blaxel/prod-base:latest" } };
|
|
98
|
+
}
|
|
99
|
+
if (!sandbox.spec.runtime) {
|
|
100
|
+
sandbox.spec.runtime = { image: defaultImage, memory: defaultMemory };
|
|
101
|
+
}
|
|
102
|
+
sandbox.spec.runtime.image = sandbox.spec.runtime.image || defaultImage;
|
|
103
|
+
sandbox.spec.runtime.memory = sandbox.spec.runtime.memory || defaultMemory;
|
|
104
|
+
sandbox.spec.runtime.generation = sandbox.spec.runtime.generation || "mk3";
|
|
69
105
|
const { data } = await (0, index_js_1.createSandbox)({
|
|
70
106
|
body: sandbox,
|
|
71
107
|
throwOnError: true,
|
|
@@ -96,7 +132,11 @@ class SandboxInstance {
|
|
|
96
132
|
}
|
|
97
133
|
static async createIfNotExists(sandbox) {
|
|
98
134
|
try {
|
|
99
|
-
const
|
|
135
|
+
const name = 'name' in sandbox ? sandbox.name : sandbox.metadata?.name;
|
|
136
|
+
if (!name) {
|
|
137
|
+
throw new Error("Sandbox name is required");
|
|
138
|
+
}
|
|
139
|
+
const sandboxInstance = await SandboxInstance.get(name);
|
|
100
140
|
return sandboxInstance;
|
|
101
141
|
}
|
|
102
142
|
catch (e) {
|
|
@@ -108,7 +148,16 @@ class SandboxInstance {
|
|
|
108
148
|
}
|
|
109
149
|
/* eslint-disable */
|
|
110
150
|
static async fromSession(session) {
|
|
111
|
-
|
|
151
|
+
// Create a minimal sandbox configuration for session-based access
|
|
152
|
+
const sandboxName = session.name.includes("-") ? session.name.split("-")[0] : session.name;
|
|
153
|
+
const sandbox = {
|
|
154
|
+
metadata: { name: sandboxName },
|
|
155
|
+
forceUrl: session.url,
|
|
156
|
+
headers: { "X-Blaxel-Preview-Token": session.token },
|
|
157
|
+
params: { bl_preview_token: session.token }
|
|
158
|
+
};
|
|
159
|
+
// Create instance using constructor instead of direct property assignment
|
|
160
|
+
return new SandboxInstance(sandbox);
|
|
112
161
|
}
|
|
113
162
|
}
|
|
114
163
|
exports.SandboxInstance = SandboxInstance;
|
package/dist/sandbox/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Sandbox } from "../client/types.gen";
|
|
1
|
+
import { Port, Sandbox } from "../client/types.gen";
|
|
2
2
|
export interface SessionCreateOptions {
|
|
3
3
|
expiresAt?: Date;
|
|
4
4
|
responseHeaders?: Record<string, string>;
|
|
@@ -15,3 +15,10 @@ export type SandboxConfiguration = {
|
|
|
15
15
|
headers?: Record<string, string>;
|
|
16
16
|
params?: Record<string, string>;
|
|
17
17
|
} & Sandbox;
|
|
18
|
+
export type SandboxCreateConfiguration = {
|
|
19
|
+
name?: string;
|
|
20
|
+
image?: string;
|
|
21
|
+
memory?: number;
|
|
22
|
+
ports?: (Port | Record<string, any>)[];
|
|
23
|
+
};
|
|
24
|
+
export declare function normalizePorts(ports?: (Port | Record<string, any>)[]): Port[] | undefined;
|
package/dist/sandbox/types.js
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePorts = normalizePorts;
|
|
4
|
+
function normalizePorts(ports) {
|
|
5
|
+
if (!ports || ports.length === 0) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const portObjects = [];
|
|
9
|
+
for (const port of ports) {
|
|
10
|
+
if (typeof port === 'object' && port !== null) {
|
|
11
|
+
if ('name' in port || 'target' in port || 'protocol' in port) {
|
|
12
|
+
// It's a Port-like object, ensure protocol defaults to HTTP
|
|
13
|
+
const normalizedPort = {
|
|
14
|
+
name: typeof port.name === 'string' ? port.name : undefined,
|
|
15
|
+
target: typeof port.target === 'number' ? port.target : undefined,
|
|
16
|
+
protocol: typeof port.protocol === 'string' ? port.protocol : "HTTP"
|
|
17
|
+
};
|
|
18
|
+
portObjects.push(normalizedPort);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
throw new Error(`Invalid port type: ${typeof port}. Expected Port object or object with port properties.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error(`Invalid port type: ${typeof port}. Expected Port object or object with port properties.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return portObjects;
|
|
29
|
+
}
|
|
@@ -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:
|
|
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
|
|
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() {
|
|
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
|
-
|
|
30
|
+
async flush() { }
|
|
31
|
+
extractContextFromHeaders() {
|
|
32
|
+
return null;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
|
-
* Registry for
|
|
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
|
-
//
|
|
57
|
-
exports.telemetryRegistry = TelemetryRegistry
|
|
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
|
-
|
|
95
|
+
return exports.telemetryRegistry.getProvider().flush();
|
|
80
96
|
}
|