A user on X asked for Langfuse built in. magpie could already export to Langfuse over OTLP, but Settings › Observability had the user type the endpoint .../api/public/otel and a percent-encoded Authorization=Basic%20<base64(pk:sk)> header by hand. Settings › Observability now has a Collector row: OTLP or Langfuse. With Langfuse, the user picks the host (Cloud EU, Cloud US, or Self-hosted with an address, which also covers Langfuse's JP and HIPAA regions) and fills in the public and secret keys. Once both keys are there, magpie saves: - the endpoint <host>/api/public/otel; - Authorization: Basic base64(pk:sk), in otel.headers as before, so the secret is stored where it was and a backup without keys leaves it out; - on a first setup, also x-langfuse-ingestion-version: 4, metrics off and export on. langfuse.com/docs/opentelemetry/get-started (read 10-26) gives the same header for every region and for self-hosted, and says that without it OTLP data can arrive up to 10 minutes late. A Langfuse endpoint set up by hand opens in this view with its keys decoded into the fields. Opening it saves nothing. Changing a key or the host keeps the user's other headers, their metrics and export choices, and an ingestion header they set or left out. Switching from another collector leaves that collector's headers behind and does not send them to Langfuse. The Observability page moved from app.js into the otel plugin (assets/plugins/otel/page.js, with i18n.js for its words, in Client), because app.js had 13 bytes of budget left. The app.js and core budgets are lowered to what is left (1,321,319 and 1,537,645; app.js is 1,321,313 after rebasing on2620dc319). "Collector" and "Secret key" go in the core i18n.js because other files use the same words. Docs: reference.md's Langfuse paragraph (with the env form for magpie serve) and the en/zh/ja privacy pages. Run (macOS): - go test ./... -timeout 45m -count=1 at the pre-rebase head (parente5dd86965): every package ok but internal/provider, which crashed in TestUnreadLoginsWriteErrorsKeepCredentials with "close of synctest channel from outside bubble" in filememo.Forget. That is #3632, red on main since091153bf7. - The whole GUI suite (make test-ui, concurrency 4, Chromium and WebKit) at the same head: 16 reds. Each red file was run alone here and at the parente5dd86965. The same reds came back at both: menu-input-scroll (#3402), old-webkit (#3403) and plugin-card-update's webkit Update (#3079). The parent also failed fonts' webkit run. page-width, api-key-theme, panel-arrange, panel-balance-order, own-requests, library-mcp-health-wsl and plugin-list-error passed alone here: 137 passes, 7 fails, all of them the three filed above. - At the pushed head (rebased on origin/mainc87a0179b): the budget tests; otel, otel-langfuse, i18n-keys, settings-sections, builtins, idle-ticks and page-width, both engines, 58 pass; go test ./internal/otlp ./plugins/otel ./internal/gui, all ok except TestRestartHandsTheGatewayOver (#3451). That test failed 1 of 8 here and 1 of 8 on origin/maindce7fe609. - Before the rebase: otel-langfuse (new: first setup, US, self-hosted, hand setup kept, another collector's headers dropped, 5 languages at 1100/520/360px) with otel, i18n-keys, settings-sections, builtins, readable-focus, segs-press-redraw, ux-safety, dialog-backdrop-drag and mono-icon-redraw: 113 pass. go vet for darwin, linux and windows on the touched packages; gofmt -l clean. - Broken by hand: with every save treated as a first setup and the old collector's headers carried over, otel-langfuse's "set up by hand keeps its values" and "another collector's headers" went red. - New TestOTelLangfuseSetup: settings saved as the page writes them reach a fake collector at /api/public/otel/v1/traces with the Basic header and ingestion version 4, and nothing on /v1/metrics. - Real app: a -tags dev build in a sandbox HOME (ports 3461/3462). I drove its real Settings page with Playwright: Langfuse, then Self-hosted http://127.0.0.1:3463, then both keys. settings.json got the endpoint, Basic header, version 4 and enabled. A gateway request then reached a local fake collector at /api/public/otel/v1/traces with Authorization Basic base64(pk-lf-real-ui:sk-lf-real-ui) and x-langfuse-ingestion-version 4. Not tried: a real Langfuse Cloud or self-hosted project (no account here), so Langfuse accepting the spans and how they show in its UI aren't checked. The TUI and magpie serve still have no Langfuse shortcut; serve takes the env form in reference.md. The Linux app (WebKitGTK) and Windows weren't tried; the change is form fields and segs, with no motion.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
// Package otel is Settings' Observability: each request's traces and
|
|
// metrics sent to an OpenTelemetry collector, such as Langfuse. While it
|
|
// sends, it stays on.
|
|
//
|
|
// It is the first consumer of the gateway's observer point (P3 of
|
|
// docs/subsystems/plugin-runtime.md): Apply registers internal/otlp's
|
|
// exporter as a usage.Observer, and off, the gateway exports nothing and
|
|
// keeps no reply whole for it.
|
|
package otel
|
|
|
|
import (
|
|
"github.com/yetone/magpie/internal/otlp"
|
|
"github.com/yetone/magpie/internal/pluginrt"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
func init() {
|
|
pluginrt.Register(pluginrt.Manifest{
|
|
ID: "otel", API: "^1", Requires: []string{"window", "settings", "gateway"},
|
|
Name: "Observability", Sub: "Send each request's traces and metrics to an OpenTelemetry collector, such as Langfuse",
|
|
One: "Sending to a collector", Many: "Sending to a collector",
|
|
// on while settings.json or MAGPIE_OTEL_ENABLED says to send: off,
|
|
// nothing would
|
|
InUse: func() (int, error) {
|
|
if _, err := settings.LoadChecked(); err != nil {
|
|
return 0, err
|
|
}
|
|
config, err := settings.OTelExport()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if config.Enabled {
|
|
return 1, nil
|
|
}
|
|
return 0, nil
|
|
},
|
|
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 nil
|
|
},
|
|
})
|
|
}
|