Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
otel: Langfuse is set up from its host and the project's two keys
yetoneef0a03e137db
diff --git a/docs/reference.md b/docs/reference.mdindex a0b4ee646..e5ec56e73 100644--- a/docs/reference.md+++ b/docs/reference.md@@ -2827,10 +2827,23 @@ MAGPIE_OTEL_ENABLED=true MAGPIE_OTEL_ENDPOINT=http://localhost:4318 magpie servekeeps them entire rather than cut at 256 KB. A long reply is written to atemporary file; a body too large for the collector is still refused.-For Langfuse, use `https://<your-langfuse-host>/api/public/otel` as the base-URL and `Authorization=Basic%20<base64(public-key:secret-key)>` as the header.-Leave metrics off. This uses Langfuse's OTLP ingestion endpoint. For Langfuse-v4, add the header `x-langfuse-ingestion-version=4` for real-time ingestion.+For Langfuse, pick **Collector › Langfuse**, then the host (Cloud EU+`https://cloud.langfuse.com`, Cloud US `https://us.cloud.langfuse.com`, or+**Self-hosted** with your own address, which also takes another Langfuse+Cloud region such as `https://jp.cloud.langfuse.com`) and the project's public+and secret keys (Langfuse › Settings › API Keys). magpie saves them as the+endpoint `<host>/api/public/otel` and the header+`Authorization: Basic <base64(public-key:secret-key)>`, kept with the other+OTLP headers (left out of a backup without keys). Nothing is saved until both+keys are there. A first setup also adds `x-langfuse-ingestion-version: 4`+(Langfuse's docs: without it, OTLP data can show up to 10 minutes late), turns+metrics off, since Langfuse takes traces only, and turns export on. A Langfuse+endpoint set up by hand opens in this view with its keys filled in, and+changing a key or the host keeps every other header and the metrics and+export choices as they were. Switching from another collector leaves that+collector's headers behind. For `magpie serve`, the same values go in the+environment: `MAGPIE_OTEL_ENDPOINT=https://cloud.langfuse.com/api/public/otel`+and `MAGPIE_OTEL_HEADERS=Authorization=Basic%20<base64(public-key:secret-key)>,x-langfuse-ingestion-version=4`.Traces include agent, provider, model, token counts (including cache andreasoning), HTTP status, timing, and route ID. Attempts with the same route IDdiff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.cssindex facc964ef..5ce0899e5 100644--- a/internal/gui/assets/app.css+++ b/internal/gui/assets/app.css@@ -3390,6 +3390,8 @@ img.nav-ic { border-radius: 3px; object-fit: contain; }#otelList .otel-stacked > .val { width: 100%; max-width: none; margin-left: 0; }#otelList input.words { width: 100%; }#otelList .otel-stacked .segs { margin-left: 0; max-width: 100%; flex-wrap: wrap; }+#otelList .otel-host, #otelList .otel-keys { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; width: 100%; }+#otelList .otel-host > [hidden] { display: none; }#otelList .otel-env { padding: 12px 14px; border-top: 1px solid var(--line-2); font-size: 11.5px; color: var(--muted); }.session-terminal-select, .pref-pick { max-width: min(230px, 45%); height: 26px; color: var(--fg); }diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 3c165294a..180ee1951 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -22262,85 +22262,6 @@ function openMaskRecord(key) {show("masking").then((went) => { if (went !== false && key && view === "masking") magpie.call("masking", "focus", key); });}-function renderOTel(s, keep) {- const page = $("#otelList");- page.replaceChildren();- let config = { ...(s.otel || {}) };- // a heading over a card of its own, as on every other Settings tab- let box;- const section = (name) => {- const head = el("div", "row-head");- head.append(el("span", "label", t(name)));- box = el("div", "list prefs");- page.append(head, box);- };- const row = (id, name, sub, control) => {- const r = el("div", "row pref");- r.id = id;- const who = el("div", "who");- who.append(el("div", "name", t(name)), el("div", "sub", t(sub)));- const val = el("div", "val");- val.append(control);- r.append(who, val);- if (id === "otelEndpointRow" || id === "otelHeadersRow" || id === "otelBodiesRow") r.classList.add("otel-stacked");- box.append(r);- };- const save = (change) => {- config = { ...config, ...change };- savePrefs({ ...keep, otel: { ...config } });- };- section("Collector connection");- row("otelExportRow", "OTLP export", "Send traces to your collector. Choose what to include below; account credentials stay local",- segs([["off", t("Off")], ["on", t("On")]], config.enabled ? "on" : "off", (v) => save({ enabled: v === "on" })));- const endpoint = input(config.endpoint || "", "http://localhost:4318", "url");- endpoint.className = "words";- endpoint.setAttribute("aria-label", t("OTLP endpoint"));- endpoint.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") endpoint.blur(); };- endpoint.onchange = () => save({ endpoint: endpoint.value.trim().replace(/\/+$/, "") });- row("otelEndpointRow", "OTLP endpoint", "Base URL of your collector, or Langfuse's /api/public/otel endpoint", endpoint);- const headers = input(Object.entries(config.headers || {}).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join(","), "Authorization=Bearer%20token", "password");- headers.className = "words";- headers.setAttribute("aria-label", t("OTLP headers"));- headers.autocomplete = "off";- headers.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") headers.blur(); };- headers.onchange = () => {- const values = {};- try {- for (const part of headers.value.split(",").filter((p) => p.trim())) {- const i = part.indexOf("=");- if (i < 1) throw new Error(t("Use comma-separated name=value headers"));- values[part.slice(0, i).trim()] = decodeURIComponent(part.slice(i + 1).trim());- }- save({ headers: values });- } catch (e) { toast(e.message, true); }- };- row("otelHeadersRow", "OTLP headers", "Comma-separated name=value pairs; percent-encode spaces and commas in values", headers);- section("Export scope");- row("otelMetricsRow", "Export metrics", "Also send duration and token histograms. Leave off for a traces-only service such as Langfuse",- segs([["off", t("Off")], ["on", t("On")]], config.metrics ? "on" : "off", (v) => save({ metrics: v === "on" })));- row("otelSessionsRow", "Trace agent conversations", "Reads all local sessions from Codex, Pi, Oh My Pi, Claude Code, Cowork, OpenCode and Gemini CLI, including calls not routed through Magpie. When content is included below, exports prompts, replies, tool arguments and tool output (including file contents and command output), with secrets masked",- segs([["off", t("Off")], ["on", t("On")]], config.sessions ? "on" : "off", (v) => save({ sessions: v === "on" })));- section("Trace content");- const mode = !config.bodies ? "metadata" : config.bodiesWhole ? "full" : "limited";- const content = segs([["metadata", t("Metadata only")], ["limited", t("Up to 256 KB")], ["full", t("Full content")]], mode,- (v) => {- for (const button of content.querySelectorAll("button")) button.setAttribute("aria-pressed", String(button.classList.contains("on")));- save({ bodies: v !== "metadata", bodiesWhole: v === "full" });- });- content.setAttribute("role", "group");- content.setAttribute("aria-label", t("Request and response content"));- for (const [i, button] of [...content.querySelectorAll("button")].entries()) {- button.setAttribute("aria-pressed", String(["metadata", "limited", "full"][i] === mode));- }- const descriptions = {- metadata: "Send model, token, status and timing metadata only. Prompts, replies and tool content stay local",- limited: "Include requests and replies as trace input and output, with secrets masked. Each body is limited to 256 KB",- full: "Include complete requests and replies, with secrets masked. Large content may be refused by your collector",- };- row("otelBodiesRow", "Request and response content", descriptions[mode], content);- if (s.otelEnv) box.append(el("div", "sub otel-env", t("Environment variables override these saved OTLP preferences")));-}-// renderRedactRules: the user's own rules for secrets magpie's don't know, a// gateway's oc_sk_… key say (#195) — one row each, and a row to add one by a// prefix or a regular expression. They are set on their own, all of them eachdiff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.jsindex baab0174f..66db26b18 100644--- a/internal/gui/assets/i18n.js+++ b/internal/gui/assets/i18n.js@@ -925,6 +925,8 @@ const I18N = {"Collector connection": "采集服务连接","Export scope": "导出范围","Trace content": "链路内容",+ "Collector": "采集服务",+ "Secret key": "私钥","Send traces to your collector. Choose what to include below; account credentials stay local": "向采集服务发送链路数据,在下方选择导出范围和内容;账号凭据留在本机","Request and response content": "请求和响应内容","Metadata only": "仅元数据",@@ -4896,6 +4898,8 @@ const I18N = {"Collector connection": "採集服務連線","Export scope": "匯出範圍","Trace content": "鏈路內容",+ "Collector": "採集服務",+ "Secret key": "私鑰","Send traces to your collector. Choose what to include below; account credentials stay local": "向採集服務傳送鏈路資料,在下方選擇匯出範圍和內容;帳號憑據留在本機","Request and response content": "請求和回應內容","Metadata only": "僅後設資料",@@ -8839,6 +8843,8 @@ const I18N = {"Collector connection": "コレクターへの接続","Export scope": "エクスポート範囲","Trace content": "トレース内容",+ "Collector": "コレクター",+ "Secret key": "シークレットキー","Send traces to your collector. Choose what to include below; account credentials stay local": "トレースをコレクターに送信します。含める内容は下で選択してください。アカウントの認証情報はローカルに残ります","Request and response content": "リクエストとレスポンスの内容","Metadata only": "メタデータのみ",@@ -12796,6 +12802,8 @@ const I18N = {"Collector connection": "Collector-Verbindung","Export scope": "Exportumfang","Trace content": "Trace-Inhalt",+ "Collector": "Collector",+ "Secret key": "Geheimer Schlüssel","Send traces to your collector. Choose what to include below; account credentials stay local": "Traces an Ihren Collector senden. Unten festlegen, was enthalten ist; Zugangsdaten der Konten bleiben lokal","Request and response content": "Inhalt von Anfrage und Antwort","Metadata only": "Nur Metadaten",diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.htmlindex 0f8d11896..4da6b6476 100644--- a/internal/gui/assets/index.html+++ b/internal/gui/assets/index.html@@ -487,6 +487,7 @@<script src="plugins/usage/client.js"></script><script src="plugins/redact/i18n.js"></script><script src="plugins/redact/client.js"></script>+<script src="plugins/otel/i18n.js"></script><script src="purposes.js"></script><script src="app.js"></script><script src="plugins.js"></script>@@ -494,6 +495,7 @@<script src="context.js"></script><script src="plugins/usage/page.js"></script><script src="plugins/redact/page.js"></script>+<script src="plugins/otel/page.js"></script><script src="start.js"></script></body></html>diff --git a/internal/gui/assets/plugins/otel/i18n.js b/internal/gui/assets/plugins/otel/i18n.jsnew file mode 100644index 000000000..af8f92bc2--- /dev/null+++ b/internal/gui/assets/plugins/otel/i18n.js@@ -0,0 +1,48 @@+// Settings › Observability's own words in each language, the English the+// key: the kernel adds them to i18n.js's (magpie.strings).+magpie.strings({+ zh: {+ "Langfuse needs only its host and your project's keys; any other OTLP/HTTP collector takes its address and headers": "Langfuse 只需要地址和项目密钥;其他 OTLP/HTTP 采集服务填地址和请求头",+ "Langfuse host": "Langfuse 地址",+ "Langfuse Cloud's region, or the address of your own Langfuse": "Langfuse Cloud 的区域,或你自己部署的 Langfuse 地址",+ "Cloud EU": "Cloud 欧洲",+ "Cloud US": "Cloud 美国",+ "Self-hosted": "自部署",+ "Public key": "公钥",+ "From your Langfuse project's Settings › API Keys. Traces go to {url}": "在 Langfuse 项目的 Settings › API Keys 里获取。链路数据发往 {url}",+ "Enter your Langfuse address, such as https://langfuse.example.com": "请填写 Langfuse 地址,比如 https://langfuse.example.com",+ },+ "zh-TW": {+ "Langfuse needs only its host and your project's keys; any other OTLP/HTTP collector takes its address and headers": "Langfuse 只需要位址和專案金鑰;其他 OTLP/HTTP 採集服務填位址和請求標頭",+ "Langfuse host": "Langfuse 位址",+ "Langfuse Cloud's region, or the address of your own Langfuse": "Langfuse Cloud 的區域,或你自行部署的 Langfuse 位址",+ "Cloud EU": "Cloud 歐洲",+ "Cloud US": "Cloud 美國",+ "Self-hosted": "自行部署",+ "Public key": "公鑰",+ "From your Langfuse project's Settings › API Keys. Traces go to {url}": "在 Langfuse 專案的 Settings › API Keys 取得。鏈路資料傳送到 {url}",+ "Enter your Langfuse address, such as https://langfuse.example.com": "請填寫 Langfuse 位址,例如 https://langfuse.example.com",+ },+ ja: {+ "Langfuse needs only its host and your project's keys; any other OTLP/HTTP collector takes its address and headers": "Langfuse はホストとプロジェクトのキーだけで設定できます。ほかの OTLP/HTTP コレクターはアドレスとヘッダーを入力します",+ "Langfuse host": "Langfuse のホスト",+ "Langfuse Cloud's region, or the address of your own Langfuse": "Langfuse Cloud のリージョン、またはセルフホストした Langfuse のアドレス",+ "Cloud EU": "Cloud EU",+ "Cloud US": "Cloud US",+ "Self-hosted": "セルフホスト",+ "Public key": "公開キー",+ "From your Langfuse project's Settings › API Keys. Traces go to {url}": "Langfuse プロジェクトの Settings › API Keys で取得します。トレースの送信先は {url} です",+ "Enter your Langfuse address, such as https://langfuse.example.com": "Langfuse のアドレスを入力してください(例: https://langfuse.example.com)",+ },+ de: {+ "Langfuse needs only its host and your project's keys; any other OTLP/HTTP collector takes its address and headers": "Langfuse braucht nur seinen Host und die Schlüssel Ihres Projekts; jeder andere OTLP/HTTP-Collector bekommt Adresse und Header",+ "Langfuse host": "Langfuse-Host",+ "Langfuse Cloud's region, or the address of your own Langfuse": "Die Region von Langfuse Cloud oder die Adresse Ihres eigenen Langfuse",+ "Cloud EU": "Cloud EU",+ "Cloud US": "Cloud US",+ "Self-hosted": "Selbst gehostet",+ "Public key": "Öffentlicher Schlüssel",+ "From your Langfuse project's Settings › API Keys. Traces go to {url}": "Aus Settings › API Keys Ihres Langfuse-Projekts. Traces gehen an {url}",+ "Enter your Langfuse address, such as https://langfuse.example.com": "Geben Sie Ihre Langfuse-Adresse ein, z. B. https://langfuse.example.com",+ },+});diff --git a/internal/gui/assets/plugins/otel/page.js b/internal/gui/assets/plugins/otel/page.jsnew file mode 100644index 000000000..0275931e2--- /dev/null+++ b/internal/gui/assets/plugins/otel/page.js@@ -0,0 +1,189 @@+// Settings › Observability's code (the otel plugin's page): run after app.js,+// whose helpers it shares (el, segs, input, savePrefs), and before start.js+// draws Settings. The connection is either any OTLP collector, set by its+// address and headers, or Langfuse, set by what only the user knows: where it+// is and the project's two keys. Langfuse's address, its Basic sign-in and+// its ingestion header are made from those, into the same endpoint and+// headers settings, so the secret is kept where it always was.++const LANGFUSE_PATH = "/api/public/otel";+const LANGFUSE_HOSTS = [["https://cloud.langfuse.com", "Cloud EU"], ["https://us.cloud.langfuse.com", "Cloud US"]];+// otelKind is the user's pick while the page is open ("otlp" or "langfuse"),+// null for what the saved endpoint says; lfDraft holds keys typed but not yet+// saved, so a redraw doesn't drop them+let otelKind = null, lfDraft = null;+// the rows whose control takes a line of its own under their words+const OTEL_STACKED = ["otelEndpointRow", "otelHeadersRow", "otelBodiesRow", "otelLangfuseHostRow", "otelLangfuseKeysRow"];++// langfuseOf: the host and keys a saved config has, or null for an endpoint+// that isn't Langfuse's OTLP one+function langfuseOf(config) {+ const endpoint = (config.endpoint || "").replace(/\/+$/, "");+ if (!endpoint.endsWith(LANGFUSE_PATH)) return null;+ let pk = "", sk = "";+ const auth = Object.entries(config.headers || {}).find(([k]) => k.toLowerCase() === "authorization")?.[1] || "";+ const basic = /^Basic\s+(\S+)$/i.exec(auth.trim());+ if (basic) {+ try {+ const pair = atob(basic[1]), i = pair.indexOf(":");+ if (i > 0) { pk = pair.slice(0, i); sk = pair.slice(i + 1); }+ } catch {}+ }+ return { host: endpoint.slice(0, -LANGFUSE_PATH.length), pk, sk };+}++// langfuseHost: a typed host as a base URL (scheme added, Langfuse's OTLP+// path taken off if pasted), "" for one that isn't an http(s) address+function langfuseHost(v) {+ let h = v.trim().replace(/\/+$/, "");+ if (h.endsWith(LANGFUSE_PATH)) h = h.slice(0, -LANGFUSE_PATH.length);+ if (h && !/^[a-z][a-z0-9+.-]*:\/\//i.test(h)) h = "https://" + h;+ try {+ const u = new URL(h);+ return /^https?:$/.test(u.protocol) && u.hostname && !u.search && !u.hash && !u.username ? h : "";+ } catch { return ""; }+}++function renderOTel(s, keep) {+ const page = $("#otelList");+ page.replaceChildren();+ let config = { ...(s.otel || {}) };+ const saved = langfuseOf(config);+ const kind = otelKind || (saved ? "langfuse" : "otlp");+ // a heading over a card of its own, as on every other Settings tab+ let box;+ const section = (name) => {+ const head = el("div", "row-head");+ head.append(el("span", "label", t(name)));+ box = el("div", "list prefs");+ page.append(head, box);+ };+ const row = (id, name, sub, control) => {+ const r = el("div", "row pref");+ r.id = id;+ const who = el("div", "who");+ who.append(el("div", "name", t(name)), el("div", "sub", sub));+ const val = el("div", "val");+ val.append(control);+ r.append(who, val);+ if (OTEL_STACKED.includes(id)) r.classList.add("otel-stacked");+ box.append(r);+ return r;+ };+ const save = (change) => {+ otelKind = kind; // what the user is editing stays on screen as they save+ config = { ...config, ...change };+ savePrefs({ ...keep, otel: { ...config } });+ };+ const field = (value, placeholder, type, label) => {+ const f = input(value, placeholder, type);+ f.className = "words";+ f.setAttribute("aria-label", t(label));+ f.autocomplete = "off";+ f.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") f.blur(); };+ return f;+ };+ section("Collector connection");+ row("otelExportRow", "OTLP export", t("Send traces to your collector. Choose what to include below; account credentials stay local"),+ segs([["off", t("Off")], ["on", t("On")]], config.enabled ? "on" : "off", (v) => save({ enabled: v === "on" })));+ row("otelKindRow", "Collector", t("Langfuse needs only its host and your project's keys; any other OTLP/HTTP collector takes its address and headers"),+ segs([["otlp", "OTLP"], ["langfuse", "Langfuse"]], kind, (v) => { otelKind = v; renderOTel(s, keep); }));+ if (kind === "langfuse") renderLangfuse(saved, config, save, row, field);+ else {+ const endpoint = field(config.endpoint || "", "http://localhost:4318", "url", "OTLP endpoint");+ endpoint.onchange = () => save({ endpoint: endpoint.value.trim().replace(/\/+$/, "") });+ row("otelEndpointRow", "OTLP endpoint", t("Base URL of your collector, or Langfuse's /api/public/otel endpoint"), endpoint);+ const headers = field(Object.entries(config.headers || {}).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join(","), "Authorization=Bearer%20token", "password", "OTLP headers");+ headers.onchange = () => {+ const values = {};+ try {+ for (const part of headers.value.split(",").filter((p) => p.trim())) {+ const i = part.indexOf("=");+ if (i < 1) throw new Error(t("Use comma-separated name=value headers"));+ values[part.slice(0, i).trim()] = decodeURIComponent(part.slice(i + 1).trim());+ }+ save({ headers: values });+ } catch (e) { toast(e.message, true); }+ };+ row("otelHeadersRow", "OTLP headers", t("Comma-separated name=value pairs; percent-encode spaces and commas in values"), headers);+ }+ section("Export scope");+ row("otelMetricsRow", "Export metrics", t("Also send duration and token histograms. Leave off for a traces-only service such as Langfuse"),+ segs([["off", t("Off")], ["on", t("On")]], config.metrics ? "on" : "off", (v) => save({ metrics: v === "on" })));+ row("otelSessionsRow", "Trace agent conversations", t("Reads all local sessions from Codex, Pi, Oh My Pi, Claude Code, Cowork, OpenCode and Gemini CLI, including calls not routed through Magpie. When content is included below, exports prompts, replies, tool arguments and tool output (including file contents and command output), with secrets masked"),+ segs([["off", t("Off")], ["on", t("On")]], config.sessions ? "on" : "off", (v) => save({ sessions: v === "on" })));+ section("Trace content");+ const mode = !config.bodies ? "metadata" : config.bodiesWhole ? "full" : "limited";+ const content = segs([["metadata", t("Metadata only")], ["limited", t("Up to 256 KB")], ["full", t("Full content")]], mode,+ (v) => {+ for (const button of content.querySelectorAll("button")) button.setAttribute("aria-pressed", String(button.classList.contains("on")));+ save({ bodies: v !== "metadata", bodiesWhole: v === "full" });+ });+ content.setAttribute("role", "group");+ content.setAttribute("aria-label", t("Request and response content"));+ for (const [i, button] of [...content.querySelectorAll("button")].entries()) {+ button.setAttribute("aria-pressed", String(["metadata", "limited", "full"][i] === mode));+ }+ const descriptions = {+ metadata: "Send model, token, status and timing metadata only. Prompts, replies and tool content stay local",+ limited: "Include requests and replies as trace input and output, with secrets masked. Each body is limited to 256 KB",+ full: "Include complete requests and replies, with secrets masked. Large content may be refused by your collector",+ };+ row("otelBodiesRow", "Request and response content", t(descriptions[mode]), content);+ if (s.otelEnv) box.append(el("div", "sub otel-env", t("Environment variables override these saved OTLP preferences")));+}++// renderLangfuse: Langfuse's host and keys. Nothing is saved until both keys+// are there; then the endpoint and the Basic header are made from them, and+// a first setup also adds the ingestion header (Langfuse's docs: without it+// OTLP data can show up to 10 minutes late), turns metrics off (Langfuse+// takes traces only) and export on. Every other header, and an ingestion+// header the user set themselves, is kept as it was.+function renderLangfuse(saved, config, save, row, field) {+ if (lfDraft && saved && lfDraft.pk === saved.pk && lfDraft.sk === saved.sk && lfDraft.host === saved.host) lfDraft = null;+ const d = lfDraft || { host: saved?.host || LANGFUSE_HOSTS[0][0], pk: saved?.pk || "", sk: saved?.sk || "" };+ const preset = LANGFUSE_HOSTS.some(([h]) => h === d.host) ? d.host : "other";+ const commit = () => {+ d.pk = d.pk.trim(); d.sk = d.sk.trim();+ lfDraft = { ...d };+ const host = langfuseHost(d.host);+ if (!host) return void toast(t("Enter your Langfuse address, such as https://langfuse.example.com"), true);+ lfDraft.host = d.host = host;+ if (!d.pk || !d.sk) return;+ // a first setup: no Langfuse endpoint saved yet, or one with no sign-in.+ // Another collector's headers are its own, never sent to Langfuse+ const first = !saved || !Object.keys(config.headers || {}).some((k) => k.toLowerCase() === "authorization");+ const headers = {};+ let version = false;+ for (const [k, v] of Object.entries(saved ? config.headers || {} : {})) {+ if (k.toLowerCase() === "authorization") continue;+ if (k.toLowerCase() === "x-langfuse-ingestion-version") version = true;+ headers[k] = v;+ }+ headers.Authorization = "Basic " + btoa(unescape(encodeURIComponent(d.pk + ":" + d.sk)));+ if (!version && first) headers["x-langfuse-ingestion-version"] = "4";+ save({ endpoint: host + LANGFUSE_PATH, headers, ...(first ? { metrics: false, enabled: true } : {}) });+ };+ const other = field(preset === "other" ? d.host : "", "https://langfuse.example.com", "url", "Langfuse host");+ other.onchange = () => { d.host = other.value; commit(); };+ other.hidden = preset !== "other";+ const where = el("div", "otel-host");+ where.append(segs([...LANGFUSE_HOSTS.map(([h, name]) => [h, t(name)]), ["other", t("Self-hosted")]], preset, (v) => {+ other.hidden = v !== "other";+ d.host = v === "other" ? other.value : v;+ lfDraft = { ...d };+ if (v === "other") return void other.focus({ preventScroll: true });+ commit();+ }), other);+ row("otelLangfuseHostRow", "Langfuse host", t("Langfuse Cloud's region, or the address of your own Langfuse"), where);+ const pk = field(d.pk, "pk-lf-…", "text", "Public key");+ pk.oninput = () => { d.pk = pk.value; lfDraft = { ...d }; };+ pk.onchange = commit;+ const sk = field(d.sk, "sk-lf-…", "password", "Secret key");+ sk.oninput = () => { d.sk = sk.value; lfDraft = { ...d }; };+ sk.onchange = commit;+ const keys = el("div", "otel-keys");+ keys.append(pk, sk);+ const host = langfuseHost(d.host);+ row("otelLangfuseKeysRow", "API keys", t("From your Langfuse project's Settings › API Keys. Traces go to {url}", { url: (host || "…") + LANGFUSE_PATH }), keys);+}diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.goindex 7642f4ee5..4e6c598d4 100644--- a/internal/gui/core_budget_test.go+++ b/internal/gui/core_budget_test.go@@ -15,8 +15,8 @@ import (// so a page can't quietly grow back into the core; a change that needs more// raises them and says why in its commit.const (- appScriptBudget = 1_326_105 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25)- coreScriptBudget = 1_542_418 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26)+ appScriptBudget = 1_321_319 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26)+ coreScriptBudget = 1_537_645 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26))func TestCoreScriptBudget(t *testing.T) {diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.mdindex 73d02c942..c789b8dde 100644--- a/internal/gui/tests/README.md+++ b/internal/gui/tests/README.md@@ -2051,9 +2051,17 @@ It runs in Chromium and WebKitwith the real assets and an isolated API fixture:```sh-node --test internal/gui/tests/otel.test.cjs+node --test internal/gui/tests/otel.test.cjs internal/gui/tests/otel-langfuse.test.cjs```+`otel-langfuse.test.cjs` checks the Langfuse setup: picking Langfuse and giving+two keys saves Cloud EU's endpoint, the Basic header, the ingestion header,+metrics off and export on, and nothing is saved on one key alone; Cloud US and+a self-hosted address change only the endpoint. A Langfuse set up by hand opens+with its keys filled in, nothing saved on opening, and a changed key keeps its+other headers, metrics and export choice; another collector's headers aren't+carried over. Every language at 1100, 520 and 360px, in Chromium and WebKit.+`account-arrange.test.cjs` drags a subscription's accounts and a provider'skeys by their rows (no handle) in every routing mode, and by Alt+↑/↓: thefirst row, its First mark and the order saved for routing agree, one savediff --git a/internal/gui/tests/otel-langfuse.test.cjs b/internal/gui/tests/otel-langfuse.test.cjsnew file mode 100644index 000000000..41454a288--- /dev/null+++ b/internal/gui/tests/otel-langfuse.test.cjs@@ -0,0 +1,185 @@+// Settings › Observability's Langfuse setup: the user picks Langfuse and+// gives its host and the project's two keys, and magpie makes the endpoint,+// the Basic sign-in and the ingestion header from them. A Langfuse set up by+// hand keeps every value the user set; another collector's headers never go+// to Langfuse. Chromium and WebKit, every language, down to 360px.+const assert = require("node:assert/strict");+const fs = require("node:fs/promises");+const path = require("node:path");+const { test } = require("node:test");+const { chromium, webkit } = require("playwright");+const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");++const assets = path.resolve(__dirname, "../assets");+const basic = (pk, sk) => "Basic " + Buffer.from(pk + ":" + sk).toString("base64");++function server(lang, otel, posts) {+ const fixed = {+ theme: "light", lang, tray: "panel", currency: "usd", redactWords: [], version: "0.1.400", dir: "~/.config/magpie",+ gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [],+ workbuddyCheckins: [], lanURLs: [], fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, otel,+ };+ let cur = fixed;+ return async (route) => {+ const req = route.request(), url = new URL(req.url());+ const json = (data) => route.fulfill({ json: data });+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: fixed.fx });+ if (url.pathname === "/api/settings") {+ if (req.method() === "POST") {+ const body = req.postDataJSON();+ posts.push(body);+ cur = { ...fixed, ...body };+ }+ return json(cur);+ }+ if (url.pathname === "/api/plugins") return json({ plugins: [] });+ if (url.pathname === "/api/usage/quotas") return json([]);+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });+ if (url.pathname.startsWith("/api/")) return json({});+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];+ await route.fulfill({ body: await fs.readFile(file), contentType });+ };+}++async function open(browser, lang, otel, width = 1100) {+ const posts = [], errors = [];+ const context = await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" });+ const page = await context.newPage();+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", server(lang, otel, posts));+ await watchSettingsReads(page);+ await page.goto("http://magpie.test/?view=settings&tab=otel");+ await settingsDrawn(page);+ await page.locator("#otelKindRow").waitFor();+ // a save, waited for by its answer+ const saved = async (action) => {+ const n = posts.length + 1;+ const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");+ await action(); await response;+ await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));+ assert.equal(posts.length, n);+ return posts[n - 1].otel;+ };+ return { context, page, posts, errors, saved };+}++const keys = (page) => page.locator("#otelLangfuseKeysRow input");++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(engine + ": Langfuse setup", async (t) => {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ t.after(() => browser.close());++ await t.test("a first setup needs only the two keys", async () => {+ const { context, page, posts, errors, saved } = await open(browser, "en", {});+ assert.equal(await page.locator("#otelKindRow .opt.on").textContent(), "OTLP");+ await page.locator("#otelKindRow .opt", { hasText: "Langfuse" }).click();+ await page.locator("#otelLangfuseHostRow").waitFor();+ assert.equal(await page.locator("#otelEndpointRow").count(), 0);+ assert.equal(await page.locator("#otelLangfuseHostRow .opt.on").textContent(), "Cloud EU");+ assert.equal(await keys(page).nth(1).getAttribute("type"), "password");+ // one key alone saves nothing+ await keys(page).first().fill("pk-lf-1");+ await keys(page).first().press("Tab");+ await page.waitForTimeout(150);+ assert.equal(posts.length, 0, "nothing saved before both keys are there");+ let o = await saved(async () => { await keys(page).nth(1).fill("sk-lf-2"); await keys(page).nth(1).press("Enter"); });+ assert.equal(o.endpoint, "https://cloud.langfuse.com/api/public/otel");+ assert.deepEqual(o.headers, { Authorization: basic("pk-lf-1", "sk-lf-2"), "x-langfuse-ingestion-version": "4" });+ assert.equal(o.metrics, false);+ assert.equal(o.enabled, true);+ assert.equal(await page.locator("#otelExportRow .opt.on").textContent(), "On");+ assert((await page.locator("#otelLangfuseKeysRow .sub").textContent()).includes("https://cloud.langfuse.com/api/public/otel"));+ // the US region, then a host of the user's own+ o = await saved(() => page.locator("#otelLangfuseHostRow .opt", { hasText: "Cloud US" }).click());+ assert.equal(o.endpoint, "https://us.cloud.langfuse.com/api/public/otel");+ assert.equal(o.headers.Authorization, basic("pk-lf-1", "sk-lf-2"));+ await page.locator("#otelLangfuseHostRow .opt", { hasText: "Self-hosted" }).click();+ const host = page.locator("#otelLangfuseHostRow input");+ await host.waitFor();+ o = await saved(async () => { await host.fill("langfuse.example.com/api/public/otel/"); await host.press("Enter"); });+ assert.equal(o.endpoint, "https://langfuse.example.com/api/public/otel");+ assert.equal(await page.locator("#otelLangfuseHostRow .opt.on").textContent(), "Self-hosted");+ assert.equal(await host.inputValue(), "https://langfuse.example.com");+ // a reload finds it all as Langfuse again+ await page.reload();+ await page.locator("#otelLangfuseKeysRow").waitFor();+ assert.equal(await keys(page).first().inputValue(), "pk-lf-1");+ assert.equal(await keys(page).nth(1).inputValue(), "sk-lf-2");+ assert.equal(await page.locator("#otelKindRow .opt.on").textContent(), "Langfuse");+ assert.deepEqual(errors, []);+ await context.close();+ });++ await t.test("a Langfuse set up by hand keeps its values", async () => {+ const hand = {+ enabled: false, metrics: true, endpoint: "https://cloud.langfuse.com/api/public/otel",+ headers: { Authorization: basic("pk-lf-a", "sk-lf-a"), "X-Team": "a,b" },+ };+ const { context, page, posts, errors, saved } = await open(browser, "en", hand);+ await page.locator("#otelLangfuseKeysRow").waitFor();+ assert.equal(await keys(page).first().inputValue(), "pk-lf-a");+ await page.waitForTimeout(150);+ assert.equal(posts.length, 0, "opening the page saves nothing");+ const o = await saved(async () => { await keys(page).nth(1).fill("sk-lf-b"); await keys(page).nth(1).press("Enter"); });+ assert.deepEqual(o.headers, { Authorization: basic("pk-lf-a", "sk-lf-b"), "X-Team": "a,b" }, "no header added or dropped");+ assert.equal(o.metrics, true, "metrics as the user set them");+ assert.equal(o.enabled, false, "export as the user set it");+ assert.deepEqual(errors, []);+ await context.close();+ });++ await t.test("another collector's headers stay with it", async () => {+ const { context, page, errors, saved } = await open(browser, "en", { enabled: true, endpoint: "http://localhost:4318", headers: { Authorization: "Bearer other", "X-Other": "1" } });+ await page.locator("#otelKindRow .opt", { hasText: "Langfuse" }).click();+ await keys(page).first().fill("pk-lf-1");+ const o = await saved(async () => { await keys(page).nth(1).fill("sk-lf-2"); await keys(page).nth(1).press("Enter"); });+ assert.deepEqual(o.headers, { Authorization: basic("pk-lf-1", "sk-lf-2"), "x-langfuse-ingestion-version": "4" });+ assert.equal(o.endpoint, "https://cloud.langfuse.com/api/public/otel");+ assert.deepEqual(errors, []);+ await context.close();+ });++ const names = {+ zh: ["采集服务", "Langfuse 地址", "API 密钥", "Cloud 欧洲"],+ "zh-TW": ["採集服務", "Langfuse 位址", "API 金鑰", "Cloud 歐洲"],+ ja: ["コレクター", "Langfuse のホスト", "API キー", "Cloud EU"],+ de: ["Collector", "Langfuse-Host", "API-Schlüssel", "Cloud EU"],+ en: ["Collector", "Langfuse host", "API keys", "Cloud EU"],+ };+ for (const [lang, want] of Object.entries(names)) {+ await t.test(lang + " at narrow widths", async () => {+ const { context, page, errors } = await open(browser, lang, { endpoint: "https://cloud.langfuse.com/api/public/otel", headers: { Authorization: basic("pk-lf-1", "sk-lf-2") } });+ await page.locator("#otelLangfuseKeysRow").waitFor();+ assert.deepEqual([+ await page.locator("#otelKindRow .name").textContent(),+ await page.locator("#otelLangfuseHostRow .name").textContent(),+ await page.locator("#otelLangfuseKeysRow .name").textContent(),+ await page.locator("#otelLangfuseHostRow .opt.on").textContent(),+ ], want);+ for (const width of [1100, 520, 360]) {+ await page.setViewportSize({ width, height: 1000 });+ await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));+ const layout = await page.locator("#otelList").evaluate((list) => {+ const row = list.querySelector("#otelLangfuseKeysRow");+ return {+ fields: [...row.querySelectorAll("input")].map((f) => f.getBoundingClientRect().width),+ rowWidth: row.getBoundingClientRect().width,+ overflow: [...list.querySelectorAll(".row, .val, .segs")].filter((e) => e.scrollWidth > e.clientWidth + 1).map((e) => e.id || e.className),+ page: document.documentElement.scrollWidth > innerWidth + 1,+ };+ });+ for (const w of layout.fields) assert(w > layout.rowWidth - 40, `key fields span the row at ${width}px`);+ assert.deepEqual(layout.overflow, [], `nothing overflows at ${width}px`);+ assert.equal(layout.page, false, `no sideways scroll at ${width}px`);+ }+ if (process.env.ARTIFACT_DIR) await page.locator("#otelList").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `langfuse-${engine}-${lang}.png`) });+ assert.deepEqual(errors, []);+ await context.close();+ });+ }+ });+}diff --git a/internal/gui/tests/otel.test.cjs b/internal/gui/tests/otel.test.cjsindex 08db1d538..fd8cb1478 100644--- a/internal/gui/tests/otel.test.cjs+++ b/internal/gui/tests/otel.test.cjs@@ -162,7 +162,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));const layout = await page.locator("#otelList").evaluate((list) => {const sub = list.querySelector("#otelSessionsRow .sub");- const row = list.querySelector("#otelEndpointRow");+ // the saved endpoint is Langfuse's, so after the reload the+ // Langfuse fields stand where the endpoint's was+ const row = list.querySelector("#otelEndpointRow, #otelLangfuseKeysRow");const field = row.querySelector("input");return {wraps: getComputedStyle(sub).whiteSpace === "normal",diff --git a/internal/otlp/otel_test.go b/internal/otlp/otel_test.goindex a5d9b06f4..da04a7ee9 100644--- a/internal/otlp/otel_test.go+++ b/internal/otlp/otel_test.go@@ -1,10 +1,12 @@package otlpimport (+ "encoding/base64""encoding/json""io""net/http""net/http/httptest"+ "os""path/filepath""strings""sync"@@ -400,3 +402,45 @@ func TestOTelQueueBodiesBudgetConcurrent(t *testing.T) {}}}++// Settings › Observability's Langfuse setup saves an endpoint and headers+// made from the host and the project's keys (plugins/otel/page.js); sent+// from saved settings, with no MAGPIE_OTEL_* in the way, a batch reaches+// Langfuse's OTLP traces path with the Basic sign-in and the ingestion+// header, and metrics, off, send nothing.+func TestOTelLangfuseSetup(t *testing.T) {+ type got struct{ path, auth, version string }+ var mu sync.Mutex+ var seen []got+ collector := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ mu.Lock()+ seen = append(seen, got{r.URL.Path, r.Header.Get("Authorization"), r.Header.Get("x-langfuse-ingestion-version")})+ mu.Unlock()+ io.WriteString(w, `{}`)+ }))+ defer collector.Close()+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "config"))+ for _, k := range []string{"MAGPIE_OTEL_ENABLED", "MAGPIE_OTEL_ENDPOINT", "MAGPIE_OTEL_HEADERS", "MAGPIE_OTEL_METRICS", "MAGPIE_OTEL_SESSIONS", "MAGPIE_OTEL_BODIES", "MAGPIE_OTEL_BODIES_WHOLE"} {+ t.Setenv(k, "")+ os.Unsetenv(k)+ }+ auth := "Basic " + base64.StdEncoding.EncodeToString([]byte("pk-lf-1:sk-lf-2"))+ if err := settings.Save(settings.Settings{OTel: settings.OTel{+ Enabled: true, Endpoint: collector.URL + "/api/public/otel",+ Headers: map[string]string{"Authorization": auth, "x-langfuse-ingestion-version": "4"},+ }}); err != nil {+ t.Fatal(err)+ }+ cfg, err := settings.OTelExport()+ if err != nil {+ t.Fatal(err)+ }+ e := newOTelExporter()+ defer e.cancel()+ e.flush([]otelItem{{record: Record{Time: time.Now(), Status: 200, Agent: "codex", Provider: "openai", Model: "gpt-5"}, config: cfg}})+ mu.Lock()+ defer mu.Unlock()+ if want := []got{{"/api/public/otel/v1/traces", auth, "4"}}; len(seen) != 1 || seen[0] != want[0] {+ t.Fatalf("collector saw %+v, want %+v", seen, want)+ }+}diff --git a/plugins/otel/otel.go b/plugins/otel/otel.goindex 51209655b..56ed5bf00 100644--- a/plugins/otel/otel.go+++ b/plugins/otel/otel.go@@ -35,7 +35,8 @@ func init() {}return 0, nil},- Parts: []pluginrt.Part{{Slot: "settings.section", Key: "otel"}},+ Parts: []pluginrt.Part{{Slot: "settings.section", Key: "otel"}},+ Client: []string{"i18n.js", "page.js"},Apply: func(c *pluginrt.Ctx) error {c.OnDispose(usage.Observe(otlp.New()))return nildiff --git a/site/public/docs/ja/privacy.html b/site/public/docs/ja/privacy.htmlindex c806caf45..d797f8ba9 100644--- a/site/public/docs/ja/privacy.html+++ b/site/public/docs/ja/privacy.html@@ -182,7 +182,7 @@<p>モデルの価格と名前のために <a href="https://models.dev">models.dev</a> のカタログ(<code>models.dev/api.json</code>)を、あなたの通貨で価格を表示するために <code>open.er-api.com</code> から米ドルの為替レート(12 時間保持)を取得します。プラグインとその更新は npm レジストリから、ライブラリの項目は GitHub から取得します。どれも公開データの単なるダウンロードで、あなた、あなたのプロバイダー、使用量については何も送りません。ただし、どのリクエストとも同じく、これらのホストにはあなた(またはプロキシ)の IP アドレスが見えます。magpie は各プロバイダーにも、あなた自身のキーやサインインで残量とモデル一覧を尋ねます。<span class="ui">設定</span> → <span class="ui">利用枠</span> → <span class="ui">利用枠の読み込み</span> → <span class="ui">手動のみ</span> で、頼んだときに限れます。</p><h2 id="otel"><a class="anchor" href="#otel">OTLP エクスポート</a></h2>- <p>magpie はゲートウェイの各リクエストを、あなたの OpenTelemetry コレクター(Langfuse など)へエクスポートできます。<b>既定ではオフ</b>で、送り先はあなたが設定したエンドポイントだけです。私たちには送りません。オンにすると、リクエストごとのスパン(エージェント、プロバイダー、モデル、トークン数、ステータス、時間、推定コスト)を送ります。別のスイッチで、メトリクス、ローカルのエージェント会話、リクエストと返答の本文(シークレットはマスク)を加えられます。<span class="ui">設定</span> → <span class="ui">オブザーバビリティ</span> でオンにするか、<code>magpie serve</code> では <code>MAGPIE_OTEL_ENABLED</code>、<code>MAGPIE_OTEL_ENDPOINT</code>、<code>MAGPIE_OTEL_HEADERS</code>、<code>MAGPIE_OTEL_METRICS</code>、<code>MAGPIE_OTEL_SESSIONS</code>、<code>MAGPIE_OTEL_BODIES</code>、<code>MAGPIE_OTEL_BODIES_WHOLE</code> を使います。エンドポイントだけではオンになりません。詳しくは<a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">リファレンス</a>を。</p>+ <p>magpie はゲートウェイの各リクエストを、あなたの OpenTelemetry コレクター(Langfuse など)へエクスポートできます。<b>既定ではオフ</b>で、送り先はあなたが設定したエンドポイントだけです。私たちには送りません。オンにすると、リクエストごとのスパン(エージェント、プロバイダー、モデル、トークン数、ステータス、時間、推定コスト)を送ります。別のスイッチで、メトリクス、ローカルのエージェント会話、リクエストと返答の本文(シークレットはマスク)を加えられます。<span class="ui">設定</span> → <span class="ui">オブザーバビリティ</span> でオンにするか、<code>magpie serve</code> では <code>MAGPIE_OTEL_ENABLED</code>、<code>MAGPIE_OTEL_ENDPOINT</code>、<code>MAGPIE_OTEL_HEADERS</code>、<code>MAGPIE_OTEL_METRICS</code>、<code>MAGPIE_OTEL_SESSIONS</code>、<code>MAGPIE_OTEL_BODIES</code>、<code>MAGPIE_OTEL_BODIES_WHOLE</code> を使います。エンドポイントだけではオンになりません。Langfuse なら、そこで <span class="ui">Langfuse</span> を選び、ホストとプロジェクトの 2 つのキーを入力すると、magpie がエンドポイントと認証を作ります。詳しくは<a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">リファレンス</a>を。</p><h2 id="masking"><a class="anchor" href="#masking">プロバイダに送る内容のマスク</a></h2><p>ここまでの節は magpie が自分で送るものです。エージェントが送る内容は選んだプロバイダに届きますが、<b>プライバシーマスク</b>はその中の秘密をこのコンピュータに留めます。<b>既定ではオフ</b>で、<span class="ui">設定</span> → <span class="ui">プライバシー</span> でオンにします。</p>diff --git a/site/public/docs/privacy.html b/site/public/docs/privacy.htmlindex 4873f9a46..20ba8b52f 100644--- a/site/public/docs/privacy.html+++ b/site/public/docs/privacy.html@@ -182,7 +182,7 @@<p>To price and name models magpie fetches the <a href="https://models.dev">models.dev</a> catalog (<code>models.dev/api.json</code>), and for prices in your currency the USD exchange rate from <code>open.er-api.com</code> (kept 12 hours). Plugins and their updates come from the npm registry, and the library’s items from GitHub. These are plain downloads of public data: nothing about you, your providers or your usage is sent, though, as with any request, those hosts see your IP address (or your proxy’s). magpie also asks each of your providers for your allowance and model list, with your own key or sign-in; <span class="ui">Settings</span> → <span class="ui">Allowances</span> → <span class="ui">Allowance reads</span> → <span class="ui">When I ask</span> limits those to when you ask.</p><h2 id="otel"><a class="anchor" href="#otel">OTLP export</a></h2>- <p>magpie can export each gateway request to an OpenTelemetry collector of yours (Langfuse, for example). It is <b>off by default</b>, and goes only to the endpoint you set, never to us. When on, it sends per-request spans: agent, provider, model, token counts, status, timing and estimated cost. Optional switches add metrics, local agent conversations, and the request and reply bodies (secrets masked). Turn it on in <span class="ui">Settings</span> → <span class="ui">Observability</span>, or for <code>magpie serve</code> with <code>MAGPIE_OTEL_ENABLED</code>, <code>MAGPIE_OTEL_ENDPOINT</code>, <code>MAGPIE_OTEL_HEADERS</code>, <code>MAGPIE_OTEL_METRICS</code>, <code>MAGPIE_OTEL_SESSIONS</code>, <code>MAGPIE_OTEL_BODIES</code> and <code>MAGPIE_OTEL_BODIES_WHOLE</code>. An endpoint alone doesn’t turn it on. The <a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">reference</a> has the details.</p>+ <p>magpie can export each gateway request to an OpenTelemetry collector of yours (Langfuse, for example). It is <b>off by default</b>, and goes only to the endpoint you set, never to us. When on, it sends per-request spans: agent, provider, model, token counts, status, timing and estimated cost. Optional switches add metrics, local agent conversations, and the request and reply bodies (secrets masked). Turn it on in <span class="ui">Settings</span> → <span class="ui">Observability</span>, or for <code>magpie serve</code> with <code>MAGPIE_OTEL_ENABLED</code>, <code>MAGPIE_OTEL_ENDPOINT</code>, <code>MAGPIE_OTEL_HEADERS</code>, <code>MAGPIE_OTEL_METRICS</code>, <code>MAGPIE_OTEL_SESSIONS</code>, <code>MAGPIE_OTEL_BODIES</code> and <code>MAGPIE_OTEL_BODIES_WHOLE</code>. An endpoint alone doesn’t turn it on. For Langfuse, pick <span class="ui">Langfuse</span> there and give its host and your project’s two keys; magpie makes the endpoint and sign-in from them. The <a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">reference</a> has the details.</p><h2 id="masking"><a class="anchor" href="#masking">Masking what goes to providers</a></h2><p>The sections above are what magpie sends by itself. What your agents send goes to the providers you chose, and <b>privacy masking</b> keeps the secrets in it on this computer. It is <b>off by default</b>; turn it on in <span class="ui">Settings</span> → <span class="ui">Privacy</span>.</p>diff --git a/site/public/docs/zh/privacy.html b/site/public/docs/zh/privacy.htmlindex b5efa65cb..eedf923d2 100644--- a/site/public/docs/zh/privacy.html+++ b/site/public/docs/zh/privacy.html@@ -182,7 +182,7 @@<p>为了给模型定价和命名,magpie 会拉取 <a href="https://models.dev">models.dev</a> 的模型目录(<code>models.dev/api.json</code>);为了用你的货币显示价格,会从 <code>open.er-api.com</code> 拉取美元汇率(缓存 12 小时)。插件及其更新来自 npm 仓库,库里的内容来自 GitHub。这些都是公开数据的普通下载,不发送任何关于你、你的供应商或用量的信息;和任何请求一样,这些主机能看到你的 IP(或代理的 IP)。magpie 还会用你自己的密钥或登录向各个供应商读取额度和模型列表;<span class="ui">设置</span> → <span class="ui">额度</span> → <span class="ui">额度刷新</span> → <span class="ui">仅手动</span> 可以只在你要求时才读。</p><h2 id="otel"><a class="anchor" href="#otel">OTLP 导出</a></h2>- <p>magpie 可以把每个网关请求导出到你自己的 OpenTelemetry 收集器(比如 Langfuse)。它<b>默认关闭</b>,只发到你设置的地址,从不发给我们。开启后发送每个请求的 span:agent、供应商、模型、token 数、状态、耗时和估算费用。另有开关可以加上指标、本地 agent 对话,以及请求和回复正文(密钥已遮盖)。在 <span class="ui">设置</span> → <span class="ui">可观测性</span> 里开启,<code>magpie serve</code> 也可以用 <code>MAGPIE_OTEL_ENABLED</code>、<code>MAGPIE_OTEL_ENDPOINT</code>、<code>MAGPIE_OTEL_HEADERS</code>、<code>MAGPIE_OTEL_METRICS</code>、<code>MAGPIE_OTEL_SESSIONS</code>、<code>MAGPIE_OTEL_BODIES</code> 和 <code>MAGPIE_OTEL_BODIES_WHOLE</code>。只设地址不会开启导出。细节见<a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">参考文档</a>。</p>+ <p>magpie 可以把每个网关请求导出到你自己的 OpenTelemetry 收集器(比如 Langfuse)。它<b>默认关闭</b>,只发到你设置的地址,从不发给我们。开启后发送每个请求的 span:agent、供应商、模型、token 数、状态、耗时和估算费用。另有开关可以加上指标、本地 agent 对话,以及请求和回复正文(密钥已遮盖)。在 <span class="ui">设置</span> → <span class="ui">可观测性</span> 里开启,<code>magpie serve</code> 也可以用 <code>MAGPIE_OTEL_ENABLED</code>、<code>MAGPIE_OTEL_ENDPOINT</code>、<code>MAGPIE_OTEL_HEADERS</code>、<code>MAGPIE_OTEL_METRICS</code>、<code>MAGPIE_OTEL_SESSIONS</code>、<code>MAGPIE_OTEL_BODIES</code> 和 <code>MAGPIE_OTEL_BODIES_WHOLE</code>。只设地址不会开启导出。用 Langfuse 的话,在那里选 <span class="ui">Langfuse</span>,填上地址和项目的两个密钥,magpie 会据此生成地址和认证头。细节见<a href="https://github.com/yetone/magpie/blob/main/docs/reference.md#otlp-export">参考文档</a>。</p><h2 id="masking"><a class="anchor" href="#masking">发给供应商的内容脱敏</a></h2><p>上面几节讲的是 magpie 自己发出的东西。你的 Agent 发出的内容会去往你选的供应商,<b>隐私脱敏</b>让其中的密钥留在这台电脑上。它<b>默认关闭</b>,在 <span class="ui">设置</span> → <span class="ui">隐私</span> 里打开。</p>