diff --git a/docs/reference.md b/docs/reference.md index d024b8f05..b38392f0c 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -3358,6 +3358,28 @@ MAGPIE_OTEL_ENABLED=true MAGPIE_OTEL_ENDPOINT=http://localhost:4318 magpie serve - `MAGPIE_OTEL_BODIES_WHOLE`: `true` or `false`, off by default; with bodies on, keeps them entire rather than cut at 256 KB. A long reply is written to a temporary file; a body too large for the collector is still refused. +- `OTEL_RESOURCE_ATTRIBUTES`: the standard OpenTelemetry variable, merged into + the resource of both traces and metrics, for example to tell servers apart: + + ```sh + OTEL_RESOURCE_ATTRIBUTES='service.instance.id=magpie-prod-01,host.name=server-a,deployment.environment.name=production' \ + MAGPIE_OTEL_ENABLED=true MAGPIE_OTEL_ENDPOINT=http://localhost:4318 magpie serve + ``` + + Comma-separated `key=value` pairs, as the + [OTel resource SDK spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) + has them: keys and values are trimmed and percent-decoded (write `,` as + `%2C`, `=` as `%3D` and `%` as `%25`; `+` stays a plus), every value is a + string, and the last of a repeated key wins. Any invalid entry (no `=`, an + empty key, a bad escape, bytes that aren't UTF-8 once decoded, an empty + entry such as a trailing comma) discards the whole variable: magpie logs + which entry, never its contents, and exports with the default resource. + Nothing else about the machine is looked up or sent. +- `OTEL_SERVICE_NAME`: the resource's `service.name`, over a `service.name` in + `OTEL_RESOURCE_ATTRIBUTES`. With neither set, or set empty, it is `magpie`. + + Neither variable turns export on, and both are read in the process that + exports (the app, or `magpie serve`), so restart it after changing them. For Langfuse, pick **Collector › Langfuse**, then the host (Cloud EU `https://cloud.langfuse.com`, Cloud US `https://us.cloud.langfuse.com`, or diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.md index 461ce0d6c..b190f1438 100644 --- a/docs/subsystems/plugin-runtime.md +++ b/docs/subsystems/plugin-runtime.md @@ -183,7 +183,7 @@ plugin off the gateway does no observing work. | `Begin` and `Watch` | As a request starts the gateway asks each observer (`observeRequest`) with `usage.Request`: its header, agent, session (the native one when the agent names it), call kind (`auxiliary` for Claude's tool-less helper calls) and `Plain` (loopback, no gateway key, not passed on from another magpie). A `Watch` it returns gets `Attempt` for each routing attempt, unbilled failures and retries too, and `End` once. With no observer, or none watching, the request carries nothing. | [`observe.go`](../../internal/gateway/observe.go) | | Bodies | `Bodies()` is `NoBodies`, `CapturedBodies` (the first 256 KiB, cut with `usage.BodyCut`) or `WholeBodies` (the reply spooled whole as it streams, #538). The gateway takes the most any observer wants now (`ObservedBodies`): it keeps the whole reply only when one asks for it, and puts bodies on an attempt's record only when one asks for any. | [`observe.go`](../../internal/gateway/observe.go), [`capture.go`](../../internal/gateway/capture.go) | | `Ledger` and `Watched` | Every row `Append` writes is passed to each observer. A row of a request some observer watched has `Watched` set (`appendUsage`), so an observer that sent the request's attempts doesn't send its row again. | [`usage.go`](../../internal/usage/usage.go), [`lan.go`](../../internal/gateway/lan.go) | -| `internal/otlp` | The OTLP/HTTP exporter, moved whole out of `internal/usage`: `otlp.New()` is an `Exporter`, a `usage.Observer`. Its Begin leaves a local agent's own turn to the agent's transcript when session tracing reads it, and takes a W3C `traceparent` as the parent. Settings are read on each call, as before. | [`otlp/`](../../internal/otlp) | +| `internal/otlp` | The OTLP/HTTP exporter, moved whole out of `internal/usage`: `otlp.New()` is an `Exporter`, a `usage.Observer`. Its Begin leaves a local agent's own turn to the agent's transcript when session tracing reads it, and takes a W3C `traceparent` as the parent. Settings are read on each call, as before. Both signals' resource is `service.name=magpie` with `OTEL_RESOURCE_ATTRIBUTES` merged over it and `OTEL_SERVICE_NAME` over that (`otelResourceAttributes`, #5167); an invalid variable is discarded whole and logged once, by entry position only. Nothing about the host is collected. | [`otlp/`](../../internal/otlp) | | `plugins/otel` | Requires `window`, `settings` and `gateway`. Apply registers `otlp.New()` and disposes of it when turned off. `InUse` is 1 while `settings.OTelExport` says to send (settings.json or `MAGPIE_OTEL_*`), so a user who exports only through the environment keeps it on under Essentials. | [`otel.go`](../../plugins/otel/otel.go) | ## Gateway extension points (P3): router strategy diff --git a/internal/otlp/otel_resource.go b/internal/otlp/otel_resource.go new file mode 100644 index 000000000..de8a66605 --- /dev/null +++ b/internal/otlp/otel_resource.go @@ -0,0 +1,106 @@ +package otlp + +import ( + "fmt" + "log" + "net/url" + "os" + "sort" + "strings" + "sync" + "unicode/utf8" +) + +// otelResource is what both signals' resources were last built from, so an +// export doesn't parse the variables again and a bad value is logged once, +// not on every flush. +var otelResource struct { + sync.Mutex + attrs, name string + built bool + out []otelAttribute +} + +// otelResourceAttributes is the resource every export carries: +// service.name=magpie, with the standard OTEL_RESOURCE_ATTRIBUTES merged +// over it and OTEL_SERVICE_NAME over that (#5167). Only what the user set +// is added; nothing about the machine is looked up. +// +// magpie's "magpie" is the fallback the spec gives the SDK +// (unknown_service), not identity the user supplied, so a service.name the +// user set wins. An empty service.name counts as unset, as an empty +// OTEL_SERVICE_NAME does. +func otelResourceAttributes() []otelAttribute { + attrs, name := os.Getenv("OTEL_RESOURCE_ATTRIBUTES"), strings.TrimSpace(os.Getenv("OTEL_SERVICE_NAME")) + otelResource.Lock() + defer otelResource.Unlock() + if otelResource.built && otelResource.attrs == attrs && otelResource.name == name { + return otelResource.out + } + values, err := parseResourceAttributes(attrs) + if err != nil { + // The spec discards the whole value on any error. The message + // never quotes it: the attributes may name private hosts. + log.Printf("otel: OTEL_RESOURCE_ATTRIBUTES ignored: %s", err) + values = map[string]string{} + } + if values["service.name"] == "" { + values["service.name"] = "magpie" + } + if name != "" { + values["service.name"] = name + } + keys := make([]string, 0, len(values)) + for key := range values { + keys = append(keys, key) + } + sort.Strings(keys) + out := make([]otelAttribute, 0, len(keys)) + for _, key := range keys { + out = append(out, otelString(key, values[key])) + } + otelResource.attrs, otelResource.name, otelResource.built, otelResource.out = attrs, name, true, out + return out +} + +// parseResourceAttributes reads key1=value1,key2=value2: keys and values +// trimmed and percent-decoded, every value a string, the last of a +// repeated key kept. An empty or blank value is no attributes. An error +// names the entry by position only. +func parseResourceAttributes(raw string) (map[string]string, error) { + values := map[string]string{} + if strings.TrimSpace(raw) == "" { + return values, nil + } + for i, entry := range strings.Split(raw, ",") { + key, value, found := strings.Cut(entry, "=") + if !found { + return nil, fmt.Errorf("entry %d has no '='", i+1) + } + key, err := decodeResourcePart(key) + if err != nil { + return nil, fmt.Errorf("entry %d's key %s", i+1, err) + } + if key == "" { + return nil, fmt.Errorf("entry %d has an empty key", i+1) + } + if value, err = decodeResourcePart(value); err != nil { + return nil, fmt.Errorf("entry %d's value %s", i+1, err) + } + values[key] = value + } + return values, nil +} + +// decodeResourcePart percent-decodes one key or value. PathUnescape leaves +// '+' as it is: this is not form encoding. +func decodeResourcePart(s string) (string, error) { + s, err := url.PathUnescape(strings.TrimSpace(s)) + if err != nil { + return "", fmt.Errorf("has a bad percent escape") + } + if !utf8.ValidString(s) { + return "", fmt.Errorf("is not UTF-8 once decoded") + } + return s, nil +} diff --git a/internal/otlp/otel_resource_test.go b/internal/otlp/otel_resource_test.go new file mode 100644 index 000000000..9e9467d7c --- /dev/null +++ b/internal/otlp/otel_resource_test.go @@ -0,0 +1,150 @@ +package otlp + +import ( + "bytes" + "encoding/json" + "io" + "log" + "net/http" + "net/http/httptest" + "reflect" + "strings" + "testing" + "time" + + "github.com/yetone/magpie/internal/settings" +) + +// exportResources flushes one record and returns the resource attributes +// the collector got on /v1/traces and on /v1/metrics, in that order. +func exportResources(t *testing.T, attrs, name string) [2]map[string]string { + t.Helper() + type received struct { + path string + body []byte + } + requests := make(chan received, 2) + collector := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + if err != nil { + t.Error(err) + } + requests <- received{r.URL.Path, body} + io.WriteString(w, `{}`) + })) + defer collector.Close() + otelConfig(t, settings.OTel{Endpoint: collector.URL, Metrics: true}) + t.Setenv("OTEL_RESOURCE_ATTRIBUTES", attrs) + t.Setenv("OTEL_SERVICE_NAME", name) + config, err := settings.OTelExport() + if err != nil { + t.Fatal(err) + } + e := newOTelExporter() + defer e.cancel() + defer e.client.CloseIdleConnections() + e.flush([]otelItem{{record: Record{Time: time.Now(), Status: 200, Input: 1}, config: config}}) + var out [2]map[string]string + for i, signal := range []string{"Spans", "Metrics"} { + var request received + select { + case request = <-requests: + default: + t.Fatalf("collector received no %s export", signal) + } + if want := map[string]string{"Spans": "/v1/traces", "Metrics": "/v1/metrics"}[signal]; request.path != want { + t.Fatalf("path = %q, want %q", request.path, want) + } + var payload map[string][]struct { + Resource struct { + Attributes []otelAttribute `json:"attributes"` + } `json:"resource"` + } + if err := json.Unmarshal(request.body, &payload); err != nil { + t.Fatal(err) + } + resources := payload["resource"+signal] + if len(resources) != 1 { + t.Fatalf("%s: got %d resources, want 1", signal, len(resources)) + } + got := map[string]string{} + for _, attr := range resources[0].Resource.Attributes { + value, ok := attr.Value["stringValue"].(string) + if !ok { + t.Fatalf("%s: attribute %q is not a string: %v", signal, attr.Key, attr.Value) + } + if _, dup := got[attr.Key]; dup { + t.Fatalf("%s: duplicate attribute %q", signal, attr.Key) + } + got[attr.Key] = value + } + out[i] = got + } + return out +} + +// A server identity set in OTEL_RESOURCE_ATTRIBUTES reaches the resource +// of both signals, as the collector receives them (#5167). +func TestOTelResourceAttributes(t *testing.T) { + magpie := map[string]string{"service.name": "magpie"} + for _, tc := range []struct { + name, attrs, service string + want map[string]string + }{ + {"default", "", "", magpie}, + {"whitespace", " \t ", "", magpie}, + {"server", "service.instance.id=magpie-prod-01,host.name=server-a,deployment.environment.name=production", "", map[string]string{ + "service.name": "magpie", "service.instance.id": "magpie-prod-01", "host.name": "server-a", "deployment.environment.name": "production", + }}, + {"override and duplicate", "service.name=first,service.name=custom,host.name=old,host.name=new", "", map[string]string{"service.name": "custom", "host.name": "new"}}, + {"encoding and empty", " label%2Ckey = a%2Cb%3Dc%20d+e , empty=,host.name=%E6%9C%BA%E5%99%A8", "", map[string]string{ + "service.name": "magpie", "label,key": "a,b=c d+e", "empty": "", "host.name": "机器", + }}, + {"unencoded UTF-8 kept", "host.name=机器", "", map[string]string{"service.name": "magpie", "host.name": "机器"}}, + {"empty service name is unset", "service.name=,host.name=a", "", map[string]string{"service.name": "magpie", "host.name": "a"}}, + {"OTEL_SERVICE_NAME wins", "service.name=from-attrs,host.name=a", " gw-eu ", map[string]string{"service.name": "gw-eu", "host.name": "a"}}, + {"OTEL_SERVICE_NAME alone", "", "gw-eu", map[string]string{"service.name": "gw-eu"}}, + {"blank OTEL_SERVICE_NAME is unset", "service.name=custom", " ", map[string]string{"service.name": "custom"}}, + {"OTEL_SERVICE_NAME over a discarded variable", "host.name=a,broken", "gw-eu", map[string]string{"service.name": "gw-eu"}}, + {"missing equals", "host.name=server-a,broken", "", magpie}, + {"trailing comma", "host.name=server-a,", "", magpie}, + {"empty key", "host.name=server-a, =value", "", magpie}, + {"bad key escape", "host.name=server-a,bad%ZZ=value", "", magpie}, + {"bad value escape", "host.name=server-a,label=bad%ZZ", "", magpie}, + {"not UTF-8 once decoded", "host.name=server-a,label=%FF", "", magpie}, + } { + t.Run(tc.name, func(t *testing.T) { + got := exportResources(t, tc.attrs, tc.service) + for i, signal := range []string{"traces", "metrics"} { + if !reflect.DeepEqual(got[i], tc.want) { + t.Errorf("%s resource attributes = %v, want %v", signal, got[i], tc.want) + } + } + }) + } +} + +// A discarded variable is reported once, by position, never by its +// contents, however many exports read it. +func TestOTelResourceAttributesLoggedOnceWithoutContents(t *testing.T) { + var buf bytes.Buffer + prev, flags := log.Writer(), log.Flags() + log.SetOutput(&buf) + log.SetFlags(0) + defer func() { log.SetOutput(prev); log.SetFlags(flags) }() + attrs := "host.name=secret-host-7731,label=bad%ZZ" + exportResources(t, attrs, "") + exportResources(t, attrs, "") + out := buf.String() + if n := strings.Count(out, "OTEL_RESOURCE_ATTRIBUTES ignored"); n != 1 { + t.Fatalf("logged %d times, want once:\n%s", n, out) + } + if !strings.Contains(out, "entry 2") { + t.Errorf("log doesn't name the entry: %q", out) + } + for _, secret := range []string{"secret-host-7731", "host.name", "bad%ZZ"} { + if strings.Contains(out, secret) { + t.Errorf("log quotes %q: %q", secret, out) + } + } +} diff --git a/internal/otlp/otel_test.go b/internal/otlp/otel_test.go index da04a7ee9..56c2b84e0 100644 --- a/internal/otlp/otel_test.go +++ b/internal/otlp/otel_test.go @@ -26,6 +26,9 @@ func otelConfig(t *testing.T, config settings.OTel) { t.Setenv("MAGPIE_OTEL_ENDPOINT", config.Endpoint) t.Setenv("MAGPIE_OTEL_HEADERS", "Authorization=Bearer%20collector-test") t.Setenv("MAGPIE_OTEL_METRICS", "false") + // The shell's own resource variables never reach a test's export. + t.Setenv("OTEL_RESOURCE_ATTRIBUTES", "") + t.Setenv("OTEL_SERVICE_NAME", "") if config.Metrics { t.Setenv("MAGPIE_OTEL_METRICS", "true") } diff --git a/internal/otlp/otel_wire.go b/internal/otlp/otel_wire.go index 17b94b622..9842f0d61 100644 --- a/internal/otlp/otel_wire.go +++ b/internal/otlp/otel_wire.go @@ -50,7 +50,7 @@ func otelAttributes(r Record) []otelAttribute { func otelEnvelope(signal string, data any) map[string]any { return map[string]any{"resource" + signal: []any{map[string]any{ - "resource": map[string]any{"attributes": []otelAttribute{otelString("service.name", "magpie")}}, + "resource": map[string]any{"attributes": otelResourceAttributes()}, "scope" + signal: []any{map[string]any{"scope": map[string]any{"name": "github.com/yetone/magpie"}, map[string]string{"Spans": "spans", "Metrics": "metrics"}[signal]: data}}, }}} } diff --git a/site/public/docs/ja/privacy.html b/site/public/docs/ja/privacy.html index 337b424e1..ebc06ef59 100644 --- a/site/public/docs/ja/privacy.html +++ b/site/public/docs/ja/privacy.html @@ -187,7 +187,7 @@
モデルの価格と名前のために models.dev のカタログ(models.dev/api.json)を、あなたの通貨で価格を表示するために open.er-api.com から米ドルの為替レート(12 時間保持)を取得します。プラグインとその更新は npm レジストリから、ライブラリの項目は GitHub から取得します。どれも公開データの単なるダウンロードで、あなた、あなたのプロバイダー、使用量については何も送りません。ただし、どのリクエストとも同じく、これらのホストにはあなた(またはプロキシ)の IP アドレスが見えます。magpie は各プロバイダーにも、あなた自身のキーやサインインで残量とモデル一覧を尋ねます。設定 → 利用枠 → 利用枠の読み込み → 手動のみ で、頼んだときに限れます。
magpie はゲートウェイの各リクエストを、あなたの OpenTelemetry コレクター(Langfuse など)へエクスポートできます。既定ではオフで、送り先はあなたが設定したエンドポイントだけです。私たちには送りません。オンにすると、リクエストごとのスパン(エージェント、プロバイダー、モデル、トークン数、ステータス、時間、推定コスト)を送ります。別のスイッチで、メトリクス、ローカルのエージェント会話、リクエストと返答の本文(シークレットはマスク)を加えられます。設定 → オブザーバビリティ でオンにするか、magpie serve では MAGPIE_OTEL_ENABLED、MAGPIE_OTEL_ENDPOINT、MAGPIE_OTEL_HEADERS、MAGPIE_OTEL_METRICS、MAGPIE_OTEL_SESSIONS、MAGPIE_OTEL_BODIES、MAGPIE_OTEL_BODIES_WHOLE を使います。エンドポイントだけではオンになりません。Langfuse なら、そこで Langfuse を選び、ホストとプロジェクトの 2 つのキーを入力すると、magpie がエンドポイントと認証を作ります。詳しくはリファレンスを。
magpie はゲートウェイの各リクエストを、あなたの OpenTelemetry コレクター(Langfuse など)へエクスポートできます。既定ではオフで、送り先はあなたが設定したエンドポイントだけです。私たちには送りません。オンにすると、リクエストごとのスパン(エージェント、プロバイダー、モデル、トークン数、ステータス、時間、推定コスト)を送ります。別のスイッチで、メトリクス、ローカルのエージェント会話、リクエストと返答の本文(シークレットはマスク)を加えられます。設定 → オブザーバビリティ でオンにするか、magpie serve では MAGPIE_OTEL_ENABLED、MAGPIE_OTEL_ENDPOINT、MAGPIE_OTEL_HEADERS、MAGPIE_OTEL_METRICS、MAGPIE_OTEL_SESSIONS、MAGPIE_OTEL_BODIES、MAGPIE_OTEL_BODIES_WHOLE を使います。エンドポイントだけではオンになりません。Langfuse なら、そこで Langfuse を選び、ホストとプロジェクトの 2 つのキーを入力すると、magpie がエンドポイントと認証を作ります。各エクスポートの resource は service.name=magpie と、あなたが OTEL_RESOURCE_ATTRIBUTES と OTEL_SERVICE_NAME に自分で設定した値(サーバー名など)だけです。マシンの情報は調べません。詳しくはリファレンスを。
ここまでの節は magpie が自分で送るものです。エージェントが送る内容は選んだプロバイダに届きますが、プライバシーマスクはその中の秘密をこのコンピュータに留めます。既定ではオフで、設定 → プライバシー でオンにします。
diff --git a/site/public/docs/privacy.html b/site/public/docs/privacy.html index cc23d45c5..a020f9fa1 100644 --- a/site/public/docs/privacy.html +++ b/site/public/docs/privacy.html @@ -187,7 +187,7 @@To price and name models magpie fetches the models.dev catalog (models.dev/api.json), and for prices in your currency the USD exchange rate from open.er-api.com (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; Settings → Allowances → Allowance reads → When I ask limits those to when you ask.
magpie can export each gateway request to an OpenTelemetry collector of yours (Langfuse, for example). It is off by default, 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 Settings → Observability, or for magpie serve with MAGPIE_OTEL_ENABLED, MAGPIE_OTEL_ENDPOINT, MAGPIE_OTEL_HEADERS, MAGPIE_OTEL_METRICS, MAGPIE_OTEL_SESSIONS, MAGPIE_OTEL_BODIES and MAGPIE_OTEL_BODIES_WHOLE. An endpoint alone doesn’t turn it on. For Langfuse, pick Langfuse there and give its host and your project’s two keys; magpie makes the endpoint and sign-in from them. The reference has the details.
magpie can export each gateway request to an OpenTelemetry collector of yours (Langfuse, for example). It is off by default, 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 Settings → Observability, or for magpie serve with MAGPIE_OTEL_ENABLED, MAGPIE_OTEL_ENDPOINT, MAGPIE_OTEL_HEADERS, MAGPIE_OTEL_METRICS, MAGPIE_OTEL_SESSIONS, MAGPIE_OTEL_BODIES and MAGPIE_OTEL_BODIES_WHOLE. An endpoint alone doesn’t turn it on. For Langfuse, pick Langfuse there and give its host and your project’s two keys; magpie makes the endpoint and sign-in from them. Each export’s resource is service.name=magpie, plus only what you set yourself in OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME (a server name, for example); nothing about your machine is looked up. The reference has the details.
The sections above are what magpie sends by itself. What your agents send goes to the providers you chose, and privacy masking keeps the secrets in it on this computer. It is off by default; turn it on in Settings → Privacy.
diff --git a/site/public/docs/zh/privacy.html b/site/public/docs/zh/privacy.html index 47d4260ff..b7ac74e60 100644 --- a/site/public/docs/zh/privacy.html +++ b/site/public/docs/zh/privacy.html @@ -187,7 +187,7 @@为了给模型定价和命名,magpie 会拉取 models.dev 的模型目录(models.dev/api.json);为了用你的货币显示价格,会从 open.er-api.com 拉取美元汇率(缓存 12 小时)。插件及其更新来自 npm 仓库,库里的内容来自 GitHub。这些都是公开数据的普通下载,不发送任何关于你、你的供应商或用量的信息;和任何请求一样,这些主机能看到你的 IP(或代理的 IP)。magpie 还会用你自己的密钥或登录向各个供应商读取额度和模型列表;设置 → 额度 → 额度刷新 → 仅手动 可以只在你要求时才读。
magpie 可以把每个网关请求导出到你自己的 OpenTelemetry 收集器(比如 Langfuse)。它默认关闭,只发到你设置的地址,从不发给我们。开启后发送每个请求的 span:agent、供应商、模型、token 数、状态、耗时和估算费用。另有开关可以加上指标、本地 agent 对话,以及请求和回复正文(密钥已遮盖)。在 设置 → 可观测性 里开启,magpie serve 也可以用 MAGPIE_OTEL_ENABLED、MAGPIE_OTEL_ENDPOINT、MAGPIE_OTEL_HEADERS、MAGPIE_OTEL_METRICS、MAGPIE_OTEL_SESSIONS、MAGPIE_OTEL_BODIES 和 MAGPIE_OTEL_BODIES_WHOLE。只设地址不会开启导出。用 Langfuse 的话,在那里选 Langfuse,填上地址和项目的两个密钥,magpie 会据此生成地址和认证头。细节见参考文档。
magpie 可以把每个网关请求导出到你自己的 OpenTelemetry 收集器(比如 Langfuse)。它默认关闭,只发到你设置的地址,从不发给我们。开启后发送每个请求的 span:agent、供应商、模型、token 数、状态、耗时和估算费用。另有开关可以加上指标、本地 agent 对话,以及请求和回复正文(密钥已遮盖)。在 设置 → 可观测性 里开启,magpie serve 也可以用 MAGPIE_OTEL_ENABLED、MAGPIE_OTEL_ENDPOINT、MAGPIE_OTEL_HEADERS、MAGPIE_OTEL_METRICS、MAGPIE_OTEL_SESSIONS、MAGPIE_OTEL_BODIES 和 MAGPIE_OTEL_BODIES_WHOLE。只设地址不会开启导出。用 Langfuse 的话,在那里选 Langfuse,填上地址和项目的两个密钥,magpie 会据此生成地址和认证头。每次导出的 resource 是 service.name=magpie,再加上你自己在 OTEL_RESOURCE_ATTRIBUTES 和 OTEL_SERVICE_NAME 里设置的值(比如服务器名),不会读取你机器上的任何信息。细节见参考文档。
上面几节讲的是 magpie 自己发出的东西。你的 Agent 发出的内容会去往你选的供应商,隐私脱敏让其中的密钥留在这台电脑上。它默认关闭,在 设置 → 隐私 里打开。