retrace-sdk 0.2.1 → 0.2.3
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 +4 -0
- package/dist/interceptors/openai.js +6 -6
- package/dist/recorder.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,10 @@ configure({ apiKey: "rt_live_...", sampleRate: 0.1 }); // Record 10% of traces
|
|
|
101
101
|
|
|
102
102
|
## Changelog
|
|
103
103
|
|
|
104
|
+
### 0.2.2
|
|
105
|
+
|
|
106
|
+
- **Fixed** — OpenAI interceptor no longer creates dummy client instance to find prototype
|
|
107
|
+
|
|
104
108
|
### 0.2.1
|
|
105
109
|
|
|
106
110
|
- **Offline buffer** — stores up to 1000 messages when WebSocket disconnects, flushes on reconnect
|
|
@@ -40,13 +40,13 @@ export function installOpenAIInterceptor(onSpan) {
|
|
|
40
40
|
const mod = openaiMod;
|
|
41
41
|
const proto = mod?.OpenAI?.Chat?.Completions?.prototype || mod?.default?.Chat?.Completions?.prototype;
|
|
42
42
|
if (!proto?.create) {
|
|
43
|
-
// Try
|
|
43
|
+
// Try accessing prototype chain without instantiation
|
|
44
44
|
const OpenAI = mod?.OpenAI || mod?.default;
|
|
45
|
-
if (OpenAI) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
originalCreate =
|
|
49
|
-
|
|
45
|
+
if (OpenAI?.prototype?.chat) {
|
|
46
|
+
const chatProto = Object.getPrototypeOf(Object.getPrototypeOf(OpenAI.prototype.chat)?.completions || {});
|
|
47
|
+
if (chatProto?.create) {
|
|
48
|
+
originalCreate = chatProto.create;
|
|
49
|
+
chatProto.create = createPatchedCreate();
|
|
50
50
|
installed = true;
|
|
51
51
|
}
|
|
52
52
|
}
|
package/dist/recorder.js
CHANGED
|
@@ -95,9 +95,16 @@ export class TraceRecorder {
|
|
|
95
95
|
export function record(opts) {
|
|
96
96
|
const cfg = getConfig();
|
|
97
97
|
if (!cfg.enabled || Math.random() > cfg.sampleRate) {
|
|
98
|
-
// Return a no-op
|
|
98
|
+
// Return a no-op that silently swallows all method calls
|
|
99
|
+
const methods = new Set(["start", "end", "startSpan", "endSpan", "addSpan"]);
|
|
99
100
|
const noop = {};
|
|
100
|
-
return new Proxy(noop, {
|
|
101
|
+
return new Proxy(noop, {
|
|
102
|
+
get: (_t, prop) => {
|
|
103
|
+
if (typeof prop === "string" && methods.has(prop))
|
|
104
|
+
return () => noop;
|
|
105
|
+
return undefined;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
101
108
|
}
|
|
102
109
|
return new TraceRecorder(opts);
|
|
103
110
|
}
|