retrace-sdk 0.3.6 → 0.3.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/dist/recorder.js +9 -2
- package/package.json +1 -1
package/dist/recorder.js
CHANGED
|
@@ -4,6 +4,13 @@ import { createTransport } from "./transport.js";
|
|
|
4
4
|
import { installGeminiInterceptor } from "./interceptors/gemini.js";
|
|
5
5
|
import { installOpenAIInterceptor } from "./interceptors/openai.js";
|
|
6
6
|
import { installAnthropicInterceptor } from "./interceptors/anthropic.js";
|
|
7
|
+
// Shared transport — stays open across multiple traces for resume/replay listening
|
|
8
|
+
let sharedTransport = null;
|
|
9
|
+
function getSharedTransport() {
|
|
10
|
+
if (!sharedTransport)
|
|
11
|
+
sharedTransport = createTransport();
|
|
12
|
+
return sharedTransport;
|
|
13
|
+
}
|
|
7
14
|
export class TraceRecorder {
|
|
8
15
|
builder;
|
|
9
16
|
transport;
|
|
@@ -12,7 +19,7 @@ export class TraceRecorder {
|
|
|
12
19
|
constructor(opts) {
|
|
13
20
|
requireApiKey();
|
|
14
21
|
this.builder = new TraceBuilder();
|
|
15
|
-
this.transport =
|
|
22
|
+
this.transport = getSharedTransport();
|
|
16
23
|
const cfg = getConfig();
|
|
17
24
|
if (cfg.projectId)
|
|
18
25
|
this.builder.setProjectId(cfg.projectId);
|
|
@@ -43,7 +50,7 @@ export class TraceRecorder {
|
|
|
43
50
|
total_tokens: data.total_tokens,
|
|
44
51
|
total_cost: data.total_cost,
|
|
45
52
|
});
|
|
46
|
-
|
|
53
|
+
// Shared transport stays open for resume/replay listening
|
|
47
54
|
}
|
|
48
55
|
addSpan(span) {
|
|
49
56
|
span.trace_id = this.builder.id;
|