retrace-sdk 0.16.8 → 0.16.9
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/config.js +1 -1
- package/dist/recorder.js +7 -0
- package/dist/telemetry.d.ts +7 -0
- package/dist/telemetry.js +36 -11
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -63,7 +63,7 @@ export function configure(opts) {
|
|
|
63
63
|
if (config.enabled) {
|
|
64
64
|
void import("./interceptors/install.js").then((m) => m.ensureInterceptorsInstalled()).catch(() => { });
|
|
65
65
|
}
|
|
66
|
-
void import("./telemetry.js").then((m) => m.track("
|
|
66
|
+
void import("./telemetry.js").then((m) => m.track("sdk_init", { has_api_key: !!config.apiKey, enabled: config.enabled })).catch(() => { });
|
|
67
67
|
return config;
|
|
68
68
|
}
|
|
69
69
|
export function requireApiKey() {
|
package/dist/recorder.js
CHANGED
|
@@ -184,6 +184,13 @@ export class TraceRecorder {
|
|
|
184
184
|
// lossy / capture_complete:false). Only a naturally-drained run produces a clean terminal.
|
|
185
185
|
...(opts?.terminatedEarly ? { terminated_early: true } : {}),
|
|
186
186
|
});
|
|
187
|
+
// Anonymous usage analytics (fire-and-forget; never throws): record success/failure + which
|
|
188
|
+
// provider families ran. No PII, no user content.
|
|
189
|
+
try {
|
|
190
|
+
const dict = this.builder.toDict();
|
|
191
|
+
void import("./telemetry.js").then((m) => m.trackRecord(String(data.status), dict.spans ?? [], dict.metadata ?? {})).catch(() => { });
|
|
192
|
+
}
|
|
193
|
+
catch { /* never affect the user's program */ }
|
|
187
194
|
// Restore the enclosing trace's fallback (e.g. the ambient init() recorder) instead of nulling.
|
|
188
195
|
setActiveRecorderFallback(this.prevFallback, this.prevFallbackSink);
|
|
189
196
|
this.prevFallback = null;
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/** Coarse provider family from a model name (analytics only — never the key or content). */
|
|
2
|
+
export declare function providerOf(model?: string | null): string;
|
|
1
3
|
export declare function track(event: string, fields?: Record<string, string | number | boolean>): void;
|
|
4
|
+
/** Emit record_success / record_failure with anonymous, aggregate-only fields (span count, provider
|
|
5
|
+
* families used, whether the run was resumable / a cascade replay). Never throws. */
|
|
6
|
+
export declare function trackRecord(status: string, spans: Array<{
|
|
7
|
+
model?: string | null;
|
|
8
|
+
}>, metadata?: Record<string, unknown>): void;
|
package/dist/telemetry.js
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anonymous,
|
|
2
|
+
* Anonymous, always-on diagnostic telemetry.
|
|
3
3
|
*
|
|
4
4
|
* Sends NO user code, API keys, prompts, responses, or personal information — only the SDK version,
|
|
5
|
-
* the runtime/OS family, an anonymous per-process id, and event/error *categories
|
|
6
|
-
* API's internal
|
|
7
|
-
* service="sdk-typescript"
|
|
5
|
+
* the runtime/OS family, an anonymous per-process id, and event/error *categories*. Events are POSTed
|
|
6
|
+
* to the Retrace API's internal ingest, which forwards them to PostHog (and the logging platform)
|
|
7
|
+
* under service="sdk-typescript" — so the SDK NEVER holds any analytics key (SDK → Retrace API →
|
|
8
|
+
* PostHog).
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* Fire-and-forget: never blocks the user's program, never throws. Anonymous by construction (no PII,
|
|
11
|
+
* random per-process id) and intentionally NOT user-disableable.
|
|
10
12
|
*/
|
|
11
13
|
import os from "node:os";
|
|
12
14
|
import { getConfig } from "./config.js";
|
|
13
15
|
// Per-process random id — anonymous, not linked to any account, user, or machine identity.
|
|
14
16
|
const ANON_ID = Math.random().toString(16).slice(2, 18);
|
|
15
|
-
const DISABLED = new Set(["0", "false", "no", "off"]);
|
|
16
17
|
// Keep in sync with package.json version.
|
|
17
|
-
const SDK_VERSION = "0.16.
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const SDK_VERSION = "0.16.9";
|
|
19
|
+
/** Coarse provider family from a model name (analytics only — never the key or content). */
|
|
20
|
+
export function providerOf(model) {
|
|
21
|
+
const m = (model || "").toLowerCase();
|
|
22
|
+
if (!m)
|
|
23
|
+
return "";
|
|
24
|
+
if (m.startsWith("gemini") || m.includes("google"))
|
|
25
|
+
return "google";
|
|
26
|
+
if (/^(gpt|o1|o3|o4|chatgpt|text-embedding|davinci)/.test(m))
|
|
27
|
+
return "openai";
|
|
28
|
+
if (m.includes("claude"))
|
|
29
|
+
return "anthropic";
|
|
30
|
+
return "other";
|
|
20
31
|
}
|
|
21
32
|
export function track(event, fields = {}) {
|
|
22
|
-
if (!enabled())
|
|
23
|
-
return;
|
|
24
33
|
try {
|
|
25
34
|
const base = (getConfig().baseUrl || "https://api.retraceai.tech").replace(/\/$/, "");
|
|
26
35
|
const body = JSON.stringify({
|
|
@@ -49,3 +58,19 @@ export function track(event, fields = {}) {
|
|
|
49
58
|
/* telemetry must never affect the user's program */
|
|
50
59
|
}
|
|
51
60
|
}
|
|
61
|
+
/** Emit record_success / record_failure with anonymous, aggregate-only fields (span count, provider
|
|
62
|
+
* families used, whether the run was resumable / a cascade replay). Never throws. */
|
|
63
|
+
export function trackRecord(status, spans, metadata = {}) {
|
|
64
|
+
try {
|
|
65
|
+
const provs = Array.from(new Set(spans.map((s) => providerOf(s.model)).filter(Boolean)));
|
|
66
|
+
track(status === "completed" ? "record_success" : "record_failure", {
|
|
67
|
+
spans: spans.length,
|
|
68
|
+
providers: provs.join(",") || "none",
|
|
69
|
+
resumable: !!metadata._resumable,
|
|
70
|
+
cascade: !!metadata._cascade_replay,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
/* never throw */
|
|
75
|
+
}
|
|
76
|
+
}
|