retrace-sdk 0.3.8 → 0.4.0
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/interceptors/anthropic.js +2 -1
- package/dist/recorder.js +16 -11
- package/dist/resume.js +1 -1
- package/package.json +1 -1
|
@@ -34,7 +34,8 @@ export function installAnthropicInterceptor(onSpan) {
|
|
|
34
34
|
const Anthropic = mod?.Anthropic || mod?.default;
|
|
35
35
|
if (!Anthropic)
|
|
36
36
|
return;
|
|
37
|
-
|
|
37
|
+
// Find Messages prototype without instantiating a client
|
|
38
|
+
const proto = Anthropic.Messages?.prototype || Anthropic.prototype?.messages?.constructor?.prototype;
|
|
38
39
|
if (!proto?.create)
|
|
39
40
|
return;
|
|
40
41
|
originalCreate = proto.create;
|
package/dist/recorder.js
CHANGED
|
@@ -7,8 +7,13 @@ import { installAnthropicInterceptor } from "./interceptors/anthropic.js";
|
|
|
7
7
|
// Shared transport — stays open across multiple traces for resume/replay listening
|
|
8
8
|
let sharedTransport = null;
|
|
9
9
|
function getSharedTransport() {
|
|
10
|
-
if (!sharedTransport)
|
|
10
|
+
if (!sharedTransport) {
|
|
11
11
|
sharedTransport = createTransport();
|
|
12
|
+
// Flush pending data before process exits
|
|
13
|
+
if (typeof process !== "undefined") {
|
|
14
|
+
process.on("beforeExit", () => { sharedTransport?.close(); });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
12
17
|
return sharedTransport;
|
|
13
18
|
}
|
|
14
19
|
export class TraceRecorder {
|
|
@@ -104,16 +109,16 @@ export class TraceRecorder {
|
|
|
104
109
|
export function record(opts) {
|
|
105
110
|
const cfg = getConfig();
|
|
106
111
|
if (!cfg.enabled || Math.random() > cfg.sampleRate) {
|
|
107
|
-
// Return a no-op
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
}
|
|
112
|
+
// Return a typed no-op stub (preserves type safety unlike Proxy)
|
|
113
|
+
return {
|
|
114
|
+
get traceId() { return ""; },
|
|
115
|
+
output: undefined,
|
|
116
|
+
start() { return this; },
|
|
117
|
+
end() { },
|
|
118
|
+
addSpan() { },
|
|
119
|
+
startSpan(name) { const { SpanBuilder } = require("./trace.js"); return new SpanBuilder(name, "llm_call"); },
|
|
120
|
+
endSpan() { },
|
|
121
|
+
};
|
|
117
122
|
}
|
|
118
123
|
return new TraceRecorder(opts);
|
|
119
124
|
}
|
package/dist/resume.js
CHANGED
|
@@ -49,7 +49,7 @@ export function handleResume(command) {
|
|
|
49
49
|
catch (err) {
|
|
50
50
|
console.error("[retrace] Cascade replay failed:", err);
|
|
51
51
|
}
|
|
52
|
-
})();
|
|
52
|
+
})().catch((err) => console.error("[retrace] Replay IIFE unhandled:", err));
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
export function parseResumeMessage(msg) {
|