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.
@@ -34,7 +34,8 @@ export function installAnthropicInterceptor(onSpan) {
34
34
  const Anthropic = mod?.Anthropic || mod?.default;
35
35
  if (!Anthropic)
36
36
  return;
37
- const proto = Anthropic.Messages?.prototype || Object.getPrototypeOf(new Anthropic({ apiKey: "dummy" }).messages);
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 that silently swallows all method calls
108
- const methods = new Set(["start", "end", "startSpan", "endSpan", "addSpan"]);
109
- const noop = {};
110
- return new Proxy(noop, {
111
- get: (_t, prop) => {
112
- if (typeof prop === "string" && methods.has(prop))
113
- return () => noop;
114
- return undefined;
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retrace-sdk",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "description": "The execution replay engine for AI agents. Record, replay, fork, and share agent executions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",