@traceroot-ai/traceroot 0.1.6 → 0.1.8
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/attributes.d.ts +14 -0
- package/dist/attributes.d.ts.map +1 -0
- package/dist/attributes.js +110 -0
- package/dist/attributes.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +8 -2
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -34
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/instrumentation.d.ts.map +1 -1
- package/dist/instrumentation.js +4 -0
- package/dist/instrumentation.js.map +1 -1
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +5 -63
- package/dist/observe.js.map +1 -1
- package/dist/pi.d.ts +156 -0
- package/dist/pi.d.ts.map +1 -0
- package/dist/pi.js +615 -0
- package/dist/pi.js.map +1 -0
- package/dist/spans.d.ts +18 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +104 -0
- package/dist/spans.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -1
package/dist/pi.js
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRACER_NAME = void 0;
|
|
4
|
+
exports.resolveConfig = resolveConfig;
|
|
5
|
+
exports.openRootSpan = openRootSpan;
|
|
6
|
+
exports.stampRootOutput = stampRootOutput;
|
|
7
|
+
exports.finalizeRootSpan = finalizeRootSpan;
|
|
8
|
+
exports.openLlmSpan = openLlmSpan;
|
|
9
|
+
exports.closeLlmSpan = closeLlmSpan;
|
|
10
|
+
exports.describeToolCallSpan = describeToolCallSpan;
|
|
11
|
+
exports.openToolSpan = openToolSpan;
|
|
12
|
+
exports.closeToolSpan = closeToolSpan;
|
|
13
|
+
exports.closeDanglingSpan = closeDanglingSpan;
|
|
14
|
+
exports.wirePiCodingAgentInstrumentation = wirePiCodingAgentInstrumentation;
|
|
15
|
+
exports.instrumentPiCodingAgent = instrumentPiCodingAgent;
|
|
16
|
+
const node_path_1 = require("node:path");
|
|
17
|
+
const api_1 = require("@opentelemetry/api");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const processor_1 = require("./processor");
|
|
20
|
+
exports.TRACER_NAME = '@traceroot-ai/pi-coding-agent';
|
|
21
|
+
function resolveConfig(config) {
|
|
22
|
+
const captureContent = config?.captureContent ?? true;
|
|
23
|
+
const captureToolIo = config?.captureToolIo ?? true;
|
|
24
|
+
return {
|
|
25
|
+
captureContent,
|
|
26
|
+
captureToolIo,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const OI_SPAN_KIND_VALUE = {
|
|
30
|
+
AGENT: 'AGENT',
|
|
31
|
+
LLM: 'LLM',
|
|
32
|
+
TOOL: 'TOOL',
|
|
33
|
+
};
|
|
34
|
+
// Attribute triad matching other traceroot-ts integrations: OpenInference span-kind, OTel gen_ai.*, traceroot.pi.* retry/force-close markers.
|
|
35
|
+
const TR_ATTRIBUTES = {
|
|
36
|
+
RETRY_COUNT: 'traceroot.pi.retry_count',
|
|
37
|
+
FORCE_CLOSED: 'traceroot.pi.force_closed',
|
|
38
|
+
FORCE_CLOSED_REASON: 'traceroot.pi.force_closed_reason',
|
|
39
|
+
};
|
|
40
|
+
// Pi reports usage in the gen_ai.* family; LLM spans dual-write the OpenInference
|
|
41
|
+
// llm.* keys (from constants.ts) alongside these — see openLlmSpan/closeLlmSpan.
|
|
42
|
+
const GEN_AI_ATTRIBUTES = {
|
|
43
|
+
SYSTEM: 'gen_ai.system',
|
|
44
|
+
REQUEST_MODEL: 'gen_ai.request.model',
|
|
45
|
+
RESPONSE_MODEL: 'gen_ai.response.model',
|
|
46
|
+
USAGE_INPUT_TOKENS: 'gen_ai.usage.input_tokens',
|
|
47
|
+
USAGE_OUTPUT_TOKENS: 'gen_ai.usage.output_tokens',
|
|
48
|
+
CACHE_WRITE_INPUT_TOKENS: 'gen_ai.usage.cache_creation_input_tokens',
|
|
49
|
+
CACHE_READ_INPUT_TOKENS: 'gen_ai.usage.cache_read_input_tokens',
|
|
50
|
+
TOOL_NAME: 'gen_ai.tool.name',
|
|
51
|
+
TOOL_CALL_ID: 'gen_ai.tool.call.id',
|
|
52
|
+
};
|
|
53
|
+
function setAttr(span, key, value) {
|
|
54
|
+
if (value === undefined || value === null)
|
|
55
|
+
return;
|
|
56
|
+
span.setAttribute(key, value);
|
|
57
|
+
}
|
|
58
|
+
function endSpanSafe(span) {
|
|
59
|
+
if (!span)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
span.end();
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Never let a misbehaving OTel exporter/processor crash the host app.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Caps exported tool JSON so one call can't inflate a span's attribute payload without bound.
|
|
69
|
+
const MAX_TOOL_IO_JSON_CHARS = 32 * 1024; // 32 KB of UTF-16 code units
|
|
70
|
+
// Caps array/object breadth so a "wide" payload (tens of thousands of small entries,
|
|
71
|
+
// e.g. a custom/MCP tool result) can't fully materialize in JSON.stringify before
|
|
72
|
+
// capJsonWithMarker discards it — bounds transient serialization cost, not just the
|
|
73
|
+
// final attribute size.
|
|
74
|
+
const MAX_TOOL_IO_ENTRIES = 2048;
|
|
75
|
+
// Appended whenever capJsonWithMarker cuts, so truncation is distinguishable from coincidence.
|
|
76
|
+
const TRUNCATION_MARKER = '…[truncated]';
|
|
77
|
+
function capJsonWithMarker(json) {
|
|
78
|
+
if (json.length <= MAX_TOOL_IO_JSON_CHARS)
|
|
79
|
+
return json;
|
|
80
|
+
return `${json.slice(0, MAX_TOOL_IO_JSON_CHARS)}${TRUNCATION_MARKER}`;
|
|
81
|
+
}
|
|
82
|
+
// Caps each oversized string field AND array/object breadth while walking the tree, so
|
|
83
|
+
// neither one huge field nor tens of thousands of small ones fully materialize first.
|
|
84
|
+
function capFieldReplacer(_key, value) {
|
|
85
|
+
if (typeof value === 'string' && value.length > MAX_TOOL_IO_JSON_CHARS) {
|
|
86
|
+
return value.slice(0, MAX_TOOL_IO_JSON_CHARS);
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value) && value.length > MAX_TOOL_IO_ENTRIES) {
|
|
89
|
+
return [...value.slice(0, MAX_TOOL_IO_ENTRIES), TRUNCATION_MARKER];
|
|
90
|
+
}
|
|
91
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
92
|
+
const keys = Object.keys(value);
|
|
93
|
+
if (keys.length > MAX_TOOL_IO_ENTRIES) {
|
|
94
|
+
const capped = {};
|
|
95
|
+
for (const key of keys.slice(0, MAX_TOOL_IO_ENTRIES)) {
|
|
96
|
+
capped[key] = value[key];
|
|
97
|
+
}
|
|
98
|
+
capped[TRUNCATION_MARKER] = TRUNCATION_MARKER;
|
|
99
|
+
return capped;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
// JSON.stringify can return undefined for a top-level undefined value, despite its `string` type — short-circuit before capJsonWithMarker's .length.
|
|
105
|
+
function stringifyToolIo(value) {
|
|
106
|
+
if (value === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
return JSON.stringify(value, capFieldReplacer);
|
|
109
|
+
}
|
|
110
|
+
function assistantTextOf(message) {
|
|
111
|
+
if (!message)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (message.role === 'user' && typeof message.content === 'string')
|
|
114
|
+
return message.content;
|
|
115
|
+
if (message.role !== 'assistant')
|
|
116
|
+
return undefined;
|
|
117
|
+
// Malformed/non-array content is treated as "no text", not thrown, to avoid skipping the caller's span close.
|
|
118
|
+
if (!Array.isArray(message.content))
|
|
119
|
+
return undefined;
|
|
120
|
+
const parts = message.content
|
|
121
|
+
.filter((c) => {
|
|
122
|
+
return typeof c === 'object' && c !== null && c.type === 'text';
|
|
123
|
+
})
|
|
124
|
+
.map((c) => c.text);
|
|
125
|
+
return parts.length > 0 ? parts.join('') : undefined;
|
|
126
|
+
}
|
|
127
|
+
function isToolCallPart(part) {
|
|
128
|
+
return (typeof part === 'object' && part !== null && part.type === 'toolCall');
|
|
129
|
+
}
|
|
130
|
+
// OpenAI-convention function-call `arguments` is a JSON *string*: keep a string
|
|
131
|
+
// as-is, else serialize. A non-serializable value (circular/BigInt) collapses to
|
|
132
|
+
// "" rather than throwing, so one bad arg can't drop the whole output.
|
|
133
|
+
function toolCallArgumentsString(args) {
|
|
134
|
+
if (typeof args === 'string')
|
|
135
|
+
return args;
|
|
136
|
+
try {
|
|
137
|
+
return JSON.stringify(args) ?? '';
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Output value for an assistant turn. A text-only turn stays a plain string
|
|
144
|
+
// (unchanged). A turn that ISSUED tool calls — which is exactly the turn that
|
|
145
|
+
// owns the nested TOOL spans — serializes an OpenAI-style assistant message so
|
|
146
|
+
// the tool calls the model produced aren't silently dropped from the LLM span
|
|
147
|
+
// (assistantTextOf alone returns undefined for a tool-call-only turn). Mirrors
|
|
148
|
+
// claude-agent-sdk.ts, which serializes the full assistant message content.
|
|
149
|
+
function assistantOutputValue(message) {
|
|
150
|
+
const text = assistantTextOf(message);
|
|
151
|
+
if (!message || message.role !== 'assistant' || !Array.isArray(message.content)) {
|
|
152
|
+
return text;
|
|
153
|
+
}
|
|
154
|
+
const toolCalls = message.content.filter(isToolCallPart).map((part) => ({
|
|
155
|
+
id: part.id,
|
|
156
|
+
type: 'function',
|
|
157
|
+
function: { name: part.name, arguments: toolCallArgumentsString(part.arguments) },
|
|
158
|
+
}));
|
|
159
|
+
if (toolCalls.length === 0)
|
|
160
|
+
return text;
|
|
161
|
+
try {
|
|
162
|
+
return capJsonWithMarker(JSON.stringify({ role: 'assistant', content: text ?? null, tool_calls: toolCalls }));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// arguments are already strings, so this should not throw; never lose the close.
|
|
166
|
+
return text;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function openRootSpan(tracer, parentCtx, input) {
|
|
170
|
+
const span = tracer.startSpan('AgentSession.prompt', { kind: api_1.SpanKind.INTERNAL }, parentCtx);
|
|
171
|
+
setAttr(span, constants_1.OI_SPAN_KIND, OI_SPAN_KIND_VALUE.AGENT);
|
|
172
|
+
setAttr(span, constants_1.OI_TRACE_SESSION_ID, input.sessionId);
|
|
173
|
+
if (input.captureContent)
|
|
174
|
+
setAttr(span, constants_1.OI_INPUT_VALUE, input.text);
|
|
175
|
+
return span;
|
|
176
|
+
}
|
|
177
|
+
// Stamps output onto the root span without ending it; continuations share one root, so the last agent_end wins.
|
|
178
|
+
function stampRootOutput(span, finalMessages, captureContent) {
|
|
179
|
+
if (!captureContent)
|
|
180
|
+
return;
|
|
181
|
+
let lastAssistant;
|
|
182
|
+
for (let i = finalMessages.length - 1; i >= 0; i -= 1) {
|
|
183
|
+
if (finalMessages[i].role === 'assistant') {
|
|
184
|
+
lastAssistant = finalMessages[i];
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
setAttr(span, constants_1.OI_OUTPUT_VALUE, assistantOutputValue(lastAssistant));
|
|
189
|
+
}
|
|
190
|
+
// Ends the root span exactly once, when the wrapping prompt() call's own returned promise settles.
|
|
191
|
+
function finalizeRootSpan(span, retryCount, status, error) {
|
|
192
|
+
// Called from a detached .then() chain nobody awaits, so guard against unhandledRejection here too.
|
|
193
|
+
try {
|
|
194
|
+
setAttr(span, TR_ATTRIBUTES.RETRY_COUNT, retryCount);
|
|
195
|
+
span.setStatus(status);
|
|
196
|
+
if (error !== undefined) {
|
|
197
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// best-effort, same as endSpanSafe
|
|
202
|
+
}
|
|
203
|
+
endSpanSafe(span);
|
|
204
|
+
}
|
|
205
|
+
function openLlmSpan(tracer, parentCtx, message) {
|
|
206
|
+
const span = tracer.startSpan(message.model || 'pi.llm', { kind: api_1.SpanKind.CLIENT }, parentCtx);
|
|
207
|
+
setAttr(span, constants_1.OI_SPAN_KIND, OI_SPAN_KIND_VALUE.LLM);
|
|
208
|
+
setAttr(span, GEN_AI_ATTRIBUTES.SYSTEM, message.provider);
|
|
209
|
+
setAttr(span, GEN_AI_ATTRIBUTES.REQUEST_MODEL, message.model);
|
|
210
|
+
// Dual-write the OpenInference llm.* family alongside gen_ai.* for downstream
|
|
211
|
+
// consumers. model_name starts at the request model; closeLlmSpan resolves it.
|
|
212
|
+
setAttr(span, constants_1.OI_LLM_MODEL_NAME, message.model);
|
|
213
|
+
return span;
|
|
214
|
+
}
|
|
215
|
+
function closeLlmSpan(span, message, captureContent) {
|
|
216
|
+
span.updateName(message.responseModel || message.model || 'pi.llm');
|
|
217
|
+
setAttr(span, GEN_AI_ATTRIBUTES.RESPONSE_MODEL, message.responseModel || message.model);
|
|
218
|
+
setAttr(span, GEN_AI_ATTRIBUTES.USAGE_INPUT_TOKENS, message.usage?.input);
|
|
219
|
+
setAttr(span, GEN_AI_ATTRIBUTES.USAGE_OUTPUT_TOKENS, message.usage?.output);
|
|
220
|
+
setAttr(span, GEN_AI_ATTRIBUTES.CACHE_READ_INPUT_TOKENS, message.usage?.cacheRead);
|
|
221
|
+
setAttr(span, GEN_AI_ATTRIBUTES.CACHE_WRITE_INPUT_TOKENS, message.usage?.cacheWrite);
|
|
222
|
+
// OpenInference llm.* dual-write of the same numbers (see openLlmSpan). Pi
|
|
223
|
+
// reports totalTokens directly, so llm.token_count.total uses it as-is rather
|
|
224
|
+
// than recomputing prompt+completion.
|
|
225
|
+
setAttr(span, constants_1.OI_LLM_MODEL_NAME, message.responseModel || message.model);
|
|
226
|
+
setAttr(span, constants_1.OI_LLM_TOKEN_COUNT_PROMPT, message.usage?.input);
|
|
227
|
+
setAttr(span, constants_1.OI_LLM_TOKEN_COUNT_COMPLETION, message.usage?.output);
|
|
228
|
+
setAttr(span, constants_1.OI_LLM_TOKEN_COUNT_TOTAL, message.usage?.totalTokens);
|
|
229
|
+
setAttr(span, constants_1.OI_LLM_TOKEN_COUNT_CACHE_READ, message.usage?.cacheRead);
|
|
230
|
+
setAttr(span, constants_1.OI_LLM_TOKEN_COUNT_CACHE_WRITE, message.usage?.cacheWrite);
|
|
231
|
+
if (captureContent) {
|
|
232
|
+
setAttr(span, constants_1.OI_OUTPUT_VALUE, assistantOutputValue(message));
|
|
233
|
+
}
|
|
234
|
+
if (message.stopReason === 'error' || message.stopReason === 'aborted') {
|
|
235
|
+
span.setStatus({
|
|
236
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
237
|
+
message: message.errorMessage || message.stopReason,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
endSpanSafe(span);
|
|
241
|
+
}
|
|
242
|
+
// Privacy-safe tool span naming: never a full file path, commands/basenames capped to MAX_NAME_SEGMENT_CHARS.
|
|
243
|
+
const basename = node_path_1.win32.basename;
|
|
244
|
+
const MAX_NAME_SEGMENT_CHARS = 60;
|
|
245
|
+
const TOOL_PATH_ARGUMENT_KEYS = [
|
|
246
|
+
'path',
|
|
247
|
+
'file',
|
|
248
|
+
'filePath',
|
|
249
|
+
'file_path',
|
|
250
|
+
'filename',
|
|
251
|
+
'target',
|
|
252
|
+
];
|
|
253
|
+
function firstPathArgument(args) {
|
|
254
|
+
for (const key of TOOL_PATH_ARGUMENT_KEYS) {
|
|
255
|
+
const value = args[key];
|
|
256
|
+
if (typeof value === 'string' && value)
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
function truncateWithEllipsis(text, maxLen) {
|
|
262
|
+
if (text.length <= maxLen)
|
|
263
|
+
return text;
|
|
264
|
+
return `${text.slice(0, maxLen)}…`;
|
|
265
|
+
}
|
|
266
|
+
function describeToolCallSpan(toolName, args) {
|
|
267
|
+
if (args && typeof args === 'object') {
|
|
268
|
+
const a = args;
|
|
269
|
+
// Checked first, exclusively by command, so an incidental path/target argument (e.g. cwd) can't shadow it.
|
|
270
|
+
if (toolName === 'bash' && typeof a.command === 'string' && a.command) {
|
|
271
|
+
const cmd = a.command.replace(/\s+/g, ' ').trim();
|
|
272
|
+
if (cmd)
|
|
273
|
+
return `bash: ${truncateWithEllipsis(cmd, MAX_NAME_SEGMENT_CHARS)}`;
|
|
274
|
+
}
|
|
275
|
+
const pathLike = firstPathArgument(a);
|
|
276
|
+
if (pathLike) {
|
|
277
|
+
const base = basename(pathLike);
|
|
278
|
+
// Can still basename() to '' (e.g. "/") — fall through instead of "toolName: ".
|
|
279
|
+
if (base) {
|
|
280
|
+
return `${toolName}: ${truncateWithEllipsis(base, MAX_NAME_SEGMENT_CHARS)}`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return toolName;
|
|
285
|
+
}
|
|
286
|
+
function openToolSpan(tracer, parentCtx, toolCallId, toolName, args, captureToolIo) {
|
|
287
|
+
const span = tracer.startSpan(
|
|
288
|
+
// captureToolIo gates arg-derived content in the NAME too, not just input/output:
|
|
289
|
+
// a bash command or file path is tool IO and must not leak into the span name when
|
|
290
|
+
// the caller opted out (e.g. `bash: curl -H "Authorization: Bearer ..."`).
|
|
291
|
+
captureToolIo ? describeToolCallSpan(toolName, args) : toolName, { kind: api_1.SpanKind.INTERNAL }, parentCtx);
|
|
292
|
+
setAttr(span, constants_1.OI_SPAN_KIND, OI_SPAN_KIND_VALUE.TOOL);
|
|
293
|
+
// Dual-write OpenInference tool.name alongside gen_ai.tool.name (matches
|
|
294
|
+
// claude-agent-sdk.ts) so dashboards keyed on the OI attribute surface pi tool spans.
|
|
295
|
+
setAttr(span, constants_1.TOOL_NAME, toolName);
|
|
296
|
+
setAttr(span, GEN_AI_ATTRIBUTES.TOOL_NAME, toolName);
|
|
297
|
+
setAttr(span, GEN_AI_ATTRIBUTES.TOOL_CALL_ID, toolCallId);
|
|
298
|
+
if (captureToolIo) {
|
|
299
|
+
try {
|
|
300
|
+
const serializedArgs = stringifyToolIo(args);
|
|
301
|
+
if (serializedArgs !== undefined) {
|
|
302
|
+
setAttr(span, constants_1.OI_INPUT_VALUE, capJsonWithMarker(serializedArgs));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// args may contain circular refs or BigInt — skip rather than crash.
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return span;
|
|
310
|
+
}
|
|
311
|
+
function closeToolSpan(span, result, isError, captureToolIo) {
|
|
312
|
+
if (captureToolIo) {
|
|
313
|
+
try {
|
|
314
|
+
const serializedResult = stringifyToolIo(result);
|
|
315
|
+
if (serializedResult !== undefined) {
|
|
316
|
+
setAttr(span, constants_1.OI_OUTPUT_VALUE, capJsonWithMarker(serializedResult));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
// result may contain circular refs or BigInt — skip rather than crash.
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (isError) {
|
|
324
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR });
|
|
325
|
+
}
|
|
326
|
+
endSpanSafe(span);
|
|
327
|
+
}
|
|
328
|
+
// Used when a span is force-closed by a later event; only the setAttr call is guarded so a throw there can't skip endSpanSafe.
|
|
329
|
+
function closeDanglingSpan(span) {
|
|
330
|
+
if (!span)
|
|
331
|
+
return;
|
|
332
|
+
try {
|
|
333
|
+
setAttr(span, TR_ATTRIBUTES.FORCE_CLOSED, true);
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
// diag.warn, not console: proper OTel logging infrastructure, silent unless the host registers a DiagLogger, and it must never throw mid-flight.
|
|
337
|
+
api_1.diag.warn('[traceroot-pi] failed to mark a dangling span force_closed (still ending it):', err);
|
|
338
|
+
}
|
|
339
|
+
endSpanSafe(span);
|
|
340
|
+
}
|
|
341
|
+
// Symbol.for(), not a bare Symbol(): two independently-loaded copies of this package must see the same registry key to detect a second instrumentPiCodingAgent() call — do not change this without adding multiplexing support.
|
|
342
|
+
const WRAPPED = Symbol.for('traceroot.pi.wrapped');
|
|
343
|
+
// Force-closes spans left open by an abandoned run, root only when requested.
|
|
344
|
+
function sweepDanglingSpans(state, options = {}) {
|
|
345
|
+
for (const [, span] of state.toolSpans) {
|
|
346
|
+
closeDanglingSpan(span);
|
|
347
|
+
}
|
|
348
|
+
state.toolSpans.clear();
|
|
349
|
+
closeDanglingSpan(state.llmSpan);
|
|
350
|
+
state.llmSpan = undefined;
|
|
351
|
+
state.llmCtx = undefined;
|
|
352
|
+
if (options.includeRoot) {
|
|
353
|
+
closeDanglingSpan(state.rootSpan);
|
|
354
|
+
state.rootSpan = undefined;
|
|
355
|
+
state.rootCtx = undefined;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// Guarantees subscribe() ran once — proto.prompt/steer/followUp can each independently be a session's first call.
|
|
359
|
+
function ensureSubscribed(session, tracer, config, subscribedSessions, sessionSpanState) {
|
|
360
|
+
if (subscribedSessions.has(session))
|
|
361
|
+
return;
|
|
362
|
+
subscribedSessions.add(session);
|
|
363
|
+
attachSpanListener(session, tracer, config, sessionSpanState);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* An `instrumentModules.piCodingAgent` value is the `{ module, config }` wrapper
|
|
367
|
+
* form (vs a raw pi module ref) when it carries a `module` property and is NOT
|
|
368
|
+
* itself a pi module namespace. The negative `AgentSession` check guards against a
|
|
369
|
+
* future pi module that also exports a `module` symbol: the real pi namespace
|
|
370
|
+
* exposes `AgentSession`, the wrapper does not, so the two stay distinguishable.
|
|
371
|
+
*/
|
|
372
|
+
function isPiCodingAgentWrapper(entry) {
|
|
373
|
+
return (typeof entry === 'object' &&
|
|
374
|
+
entry !== null &&
|
|
375
|
+
'module' in entry &&
|
|
376
|
+
entry.module != null &&
|
|
377
|
+
!('AgentSession' in entry));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Dispatcher entry point for pi, called once by wireInstrumentations() in
|
|
381
|
+
* instrumentation.ts. Kept here rather than inline in that shared file so the
|
|
382
|
+
* dispatcher stays symmetric with claude/openai (one import + one call). Unwraps
|
|
383
|
+
* the optional { module, config } form; pi carries its own captureContent/
|
|
384
|
+
* captureToolIo config, passed through unmerged (there is no apiKey/baseUrl to
|
|
385
|
+
* thread). A throw from instrumentPiCodingAgent() surfaces, same as claude's.
|
|
386
|
+
*/
|
|
387
|
+
function wirePiCodingAgentInstrumentation(entry) {
|
|
388
|
+
let mod = entry;
|
|
389
|
+
let explicitConfig;
|
|
390
|
+
if (isPiCodingAgentWrapper(entry)) {
|
|
391
|
+
mod = entry.module;
|
|
392
|
+
explicitConfig = entry.config;
|
|
393
|
+
}
|
|
394
|
+
instrumentPiCodingAgent(mod, explicitConfig);
|
|
395
|
+
}
|
|
396
|
+
function instrumentPiCodingAgent(sdk, config) {
|
|
397
|
+
const mod = sdk;
|
|
398
|
+
const resolved = resolveConfig(config);
|
|
399
|
+
// Stamped on AgentSession.prototype, never on `mod`: an ESM namespace object is permanently non-extensible, so defineProperty(mod, ...) would throw.
|
|
400
|
+
const proto = mod?.AgentSession?.prototype;
|
|
401
|
+
if (typeof proto?.prompt !== 'function' || typeof proto?.subscribe !== 'function') {
|
|
402
|
+
// Fail loudly: a pi SDK rename must not silently emit zero traces.
|
|
403
|
+
throw new Error('[traceroot-pi] AgentSession.prototype.prompt/subscribe not found — cannot install instrumentation.');
|
|
404
|
+
}
|
|
405
|
+
// Idempotent no-op on a second install for the same sdk; the first call's config stands.
|
|
406
|
+
if (proto[WRAPPED]) {
|
|
407
|
+
return sdk;
|
|
408
|
+
}
|
|
409
|
+
// resolve at use, never capture: TraceRoot.shutdown() calls trace.disable(),
|
|
410
|
+
// which swaps the OTel proxy provider for a fresh instance. A tracer captured
|
|
411
|
+
// once here would stay bound to the old, now-detached provider, so after a
|
|
412
|
+
// shutdown()/initialize() cycle every span it opens goes silently dark.
|
|
413
|
+
// Re-resolve the globally-registered provider on each span-open.
|
|
414
|
+
const tracer = {
|
|
415
|
+
startSpan: (name, options, ctx) => api_1.trace.getTracer(exports.TRACER_NAME, processor_1.SDK_VERSION).startSpan(name, options, ctx),
|
|
416
|
+
};
|
|
417
|
+
const subscribedSessions = new WeakSet();
|
|
418
|
+
// Out-of-band, since dispose() (below) has no closure over a session.
|
|
419
|
+
const sessionSpanState = new WeakMap();
|
|
420
|
+
const rollback = [];
|
|
421
|
+
try {
|
|
422
|
+
const originalPrompt = proto.prompt;
|
|
423
|
+
proto.prompt = function (text, options) {
|
|
424
|
+
ensureSubscribed(this, tracer, resolved, subscribedSessions, sessionSpanState);
|
|
425
|
+
// Queue-only steer: if already streaming with streamingBehavior set, delegate straight through before any root management, or we'd force-close the active run's still-open root.
|
|
426
|
+
const isQueueOnlySteer = this.isStreaming === true && !!options?.streamingBehavior;
|
|
427
|
+
if (isQueueOnlySteer) {
|
|
428
|
+
return originalPrompt.call(this, text, options);
|
|
429
|
+
}
|
|
430
|
+
// Non-undefined: ensureSubscribed() above created or found this entry.
|
|
431
|
+
const state = sessionSpanState.get(this);
|
|
432
|
+
// OVERLAP SAFETY: a new call raced a still-open prior root — force-close it rather than silently leaking it.
|
|
433
|
+
// This can also fire on an accidental double-submit (isStreaming flips only after several awaits inside
|
|
434
|
+
// prompt()), so stamp a distinct reason on the superseded root: its trace is truncated by design, and this
|
|
435
|
+
// keeps that debuggable from the exported data.
|
|
436
|
+
if (state.rootSpan) {
|
|
437
|
+
setAttr(state.rootSpan, TR_ATTRIBUTES.FORCE_CLOSED_REASON, 'superseded_by_new_prompt');
|
|
438
|
+
sweepDanglingSpans(state, { includeRoot: true });
|
|
439
|
+
}
|
|
440
|
+
// context.active() lets a host span nest this trace under it.
|
|
441
|
+
const parentCtx = api_1.context.active();
|
|
442
|
+
const rootSpan = openRootSpan(tracer, parentCtx, {
|
|
443
|
+
text: typeof text === 'string' ? text : undefined,
|
|
444
|
+
sessionId: this.sessionId,
|
|
445
|
+
captureContent: resolved.captureContent,
|
|
446
|
+
});
|
|
447
|
+
state.rootSpan = rootSpan;
|
|
448
|
+
state.rootCtx = api_1.trace.setSpan(parentCtx, rootSpan);
|
|
449
|
+
state.retryCount = 0;
|
|
450
|
+
// Guarded by identity so a mid-run dispose() or a later sweep, which may have already force-closed it, never double-ends. Derives the status message from the error, if any.
|
|
451
|
+
const finalize = (code, error) => {
|
|
452
|
+
if (state.rootSpan !== rootSpan)
|
|
453
|
+
return;
|
|
454
|
+
state.rootSpan = undefined;
|
|
455
|
+
state.rootCtx = undefined;
|
|
456
|
+
// A rejection can leave the in-flight attempt's spans unclosed.
|
|
457
|
+
sweepDanglingSpans(state);
|
|
458
|
+
const message = error === undefined ? undefined : error instanceof Error ? error.message : String(error);
|
|
459
|
+
finalizeRootSpan(rootSpan, state.retryCount, { code, message }, error);
|
|
460
|
+
};
|
|
461
|
+
// A synchronous throw here never reached agent_start: finalize ERROR and rethrow.
|
|
462
|
+
let result;
|
|
463
|
+
try {
|
|
464
|
+
result = originalPrompt.call(this, text, options);
|
|
465
|
+
}
|
|
466
|
+
catch (err) {
|
|
467
|
+
finalize(api_1.SpanStatusCode.ERROR, err);
|
|
468
|
+
throw err;
|
|
469
|
+
}
|
|
470
|
+
// Separate .then() chain, not a return of result.then(...): that would swallow the rejection since onReject here doesn't rethrow.
|
|
471
|
+
result.then(() => finalize(api_1.SpanStatusCode.OK), (err) => finalize(api_1.SpanStatusCode.ERROR, err));
|
|
472
|
+
return result;
|
|
473
|
+
};
|
|
474
|
+
rollback.push(() => {
|
|
475
|
+
proto.prompt = originalPrompt;
|
|
476
|
+
});
|
|
477
|
+
// Standalone entry points, not prompt() wrappers — needed so a session's first call being one of these still triggers subscribe(). Both just subscribe then delegate, so they share one wrapper.
|
|
478
|
+
const patchSubscribeTrigger = (name) => {
|
|
479
|
+
const original = proto[name];
|
|
480
|
+
if (typeof original !== 'function')
|
|
481
|
+
return;
|
|
482
|
+
proto[name] = function (text, images) {
|
|
483
|
+
ensureSubscribed(this, tracer, resolved, subscribedSessions, sessionSpanState);
|
|
484
|
+
return original.call(this, text, images);
|
|
485
|
+
};
|
|
486
|
+
rollback.push(() => {
|
|
487
|
+
proto[name] = original;
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
patchSubscribeTrigger('steer');
|
|
491
|
+
patchSubscribeTrigger('followUp');
|
|
492
|
+
if (typeof proto.dispose === 'function') {
|
|
493
|
+
const originalDispose = proto.dispose;
|
|
494
|
+
proto.dispose = function () {
|
|
495
|
+
// The real dispose() only clears _eventListeners, so force-close any still-open spans first.
|
|
496
|
+
const state = sessionSpanState.get(this);
|
|
497
|
+
if (state) {
|
|
498
|
+
try {
|
|
499
|
+
sweepDanglingSpans(state, { includeRoot: true });
|
|
500
|
+
}
|
|
501
|
+
catch (err) {
|
|
502
|
+
// Must never make dispose() throw — the host still needs teardown. diag.warn, not console (see closeDanglingSpan).
|
|
503
|
+
api_1.diag.warn('[traceroot-pi] failed to force-close in-flight spans during dispose() (a span may leak):', err);
|
|
504
|
+
}
|
|
505
|
+
finally {
|
|
506
|
+
// sweepDanglingSpans({ includeRoot: true }) above already nulled every span/ctx field; the state is dropped here regardless.
|
|
507
|
+
sessionSpanState.delete(this);
|
|
508
|
+
// Else a reused session would never re-subscribe (still "has" it).
|
|
509
|
+
subscribedSessions.delete(this);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return originalDispose.call(this);
|
|
513
|
+
};
|
|
514
|
+
rollback.push(() => {
|
|
515
|
+
proto.dispose = originalDispose;
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
// Only mark wrapped after every patch succeeded, else a re-entrant call could double-emit spans.
|
|
519
|
+
Object.defineProperty(proto, WRAPPED, { value: true, enumerable: false });
|
|
520
|
+
}
|
|
521
|
+
catch (err) {
|
|
522
|
+
for (let i = rollback.length - 1; i >= 0; i--) {
|
|
523
|
+
rollback[i]();
|
|
524
|
+
}
|
|
525
|
+
throw new Error('[traceroot-pi] failed to install instrumentation on AgentSession.prototype', {
|
|
526
|
+
cause: err,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return sdk;
|
|
530
|
+
}
|
|
531
|
+
function attachSpanListener(session, tracer, config, sessionSpanState) {
|
|
532
|
+
const state = {
|
|
533
|
+
rootSpan: undefined,
|
|
534
|
+
rootCtx: undefined,
|
|
535
|
+
llmSpan: undefined,
|
|
536
|
+
llmCtx: undefined,
|
|
537
|
+
toolSpans: new Map(),
|
|
538
|
+
retryCount: 0,
|
|
539
|
+
};
|
|
540
|
+
sessionSpanState.set(session, state);
|
|
541
|
+
session.subscribe((event) => {
|
|
542
|
+
try {
|
|
543
|
+
handleEvent(event, tracer, config, state);
|
|
544
|
+
}
|
|
545
|
+
catch (err) {
|
|
546
|
+
// Must never reach Pi's event dispatcher and destabilize its agent loop. diag.warn, not console (see closeDanglingSpan).
|
|
547
|
+
api_1.diag.warn('[traceroot-pi] instrumentation handler failed (a span may be missing or incomplete):', err);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
function handleEvent(event, tracer, config, state) {
|
|
552
|
+
switch (event.type) {
|
|
553
|
+
case 'agent_start': {
|
|
554
|
+
// Sweep dangling spans from a crashed prior attempt; root is untouched (owned by prompt()).
|
|
555
|
+
sweepDanglingSpans(state);
|
|
556
|
+
// An undefined state.rootSpan means this run bypassed the wrapped prompt() call — do not synthesize one.
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case 'message_start': {
|
|
560
|
+
if (event.message.role !== 'assistant')
|
|
561
|
+
return;
|
|
562
|
+
// A second message_start with no intervening message_end means the previous LLM span was abandoned — force-close it first.
|
|
563
|
+
closeDanglingSpan(state.llmSpan);
|
|
564
|
+
// Falls back to ROOT_CONTEXT, never context.active(): the latter is the host's ambient OTel context, unrelated to this session, and would risk cross-trace contamination.
|
|
565
|
+
const parentCtx = state.rootCtx ?? api_1.ROOT_CONTEXT;
|
|
566
|
+
state.llmSpan = openLlmSpan(tracer, parentCtx, event.message);
|
|
567
|
+
state.llmCtx = api_1.trace.setSpan(parentCtx, state.llmSpan);
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
case 'message_end': {
|
|
571
|
+
if (event.message.role !== 'assistant')
|
|
572
|
+
return;
|
|
573
|
+
if (state.llmSpan)
|
|
574
|
+
closeLlmSpan(state.llmSpan, event.message, config.captureContent);
|
|
575
|
+
state.llmSpan = undefined;
|
|
576
|
+
// llmCtx stays alive on purpose: this turn's tool_execution events fire after message_end but before turn_end, and still parent under the ended LLM span.
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
case 'turn_end': {
|
|
580
|
+
// If a stream error cut the turn short before message_end closed llmSpan, sweep force-closes it (and tool spans); root is untouched.
|
|
581
|
+
sweepDanglingSpans(state);
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
case 'tool_execution_start': {
|
|
585
|
+
// An already-open toolCallId would have its Map slot silently overwritten — force-close first.
|
|
586
|
+
const existing = state.toolSpans.get(event.toolCallId);
|
|
587
|
+
closeDanglingSpan(existing);
|
|
588
|
+
const parentCtx = state.llmCtx ?? state.rootCtx ?? api_1.ROOT_CONTEXT;
|
|
589
|
+
const span = openToolSpan(tracer, parentCtx, event.toolCallId, event.toolName, event.args, config.captureToolIo);
|
|
590
|
+
state.toolSpans.set(event.toolCallId, span);
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
case 'tool_execution_end': {
|
|
594
|
+
const span = state.toolSpans.get(event.toolCallId);
|
|
595
|
+
if (span)
|
|
596
|
+
closeToolSpan(span, event.result, event.isError, config.captureToolIo);
|
|
597
|
+
state.toolSpans.delete(event.toolCallId);
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
case 'agent_end': {
|
|
601
|
+
// Mirrors turn_end's sweep; root is not swept (closing it is proto.prompt's job) — this only stamps output onto whatever is open.
|
|
602
|
+
sweepDanglingSpans(state);
|
|
603
|
+
if (state.rootSpan) {
|
|
604
|
+
stampRootOutput(state.rootSpan, event.messages, config.captureContent);
|
|
605
|
+
}
|
|
606
|
+
if (event.willRetry) {
|
|
607
|
+
state.retryCount += 1;
|
|
608
|
+
}
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
default:
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
//# sourceMappingURL=pi.js.map
|
package/dist/pi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.js","sourceRoot":"","sources":["../src/pi.ts"],"names":[],"mappings":";;;AAmJA,sCAOC;AA+JD,oCAUC;AAGD,0CAcC;AAGD,4CAiBC;AAED,kCAaC;AAED,oCA0BC;AA6BD,oDAkBC;AAED,oCAiCC;AAED,sCAoBC;AAGD,8CASC;AAuED,4EAQC;AAED,0DA4JC;AApvBD,yCAAkC;AAClC,4CAAkG;AAElG,2CAYqB;AACrB,2CAA0C;AAqH7B,QAAA,WAAW,GAAG,+BAA+B,CAAC;AAc3D,SAAgB,aAAa,CAAC,MAAgC;IAC5D,MAAM,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,IAAI,CAAC;IACtD,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,CAAC;IACpD,OAAO;QACL,cAAc;QACd,aAAa;KACd,CAAC;AACJ,CAAC;AAED,MAAM,kBAAkB,GAAG;IACzB,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,8IAA8I;AAC9I,MAAM,aAA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AM,IAAI,KAAK,CAAC,OAAO,IAAI,kBAAY,CAAC;YAChE,MAAM,IAAI,GAAG,YAAY,CACvB,MAAM,EACN,SAAS,EACT,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,aAAa,CACrB,CAAC;YACF,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAC5C,MAAM;QACR,CAAC;QACD,KAAK,oBAAoB,CAAC,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACnD,IAAI,IAAI;gBAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;YACjF,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACzC,MAAM;QACR,CAAC;QACD,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,kIAAkI;YAClI,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACnB,eAAe,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;YACzE,CAAC;YACD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACpB,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;YACxB,CAAC;YACD,MAAM;QACR,CAAC;QACD;YACE,MAAM;IACV,CAAC;AACH,CAAC"}
|
package/dist/spans.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Span as OtelSpan } from '@opentelemetry/api';
|
|
2
|
+
import { StartSpanOptions, SpanUpdate } from './types';
|
|
3
|
+
export interface Span {
|
|
4
|
+
readonly spanId: string;
|
|
5
|
+
readonly traceId: string;
|
|
6
|
+
update(attrs: SpanUpdate): this;
|
|
7
|
+
end(): void;
|
|
8
|
+
startSpan(options: Omit<StartSpanOptions, 'parent'>): Span;
|
|
9
|
+
setError(err: unknown): this;
|
|
10
|
+
}
|
|
11
|
+
/** Wrap an existing OTel span (e.g. the active one) as a Span handle. */
|
|
12
|
+
export declare function wrapSpan(otel: OtelSpan): Span;
|
|
13
|
+
export declare function startSpan(options: StartSpanOptions): Span;
|
|
14
|
+
/** Run fn with `span` as the active span so inner observe()/startSpan() nest under it. */
|
|
15
|
+
export declare function usingSpan<T>(span: Span, fn: () => T): T;
|
|
16
|
+
/** @internal test reset */
|
|
17
|
+
export declare function _resetSpansState(): void;
|
|
18
|
+
//# sourceMappingURL=spans.d.ts.map
|