Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(exporter): keep up to 16 KB of a browser chat answer (#1178)

Shukan Shah86e9fc76681d
diff --git a/collector-builder/exporter/beaconjsonexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
index ca447a22..85d6bbe1 100644
--- a/collector-builder/exporter/beaconjsonexporter/exporter_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
@@ -231,6 +231,50 @@ func TestJSONLWriterKeepsToolDescriptionsToThePromptTextLimit(t *testing.T) {
}
}
+// A browser chat answer keeps up to 16 KB and is written once, without its raw copy; every other
+// runtime's gen_ai output keeps the raw-attribute limit and its raw attributes as before.
+func TestJSONLWriterKeepsBrowserChatAnswersToTheResponseLimit(t *testing.T) {
+ writer := jsonlWriter{maxEventBytes: defaultMaxEventBytes, redactSecrets: true}
+ answerText := func(event beaconEvent) string {
+ messages := event.GenAI.Output.Messages.([]interface{})
+ parts := messages[0].(map[string]interface{})["parts"].([]interface{})
+ return parts[0].(map[string]interface{})["content"].(string)
+ }
+ for _, tc := range []struct {
+ harness, answer string
+ limit int
+ wantRawCopy bool
+ }{
+ {harness: "claude_web", answer: strings.Repeat("Sunny, high of 70. ", 500), limit: browserResponseStringLimit},
+ {harness: "chatgpt_web", answer: strings.Repeat("Sunny, high of 70. ", 2000), limit: browserResponseStringLimit},
+ {harness: "claude_code", answer: strings.Repeat("Sunny, high of 70. ", 500), limit: asymptoteobserve.DefaultRawStringLimit, wantRawCopy: true},
+ } {
+ messages := []interface{}{map[string]interface{}{
+ "role": "assistant",
+ "parts": []interface{}{map[string]interface{}{"type": "text", "content": tc.answer}},
+ }}
+ attrs := map[string]interface{}{"gen_ai.output.messages": `[{"role":"assistant"}]`, "beacon.response.chars": int64(len(tc.answer))}
+ event := newBeaconEvent("agent.response.completed", "agent", "info", tc.harness, time.Now())
+ event.GenAI = &beaconevent.GenAIInfo{Output: &beaconevent.GenAIOutputInfo{Messages: messages}}
+ event.Raw = map[string]interface{}{"attributes": attrs}
+
+ sanitized := writer.sanitize(event)
+ if got, want := answerText(sanitized), asymptoteobserve.TruncateString(tc.answer, tc.limit); got != want {
+ t.Errorf("%s: answer = %d bytes, want %d of %d", tc.harness, len(got), len(want), len(tc.answer))
+ }
+ _, rawCopy := sanitized.Raw["attributes"].(map[string]interface{})["gen_ai.output.messages"]
+ if rawCopy != tc.wantRawCopy {
+ t.Errorf("%s: raw copy of the answer kept = %v, want %v", tc.harness, rawCopy, tc.wantRawCopy)
+ }
+ if _, ok := sanitized.Raw["attributes"].(map[string]interface{})["beacon.response.chars"]; !ok {
+ t.Errorf("%s: beacon.response.chars dropped from raw", tc.harness)
+ }
+ if _, ok := attrs["gen_ai.output.messages"]; !ok {
+ t.Errorf("%s: the caller's attributes were changed", tc.harness)
+ }
+ }
+}
+
// A gen_ai block holding a value JSON cannot represent (NaN, an out-of-range integer) is sanitized
// like any other: its text redacted and cut, the value that cannot be represented left out.
func TestJSONLWriterSanitizesGenAIHoldingUnrepresentableValues(t *testing.T) {
diff --git a/collector-builder/exporter/beaconjsonexporter/writer.go b/collector-builder/exporter/beaconjsonexporter/writer.go
index f744132b..97ca60e4 100644
--- a/collector-builder/exporter/beaconjsonexporter/writer.go
+++ b/collector-builder/exporter/beaconjsonexporter/writer.go
@@ -130,11 +130,23 @@ func (w jsonlWriter) sanitize(event beaconEvent) beaconEvent {
if event.MCP != nil {
event.MCP = asymptoteobserve.SanitizeMCP(event.MCP, w.privacyOptions())
}
+ browserResponse := event.GenAI != nil && event.GenAI.Output != nil && browserChatHarnesses[event.Harness.Name]
if event.GenAI != nil {
+ output := event.GenAI.Output
event.GenAI = asymptoteobserve.SanitizeGenAI(event.GenAI, w.privacyOptions())
+ if browserResponse {
+ opts := w.privacyOptions()
+ opts.StringLimit = browserResponseStringLimit
+ event.GenAI.Output = asymptoteobserve.SanitizeGenAI(&beaconevent.GenAIInfo{Output: output}, opts).Output
+ }
}
if event.Raw != nil {
event.Raw = w.sanitizeMap(event.Raw)
+ // The answer is in gen_ai.output.messages already, so the raw copy would only add its first
+ // 2 KB to the line again. SanitizeMap returned new maps, so this leaves the caller's alone.
+ if attrs, ok := event.Raw["attributes"].(map[string]interface{}); ok && browserResponse {
+ delete(attrs, "gen_ai.output.messages")
+ }
}
if data, err := json.Marshal(event); err == nil && len(data) > w.maxEventBytes {
event.Truncated = true
@@ -142,6 +154,13 @@ func (w jsonlWriter) sanitize(event beaconEvent) beaconEvent {
return event
}
+// A claude.ai or chatgpt.com answer is what a browser chat event is about, and most run past the
+// 2 KB raw-attribute limit the rest of gen_ai keeps, so the log keeps up to 16 KB of it. A coding
+// agent's reply rarely needs more, and its OTLP gen_ai fields can carry whole message histories.
+const browserResponseStringLimit = 16 * 1024
+
+var browserChatHarnesses = map[string]bool{"claude_web": true, "chatgpt_web": true}
+
func (w jsonlWriter) sanitizeMap(input map[string]interface{}) map[string]interface{} {
return asymptoteobserve.SanitizeMap(input, w.privacyOptions())
}
diff --git a/docs/runtimes/browser-extension.mdx b/docs/runtimes/browser-extension.mdx
index 76d3fc60..4e8b095c 100644
--- a/docs/runtimes/browser-extension.mdx
+++ b/docs/runtimes/browser-extension.mdx
@@ -156,11 +156,19 @@ Retention defaults to `full`. Browser chat telemetry has little investigative va
| Mode | What is retained |
|------|------------------|
-| `full` (default) | Complete prompt text, full assistant response, tool call arguments and results |
+| `full` (default) | Prompt text, assistant response, tool call arguments and results |
| `redacted` | The same text with emails and API-key-shaped tokens scrubbed in the browser |
| `metadata` | No chat text. Actions, models, token counts, and tool names only |
-Retention is enforced in the browser before anything is sent, so under `metadata` the text never leaves the page. Endpoint-side redaction, sanitization, truncation, and event-size limits apply to whatever is sent.
+Retention is enforced in the browser before anything is sent, so under `metadata` the text never leaves the page. The extension sends at most 48,000 bytes of any one field, and the endpoint redacts secrets and keeps less of some fields when it writes the log:
+
+| Event field | Kept in the log |
+|-------------|-----------------|
+| `prompt.text` | The first 4 KB of the prompt |
+| `gen_ai.output.messages` | The first 16 KB of the response |
+| `gen_ai.tool.call.arguments`, `gen_ai.tool.call.result` | The first 2 KB of each value |
+
+A value that was cut ends in `...[truncated]`. The response's full length is in `raw.attributes["beacon.response.chars"]`.
Change the mode in the extension's popup before enabling it on a machine where the same browser profile is used for personal conversations.
@@ -204,9 +212,9 @@ Coverage that is the same for both sites:
| Area | Support |
|------|---------|
-| Prompt telemetry | Supported, with full prompt text under `full` and `redacted` retention |
+| Prompt telemetry | Supported, with prompt text under `full` and `redacted` retention |
| Turn identity | Supported. Each chat request's turn id is sent as `beacon.prompt.id` and lands in `prompt.id` |
-| Assistant response telemetry | Supported, including the response text and model |
+| Assistant response telemetry | Supported. `agent.response.completed` events carry the response text in `gen_ai.output.messages` and the model |
| Reasoning telemetry | Not available. Neither site sends the model's reasoning to the page, only short summaries of it, and those summaries are not recorded |
| Command and file telemetry | Not applicable. Browser chat performs no local commands or file edits |
| Approval telemetry | Not available. Neither site exposes approval decisions to a page script |