@prefactor/core 0.2.5 → 0.2.7
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/README.md +1 -1
- package/dist/config.d.ts +10 -156
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/index.cjs +80 -26
- package/dist/index.cjs.map +10 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -26
- package/dist/index.js.map +10 -9
- package/dist/queue/actions.d.ts +2 -2
- package/dist/queue/actions.d.ts.map +1 -1
- package/dist/tracing/result-payload.d.ts +3 -0
- package/dist/tracing/result-payload.d.ts.map +1 -0
- package/dist/tracing/result-payload.js +11 -0
- package/dist/tracing/result-payload.js.map +1 -0
- package/dist/tracing/span.d.ts +1 -0
- package/dist/tracing/span.d.ts.map +1 -1
- package/dist/tracing/span.js +3 -0
- package/dist/tracing/span.js.map +1 -1
- package/dist/tracing/tracer.d.ts.map +1 -1
- package/dist/tracing/tracer.js +6 -1
- package/dist/tracing/tracer.js.map +1 -1
- package/dist/tracing/with-span.js +18 -2
- package/dist/tracing/with-span.js.map +1 -1
- package/dist/transport/http/agent-span-client.d.ts +7 -1
- package/dist/transport/http/agent-span-client.d.ts.map +1 -1
- package/dist/transport/http/agent-span-client.js +5 -2
- package/dist/transport/http/agent-span-client.js.map +1 -1
- package/dist/transport/http.d.ts +7 -2
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +34 -18
- package/dist/transport/http.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -3,61 +3,20 @@ import { z } from 'zod';
|
|
|
3
3
|
* Configuration schema for HTTP transport
|
|
4
4
|
*/
|
|
5
5
|
export declare const HttpTransportConfigSchema: z.ZodObject<{
|
|
6
|
-
/** API endpoint URL */
|
|
7
6
|
apiUrl: z.ZodString;
|
|
8
|
-
/** Authentication token */
|
|
9
7
|
apiToken: z.ZodString;
|
|
10
|
-
/** Optional agent instance identifier (internal ID) */
|
|
11
8
|
agentId: z.ZodOptional<z.ZodString>;
|
|
12
|
-
/** Agent identifier (external identifier); defaults to v1.0.0 when omitted */
|
|
13
9
|
agentIdentifier: z.ZodDefault<z.ZodString>;
|
|
14
|
-
/** Optional agent name */
|
|
15
10
|
agentName: z.ZodOptional<z.ZodString>;
|
|
16
|
-
/** Optional agent description */
|
|
17
11
|
agentDescription: z.ZodOptional<z.ZodString>;
|
|
18
|
-
/** Optional agent schema for validation (full schema object) */
|
|
19
12
|
agentSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
|
-
/** Request timeout in milliseconds */
|
|
21
13
|
requestTimeout: z.ZodDefault<z.ZodNumber>;
|
|
22
|
-
/** Maximum number of retry attempts */
|
|
23
14
|
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
24
|
-
/** Initial delay between retries in milliseconds */
|
|
25
15
|
initialRetryDelay: z.ZodDefault<z.ZodNumber>;
|
|
26
|
-
/** Maximum delay between retries in milliseconds */
|
|
27
16
|
maxRetryDelay: z.ZodDefault<z.ZodNumber>;
|
|
28
|
-
/** Multiplier for exponential backoff */
|
|
29
17
|
retryMultiplier: z.ZodDefault<z.ZodNumber>;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
apiUrl: string;
|
|
34
|
-
apiToken: string;
|
|
35
|
-
agentIdentifier: string;
|
|
36
|
-
requestTimeout: number;
|
|
37
|
-
maxRetries: number;
|
|
38
|
-
initialRetryDelay: number;
|
|
39
|
-
maxRetryDelay: number;
|
|
40
|
-
retryMultiplier: number;
|
|
41
|
-
retryOnStatusCodes: number[];
|
|
42
|
-
agentId?: string | undefined;
|
|
43
|
-
agentName?: string | undefined;
|
|
44
|
-
agentDescription?: string | undefined;
|
|
45
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
46
|
-
}, {
|
|
47
|
-
apiUrl: string;
|
|
48
|
-
apiToken: string;
|
|
49
|
-
agentId?: string | undefined;
|
|
50
|
-
agentIdentifier?: string | undefined;
|
|
51
|
-
agentName?: string | undefined;
|
|
52
|
-
agentDescription?: string | undefined;
|
|
53
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
54
|
-
requestTimeout?: number | undefined;
|
|
55
|
-
maxRetries?: number | undefined;
|
|
56
|
-
initialRetryDelay?: number | undefined;
|
|
57
|
-
maxRetryDelay?: number | undefined;
|
|
58
|
-
retryMultiplier?: number | undefined;
|
|
59
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
60
|
-
}>;
|
|
18
|
+
retryOnStatusCodes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
61
20
|
export type HttpTransportConfig = z.infer<typeof HttpTransportConfigSchema>;
|
|
62
21
|
/**
|
|
63
22
|
* Partial HTTP config schema for user input (before defaults are applied)
|
|
@@ -75,54 +34,21 @@ export declare const PartialHttpConfigSchema: z.ZodObject<{
|
|
|
75
34
|
initialRetryDelay: z.ZodOptional<z.ZodNumber>;
|
|
76
35
|
maxRetryDelay: z.ZodOptional<z.ZodNumber>;
|
|
77
36
|
retryMultiplier: z.ZodOptional<z.ZodNumber>;
|
|
78
|
-
retryOnStatusCodes: z.ZodOptional<z.ZodArray<z.ZodNumber
|
|
79
|
-
},
|
|
80
|
-
apiUrl: string;
|
|
81
|
-
apiToken: string;
|
|
82
|
-
agentId?: string | undefined;
|
|
83
|
-
agentIdentifier?: string | undefined;
|
|
84
|
-
agentName?: string | undefined;
|
|
85
|
-
agentDescription?: string | undefined;
|
|
86
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
87
|
-
requestTimeout?: number | undefined;
|
|
88
|
-
maxRetries?: number | undefined;
|
|
89
|
-
initialRetryDelay?: number | undefined;
|
|
90
|
-
maxRetryDelay?: number | undefined;
|
|
91
|
-
retryMultiplier?: number | undefined;
|
|
92
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
93
|
-
}, {
|
|
94
|
-
apiUrl: string;
|
|
95
|
-
apiToken: string;
|
|
96
|
-
agentId?: string | undefined;
|
|
97
|
-
agentIdentifier?: string | undefined;
|
|
98
|
-
agentName?: string | undefined;
|
|
99
|
-
agentDescription?: string | undefined;
|
|
100
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
101
|
-
requestTimeout?: number | undefined;
|
|
102
|
-
maxRetries?: number | undefined;
|
|
103
|
-
initialRetryDelay?: number | undefined;
|
|
104
|
-
maxRetryDelay?: number | undefined;
|
|
105
|
-
retryMultiplier?: number | undefined;
|
|
106
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
107
|
-
}>;
|
|
37
|
+
retryOnStatusCodes: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
38
|
+
}, z.core.$strip>;
|
|
108
39
|
export type PartialHttpConfig = z.infer<typeof PartialHttpConfigSchema>;
|
|
109
40
|
/**
|
|
110
41
|
* Main SDK configuration schema
|
|
111
42
|
*/
|
|
112
43
|
export declare const ConfigSchema: z.ZodObject<{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
44
|
+
transportType: z.ZodDefault<z.ZodEnum<{
|
|
45
|
+
http: "http";
|
|
46
|
+
}>>;
|
|
116
47
|
sampleRate: z.ZodDefault<z.ZodNumber>;
|
|
117
|
-
/** Whether to capture span inputs */
|
|
118
48
|
captureInputs: z.ZodDefault<z.ZodBoolean>;
|
|
119
|
-
/** Whether to capture span outputs */
|
|
120
49
|
captureOutputs: z.ZodDefault<z.ZodBoolean>;
|
|
121
|
-
/** Maximum length for input strings */
|
|
122
50
|
maxInputLength: z.ZodDefault<z.ZodNumber>;
|
|
123
|
-
/** Maximum length for output strings */
|
|
124
51
|
maxOutputLength: z.ZodDefault<z.ZodNumber>;
|
|
125
|
-
/** HTTP transport configuration (required if transportType is 'http') */
|
|
126
52
|
httpConfig: z.ZodOptional<z.ZodObject<{
|
|
127
53
|
apiUrl: z.ZodString;
|
|
128
54
|
apiToken: z.ZodString;
|
|
@@ -136,81 +62,9 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
136
62
|
initialRetryDelay: z.ZodOptional<z.ZodNumber>;
|
|
137
63
|
maxRetryDelay: z.ZodOptional<z.ZodNumber>;
|
|
138
64
|
retryMultiplier: z.ZodOptional<z.ZodNumber>;
|
|
139
|
-
retryOnStatusCodes: z.ZodOptional<z.ZodArray<z.ZodNumber
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
apiToken: string;
|
|
143
|
-
agentId?: string | undefined;
|
|
144
|
-
agentIdentifier?: string | undefined;
|
|
145
|
-
agentName?: string | undefined;
|
|
146
|
-
agentDescription?: string | undefined;
|
|
147
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
148
|
-
requestTimeout?: number | undefined;
|
|
149
|
-
maxRetries?: number | undefined;
|
|
150
|
-
initialRetryDelay?: number | undefined;
|
|
151
|
-
maxRetryDelay?: number | undefined;
|
|
152
|
-
retryMultiplier?: number | undefined;
|
|
153
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
154
|
-
}, {
|
|
155
|
-
apiUrl: string;
|
|
156
|
-
apiToken: string;
|
|
157
|
-
agentId?: string | undefined;
|
|
158
|
-
agentIdentifier?: string | undefined;
|
|
159
|
-
agentName?: string | undefined;
|
|
160
|
-
agentDescription?: string | undefined;
|
|
161
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
162
|
-
requestTimeout?: number | undefined;
|
|
163
|
-
maxRetries?: number | undefined;
|
|
164
|
-
initialRetryDelay?: number | undefined;
|
|
165
|
-
maxRetryDelay?: number | undefined;
|
|
166
|
-
retryMultiplier?: number | undefined;
|
|
167
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
168
|
-
}>>;
|
|
169
|
-
}, "strip", z.ZodTypeAny, {
|
|
170
|
-
transportType: "http";
|
|
171
|
-
sampleRate: number;
|
|
172
|
-
captureInputs: boolean;
|
|
173
|
-
captureOutputs: boolean;
|
|
174
|
-
maxInputLength: number;
|
|
175
|
-
maxOutputLength: number;
|
|
176
|
-
httpConfig?: {
|
|
177
|
-
apiUrl: string;
|
|
178
|
-
apiToken: string;
|
|
179
|
-
agentId?: string | undefined;
|
|
180
|
-
agentIdentifier?: string | undefined;
|
|
181
|
-
agentName?: string | undefined;
|
|
182
|
-
agentDescription?: string | undefined;
|
|
183
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
184
|
-
requestTimeout?: number | undefined;
|
|
185
|
-
maxRetries?: number | undefined;
|
|
186
|
-
initialRetryDelay?: number | undefined;
|
|
187
|
-
maxRetryDelay?: number | undefined;
|
|
188
|
-
retryMultiplier?: number | undefined;
|
|
189
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
190
|
-
} | undefined;
|
|
191
|
-
}, {
|
|
192
|
-
transportType?: "http" | undefined;
|
|
193
|
-
sampleRate?: number | undefined;
|
|
194
|
-
captureInputs?: boolean | undefined;
|
|
195
|
-
captureOutputs?: boolean | undefined;
|
|
196
|
-
maxInputLength?: number | undefined;
|
|
197
|
-
maxOutputLength?: number | undefined;
|
|
198
|
-
httpConfig?: {
|
|
199
|
-
apiUrl: string;
|
|
200
|
-
apiToken: string;
|
|
201
|
-
agentId?: string | undefined;
|
|
202
|
-
agentIdentifier?: string | undefined;
|
|
203
|
-
agentName?: string | undefined;
|
|
204
|
-
agentDescription?: string | undefined;
|
|
205
|
-
agentSchema?: Record<string, unknown> | undefined;
|
|
206
|
-
requestTimeout?: number | undefined;
|
|
207
|
-
maxRetries?: number | undefined;
|
|
208
|
-
initialRetryDelay?: number | undefined;
|
|
209
|
-
maxRetryDelay?: number | undefined;
|
|
210
|
-
retryMultiplier?: number | undefined;
|
|
211
|
-
retryOnStatusCodes?: number[] | undefined;
|
|
212
|
-
} | undefined;
|
|
213
|
-
}>;
|
|
65
|
+
retryOnStatusCodes: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
66
|
+
}, z.core.$strip>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
214
68
|
export type Config = z.infer<typeof ConfigSchema>;
|
|
215
69
|
/**
|
|
216
70
|
* Creates a validated configuration object by merging provided options with
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB;;GAEG;AACH,eAAO,MAAM,yBAAyB
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;iBAuCpC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;iBAclC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;iBAqBvB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAyB9D"}
|
package/dist/config.js
CHANGED
|
@@ -21,7 +21,7 @@ export const HttpTransportConfigSchema = z.object({
|
|
|
21
21
|
/** Optional agent description */
|
|
22
22
|
agentDescription: z.string().optional(),
|
|
23
23
|
/** Optional agent schema for validation (full schema object) */
|
|
24
|
-
agentSchema: z.record(z.unknown()).optional(),
|
|
24
|
+
agentSchema: z.record(z.string(), z.unknown()).optional(),
|
|
25
25
|
/** Request timeout in milliseconds */
|
|
26
26
|
requestTimeout: z.number().positive().default(30000),
|
|
27
27
|
/** Maximum number of retry attempts */
|
|
@@ -45,7 +45,7 @@ export const PartialHttpConfigSchema = z.object({
|
|
|
45
45
|
agentIdentifier: z.string().optional(),
|
|
46
46
|
agentName: z.string().optional(),
|
|
47
47
|
agentDescription: z.string().optional(),
|
|
48
|
-
agentSchema: z.record(z.unknown()).optional(),
|
|
48
|
+
agentSchema: z.record(z.string(), z.unknown()).optional(),
|
|
49
49
|
requestTimeout: z.number().positive().optional(),
|
|
50
50
|
maxRetries: z.number().int().nonnegative().optional(),
|
|
51
51
|
initialRetryDelay: z.number().positive().optional(),
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,6BAA6B,GAAG;IACpC,GAAG;IACH,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC;CAC1D,CAAC;AACF,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,uBAAuB;IACvB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAExB,2BAA2B;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAE3B,uDAAuD;IACvD,OAAO,EAAE,CAAC,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I,OAAO,EAAE,EAAE,CAAC;QAC9F,UAAU,EAAE,OAAO,EAAE,UAAU;YAC7B,CAAC,CAAC;gBACE,GAAG,OAAO,CAAC,UAAU;gBACrB,kBAAkB,EAAE,OAAO,CAAC,UAAU,CAAC,kBAAkB,IAAI,yBAAyB;aACvF;YACH,CAAC,CAAC,SAAS;KACd,CAAC;IAEF,sBAAsB;IACtB,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,0BAA0B,CAAC,KAAyB;IAC3D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,WAAW,GAAG,KAAK;SACtB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SAC9B,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC/B,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC;IAEtD,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(exports_src, {
|
|
|
35
35
|
serializeValue: () => serializeValue,
|
|
36
36
|
registerShutdownHandler: () => registerShutdownHandler,
|
|
37
37
|
getLogger: () => getLogger,
|
|
38
|
+
createSpanTypePrefixer: () => createSpanTypePrefixer,
|
|
38
39
|
createCore: () => createCore,
|
|
39
40
|
createConfig: () => createConfig,
|
|
40
41
|
configureLogging: () => configureLogging,
|
|
@@ -114,7 +115,7 @@ var HttpTransportConfigSchema = import_zod.z.object({
|
|
|
114
115
|
agentIdentifier: import_zod.z.string().default("v1.0.0"),
|
|
115
116
|
agentName: import_zod.z.string().optional(),
|
|
116
117
|
agentDescription: import_zod.z.string().optional(),
|
|
117
|
-
agentSchema: import_zod.z.record(import_zod.z.unknown()).optional(),
|
|
118
|
+
agentSchema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
|
|
118
119
|
requestTimeout: import_zod.z.number().positive().default(30000),
|
|
119
120
|
maxRetries: import_zod.z.number().int().nonnegative().default(3),
|
|
120
121
|
initialRetryDelay: import_zod.z.number().positive().default(1000),
|
|
@@ -129,7 +130,7 @@ var PartialHttpConfigSchema = import_zod.z.object({
|
|
|
129
130
|
agentIdentifier: import_zod.z.string().optional(),
|
|
130
131
|
agentName: import_zod.z.string().optional(),
|
|
131
132
|
agentDescription: import_zod.z.string().optional(),
|
|
132
|
-
agentSchema: import_zod.z.record(import_zod.z.unknown()).optional(),
|
|
133
|
+
agentSchema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
|
|
133
134
|
requestTimeout: import_zod.z.number().positive().optional(),
|
|
134
135
|
maxRetries: import_zod.z.number().int().nonnegative().optional(),
|
|
135
136
|
initialRetryDelay: import_zod.z.number().positive().optional(),
|
|
@@ -259,6 +260,18 @@ class SpanContext {
|
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
|
|
263
|
+
// packages/core/src/tracing/result-payload.ts
|
|
264
|
+
function buildSpanResultPayload(span) {
|
|
265
|
+
if (span.error) {
|
|
266
|
+
return {
|
|
267
|
+
error_type: span.error.errorType,
|
|
268
|
+
message: span.error.message,
|
|
269
|
+
stacktrace: span.error.stacktrace
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return span.outputs ?? {};
|
|
273
|
+
}
|
|
274
|
+
|
|
262
275
|
// packages/core/src/tracing/span.ts
|
|
263
276
|
var SpanType = {
|
|
264
277
|
AGENT: "agent",
|
|
@@ -266,6 +279,9 @@ var SpanType = {
|
|
|
266
279
|
TOOL: "tool",
|
|
267
280
|
CHAIN: "chain"
|
|
268
281
|
};
|
|
282
|
+
function createSpanTypePrefixer(namespace) {
|
|
283
|
+
return (spanType) => `${namespace}:${spanType}`;
|
|
284
|
+
}
|
|
269
285
|
var SpanStatus;
|
|
270
286
|
((SpanStatus2) => {
|
|
271
287
|
SpanStatus2["RUNNING"] = "running";
|
|
@@ -326,7 +342,11 @@ class Tracer {
|
|
|
326
342
|
}
|
|
327
343
|
try {
|
|
328
344
|
if (span.spanType === SpanType.AGENT) {
|
|
329
|
-
|
|
345
|
+
const status = span.status === "error" /* ERROR */ ? "failed" : "complete";
|
|
346
|
+
this.transport.finishSpan(span.spanId, endTime, {
|
|
347
|
+
status,
|
|
348
|
+
resultPayload: buildSpanResultPayload(span)
|
|
349
|
+
});
|
|
330
350
|
} else {
|
|
331
351
|
this.transport.emit(span);
|
|
332
352
|
}
|
|
@@ -713,11 +733,14 @@ class AgentSpanClient {
|
|
|
713
733
|
body: payload
|
|
714
734
|
});
|
|
715
735
|
}
|
|
716
|
-
async finish(spanId, timestamp) {
|
|
736
|
+
async finish(spanId, timestamp, options = {}) {
|
|
717
737
|
try {
|
|
718
738
|
await this.httpClient.request(`/api/v1/agent_spans/${spanId}/finish`, {
|
|
719
739
|
method: "POST",
|
|
720
|
-
body: {
|
|
740
|
+
body: {
|
|
741
|
+
timestamp,
|
|
742
|
+
...options
|
|
743
|
+
}
|
|
721
744
|
});
|
|
722
745
|
} catch (error) {
|
|
723
746
|
if (error instanceof HttpClientError && error.status === 409 && isAlreadyFinishedError(error.responseBody)) {
|
|
@@ -777,8 +800,14 @@ class HttpTransport {
|
|
|
777
800
|
emit(span) {
|
|
778
801
|
this.enqueue({ type: "span_end", span });
|
|
779
802
|
}
|
|
780
|
-
finishSpan(spanId, endTime) {
|
|
781
|
-
this.enqueue({
|
|
803
|
+
finishSpan(spanId, endTime, options) {
|
|
804
|
+
this.enqueue({
|
|
805
|
+
type: "span_finish",
|
|
806
|
+
spanId,
|
|
807
|
+
endTime,
|
|
808
|
+
status: options?.status,
|
|
809
|
+
resultPayload: options?.resultPayload
|
|
810
|
+
});
|
|
782
811
|
}
|
|
783
812
|
async close() {
|
|
784
813
|
this.closed = true;
|
|
@@ -850,28 +879,32 @@ class HttpTransport {
|
|
|
850
879
|
await this.sendSpan(action.span);
|
|
851
880
|
return;
|
|
852
881
|
case "span_finish": {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
882
|
+
if (this.spanIdMap.has(action.spanId)) {
|
|
883
|
+
await this.finishSpanHttp(action.spanId, action.endTime, {
|
|
884
|
+
status: action.status,
|
|
885
|
+
resultPayload: action.resultPayload
|
|
886
|
+
});
|
|
857
887
|
} else {
|
|
858
|
-
this.pendingFinishes.set(action.spanId,
|
|
888
|
+
this.pendingFinishes.set(action.spanId, {
|
|
889
|
+
endTime: action.endTime,
|
|
890
|
+
status: action.status,
|
|
891
|
+
resultPayload: action.resultPayload
|
|
892
|
+
});
|
|
859
893
|
}
|
|
860
894
|
return;
|
|
861
895
|
}
|
|
862
896
|
}
|
|
863
897
|
};
|
|
864
898
|
async processPendingFinishes(spanId) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
const pendingEndTime = this.pendingFinishes.get(spanId);
|
|
869
|
-
if (pendingEndTime === undefined) {
|
|
899
|
+
const pendingFinish = this.pendingFinishes.get(spanId);
|
|
900
|
+
if (pendingFinish === undefined) {
|
|
870
901
|
return;
|
|
871
902
|
}
|
|
872
903
|
try {
|
|
873
|
-
|
|
874
|
-
|
|
904
|
+
await this.finishSpanHttp(spanId, pendingFinish.endTime, {
|
|
905
|
+
status: pendingFinish.status,
|
|
906
|
+
resultPayload: pendingFinish.resultPayload
|
|
907
|
+
});
|
|
875
908
|
this.pendingFinishes.delete(spanId);
|
|
876
909
|
} catch (error) {
|
|
877
910
|
logger.error("Error processing pending span finish:", error);
|
|
@@ -911,6 +944,7 @@ class HttpTransport {
|
|
|
911
944
|
const startedAt = new Date(span.startTime).toISOString();
|
|
912
945
|
const finishedAt = span.endTime ? new Date(span.endTime).toISOString() : null;
|
|
913
946
|
const apiStatus = this.mapStatusForApi(span.status);
|
|
947
|
+
const resultPayload = apiStatus === "active" ? undefined : buildSpanResultPayload(span);
|
|
914
948
|
const payload = {
|
|
915
949
|
span_id: span.spanId,
|
|
916
950
|
trace_id: span.traceId,
|
|
@@ -943,6 +977,7 @@ class HttpTransport {
|
|
|
943
977
|
schema_name: span.spanType,
|
|
944
978
|
status: apiStatus,
|
|
945
979
|
payload,
|
|
980
|
+
result_payload: resultPayload,
|
|
946
981
|
parent_span_id: parentSpanId,
|
|
947
982
|
started_at: startedAt,
|
|
948
983
|
finished_at: finishedAt
|
|
@@ -1010,14 +1045,17 @@ class HttpTransport {
|
|
|
1010
1045
|
}
|
|
1011
1046
|
this.agentInstanceId = null;
|
|
1012
1047
|
}
|
|
1013
|
-
async finishSpanHttp(
|
|
1014
|
-
const backendSpanId = this.spanIdMap.get(
|
|
1048
|
+
async finishSpanHttp(spanId, endTime, options) {
|
|
1049
|
+
const backendSpanId = this.spanIdMap.get(spanId);
|
|
1015
1050
|
if (!backendSpanId) {
|
|
1016
|
-
logger.warn(`Cannot finish span ${
|
|
1051
|
+
logger.warn(`Cannot finish span ${spanId}: backend ID not found`);
|
|
1017
1052
|
return;
|
|
1018
1053
|
}
|
|
1019
1054
|
try {
|
|
1020
|
-
await this.agentSpanClient.finish(backendSpanId,
|
|
1055
|
+
await this.agentSpanClient.finish(backendSpanId, new Date(endTime).toISOString(), {
|
|
1056
|
+
status: options?.status,
|
|
1057
|
+
result_payload: options?.resultPayload ?? {}
|
|
1058
|
+
});
|
|
1021
1059
|
} catch (error) {
|
|
1022
1060
|
logger.error("Error finishing span:", error);
|
|
1023
1061
|
}
|
|
@@ -1059,8 +1097,8 @@ async function withSpan(tracerOrOptions, optionsOrFn, maybeFn) {
|
|
|
1059
1097
|
const { tracer, options, fn } = resolveArgs(tracerOrOptions, optionsOrFn, maybeFn);
|
|
1060
1098
|
const span = tracer.startSpan(options);
|
|
1061
1099
|
try {
|
|
1062
|
-
const result = await SpanContext.runAsync(span,
|
|
1063
|
-
tracer.endSpan(span);
|
|
1100
|
+
const result = await SpanContext.runAsync(span, () => Promise.resolve(fn()));
|
|
1101
|
+
tracer.endSpan(span, { outputs: toSpanOutputs(result) });
|
|
1064
1102
|
return result;
|
|
1065
1103
|
} catch (error) {
|
|
1066
1104
|
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -1068,6 +1106,22 @@ async function withSpan(tracerOrOptions, optionsOrFn, maybeFn) {
|
|
|
1068
1106
|
throw error;
|
|
1069
1107
|
}
|
|
1070
1108
|
}
|
|
1109
|
+
function toSpanOutputs(result) {
|
|
1110
|
+
if (isRecord(result)) {
|
|
1111
|
+
return result;
|
|
1112
|
+
}
|
|
1113
|
+
if (result === undefined) {
|
|
1114
|
+
return {};
|
|
1115
|
+
}
|
|
1116
|
+
return { result };
|
|
1117
|
+
}
|
|
1118
|
+
function isRecord(value) {
|
|
1119
|
+
if (value === null || typeof value !== "object") {
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1123
|
+
return prototype === Object.prototype || prototype === null;
|
|
1124
|
+
}
|
|
1071
1125
|
function resolveArgs(tracerOrOptions, optionsOrFn, maybeFn) {
|
|
1072
1126
|
if (maybeFn) {
|
|
1073
1127
|
return {
|
|
@@ -1120,4 +1174,4 @@ function serializeValue(value, maxLength = 1e4) {
|
|
|
1120
1174
|
}
|
|
1121
1175
|
}
|
|
1122
1176
|
|
|
1123
|
-
//# debugId=
|
|
1177
|
+
//# debugId=BA1292FDF3A449CF64756E2164756E21
|