The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Promote prompt.id from OTLP and the browser extension
Claudeb2b2ae3f71e4
diff --git a/browser-extension/src/shared/normalize.ts b/browser-extension/src/shared/normalize.tsindex 4ad8cc5b..8cd847f0 100644--- a/browser-extension/src/shared/normalize.ts+++ b/browser-extension/src/shared/normalize.ts@@ -107,6 +107,7 @@ export function normalizeTurn(str('beacon.content.retention', retention),str('beacon.record.id', recordId(tid, action, index)),str('beacon.capture.mode', turn.captureMode),+ ...promptIdAttr(turn),];// ---- prompt.submitted ----@@ -207,6 +208,16 @@ export function normalizeTurn(return { resourceAttributes, logRecords };}+/**+ * The turn's id as beacon.prompt.id, which the collector promotes to the+ * event's prompt.id: one chat request is one prompt and everything the reply+ * did for it. Only an id the adapter derived from the request is used; the+ * session-level fallback in tid would put every unidentified turn under one id.+ */+function promptIdAttr(turn: ChatTurn): KeyValue[] {+ return turn.turnId ? [str('beacon.prompt.id', turn.turnId)] : [];+}+function toolRecord(turn: ChatTurn,tool: ToolCall,@@ -223,6 +234,7 @@ function toolRecord(str('gen_ai.conversation.id', turn.sessionId),str('beacon.content.retention', retention),str('beacon.record.id', recordId(tid, action, index)),+ ...promptIdAttr(turn),str('tool.name', tool.name),str('gen_ai.tool.call.id', tool.id),str('gen_ai.tool.call.name', tool.name),diff --git a/browser-extension/test/unit/normalize.test.ts b/browser-extension/test/unit/normalize.test.tsindex 7641a7fd..ebb4b9dc 100644--- a/browser-extension/test/unit/normalize.test.ts+++ b/browser-extension/test/unit/normalize.test.ts@@ -309,3 +309,22 @@ describe('normalizeTurn — browser identity', () => {]);});});++describe('normalizeTurn — prompt id', () => {+ it('puts the turn id on every record as beacon.prompt.id', () => {+ const { logRecords } = normalize(+ baseTurn({ toolCalls: [{ id: 'tool-1', name: 'web_search', arguments: { q: 'x' } }] }),+ );+ expect(logRecords.length).toBeGreaterThanOrEqual(3);+ for (const rec of logRecords) {+ expect(flat(rec.attributes)['beacon.prompt.id']).toBe('conv-123:1');+ }+ });++ it('omits it when the adapter had no turn id, rather than sharing one fallback id', () => {+ const { logRecords } = normalize(baseTurn({ turnId: '' }));+ for (const rec of logRecords) {+ expect(flat(rec.attributes)['beacon.prompt.id']).toBeUndefined();+ }+ });+});diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/content.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/content.goindex ec5cdc7b..16cdbbd0 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/content.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/content.go@@ -82,7 +82,7 @@ func (c Converter) PromoteRetainedContent(event *Event, attrs map[string]interfaif promptText == "" && isPromptEvent(event) {promptText = FirstNonEmpty(FirstTextAttr(attrs, PromptTextKeys...), FirstMessageText(event.GenAI))if promptText != "" {- event.Prompt = &PromptInfo{Text: promptText}+ SetPromptText(event, promptText)}}diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.goindex af0be8ff..109abee3 100644--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/converter.go@@ -1185,9 +1185,18 @@ func (c Converter) PopulateCommon(event *Event, attrs map[string]interface{}) {}if event.Event.Category == "prompt" {if text := FirstNonEmpty(FirstTextAttr(attrs, PromptTextKeys...), FirstMessageText(event.GenAI)); text != "" {- event.Prompt = &PromptInfo{Text: text}+ SetPromptText(event, text)}}+ // The prompt this event belongs to. Claude Code writes it as prompt.id on every event of a+ // turn, Gemini CLI as prompt_id, Codex as turn.id; the alias list is shared with the hook path+ // so both capture paths put one turn under one value.+ if id := asymptoteobserve.PromptIDFrom(attrs); id != "" {+ if event.Prompt == nil {+ event.Prompt = &PromptInfo{}+ }+ event.Prompt.ID = id+ }}func GenAIFromAttrs(attrs map[string]interface{}) *GenAIInfo {@@ -2109,6 +2118,14 @@ func HasToolCall(attrs map[string]interface{}) bool {return IsMeaningfulValue(attrs["gen_ai.tool.call.arguments"])}+// SetPromptText records an event's prompt text, keeping the prompt id already on it.+func SetPromptText(event *Event, text string) {+ if event.Prompt == nil {+ event.Prompt = &PromptInfo{}+ }+ event.Prompt.Text = text+}+// ToolCallID reads the runtime's own identifier for one tool invocation.//// Claude Code writes it as tool_use_id and Codex as call_id; neither name wasdiff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/prompt_id_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/prompt_id_test.gonew file mode 100644index 00000000..3a2ababe--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/prompt_id_test.go@@ -0,0 +1,76 @@+package beaconevent++import (+ "testing"++ "go.opentelemetry.io/collector/pdata/plog"+)++// Claude Code stamps prompt.id on every event of a turn. Each one lands in prompt.id, the prompt's+// own text stays beside it, and an event Claude Code did not stamp gets no prompt object -- an+// empty one would read as a prompt to anything that checks for its presence.+func TestCapturedClaudeCoworkPromptIDOnEveryEventOfTheTurn(t *testing.T) {+ t.Setenv("UID", "501")+ fixture, events := capturedLogEvents(t, "claude-cowork-2.1.251.json")+ stamped := 0+ for i, record := range fixture.Records {+ want, _ := record.Attributes["prompt.id"].(string)+ event := events[i]+ if want == "" {+ if event.Prompt != nil && event.Prompt.ID != "" {+ t.Fatalf("%s prompt.id = %q, want none", record.Name, event.Prompt.ID)+ }+ continue+ }+ stamped+++ if event.Prompt == nil || event.Prompt.ID != want {+ t.Fatalf("%s prompt = %#v, want id %q", record.Name, event.Prompt, want)+ }+ if record.Name != "user_prompt" && event.Prompt.Text != "" {+ t.Fatalf("%s prompt.text = %q, want text only on the prompt itself", record.Name, event.Prompt.Text)+ }+ }+ if stamped == 0 {+ t.Fatal("fixture has no prompt.id records; the test asserts nothing")+ }+ for i, record := range fixture.Records {+ if record.Name == "user_prompt" && events[i].Prompt.Text != "COWORK_PROMPT_MARKER" {+ t.Fatalf("user_prompt text = %q, want it kept beside the id", events[i].Prompt.Text)+ }+ }+}++// Each runtime's OTLP spelling lands in the same field.+func TestOTLPPromptIDSpellingsNormalize(t *testing.T) {+ for name, tc := range map[string]struct {+ service string+ attrs map[string]interface{}+ want string+ }{+ "gemini cli prompt_id": {"gemini-cli", map[string]interface{}{"event.name": "gemini_cli.tool_call", "session.id": "g", "prompt_id": "g########2"}, "g########2"},+ "codex turn.id": {"codex_cli_rs", map[string]interface{}{"event.name": "codex.tool_result", "conversation.id": "c", "turn.id": "turn-9"}, "turn-9"},+ "beacon canonical": {"agent", map[string]interface{}{"beacon.event.action": "tool.invoked", "beacon.session.id": "s", "beacon.prompt.id": "p-1"}, "p-1"},+ "none": {"agent", map[string]interface{}{"beacon.event.action": "tool.invoked", "beacon.session.id": "s"}, ""},+ } {+ t.Run(name, func(t *testing.T) {+ logs := plog.NewLogs()+ rl := logs.ResourceLogs().AppendEmpty()+ rl.Resource().Attributes().PutStr("service.name", tc.service)+ record := rl.ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()+ if err := record.Attributes().FromRaw(tc.attrs); err != nil {+ t.Fatal(err)+ }+ events := NewConverter(Options{}).EventsFromLogs(logs)+ if len(events) != 1 {+ t.Fatalf("events = %d, want 1", len(events))+ }+ got := ""+ if events[0].Prompt != nil {+ got = events[0].Prompt.ID+ }+ if got != tc.want {+ t.Fatalf("prompt.id = %q, want %q", got, tc.want)+ }+ })+ }+}diff --git a/collector-builder/exporter/beaconjsonexporter/prompt_id_e2e_test.go b/collector-builder/exporter/beaconjsonexporter/prompt_id_e2e_test.gonew file mode 100644index 00000000..9e9f8a4d--- /dev/null+++ b/collector-builder/exporter/beaconjsonexporter/prompt_id_e2e_test.go@@ -0,0 +1,79 @@+package beaconjsonexporter++import (+ "context"+ "encoding/json"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "go.opentelemetry.io/collector/exporter"+ "go.opentelemetry.io/collector/pdata/plog"+)++// Claude Code's events of one turn reach the runtime log under one prompt.id, written by the real+// exporter. The prompt whose text is too large for the event ceiling loses its text to compaction+// and keeps its id, because the id is what places it in the turn.+func TestConsumeLogsWritesClaudePromptIDThroughCompaction(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ exp, err := newExporter(&Config{+ Path: path,+ MaxEventBytes: 4096, // below the 4 KiB the prompt keeps after truncation, so compaction runs+ RotateBytes: defaultRotateBytes,+ RedactSecrets: true,+ }, exporter.Settings{})+ if err != nil {+ t.Fatalf("newExporter returned error: %v", err)+ }++ logs := plog.NewLogs()+ rl := logs.ResourceLogs().AppendEmpty()+ rl.Resource().Attributes().PutStr("service.name", "claude-code")+ records := rl.ScopeLogs().AppendEmpty().LogRecords()+ add := func(name string, attrs map[string]interface{}) {+ rec := records.AppendEmpty()+ rec.Body().SetStr("claude_code." + name)+ attrs["event.name"] = name+ attrs["session.id"] = "claude-session"+ attrs["prompt.id"] = "6f1c2c1e-prompt"+ if err := rec.Attributes().FromRaw(attrs); err != nil {+ t.Fatal(err)+ }+ }+ add("user_prompt", map[string]interface{}{"prompt": strings.Repeat("summarize this log ", 4000), "prompt_length": "76000"})+ add("tool_result", map[string]interface{}{"tool_name": "Bash", "success": "true", "tool_use_id": "toolu_1"})+ add("api_request", map[string]interface{}{"model": "claude-sonnet-4-5", "input_tokens": "10", "output_tokens": "4"})++ if err := exp.consumeLogs(context.Background(), logs); err != nil {+ t.Fatalf("consumeLogs returned error: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ lines := strings.Split(strings.TrimSpace(string(data)), "\n")+ if len(lines) != 3 {+ t.Fatalf("wrote %d events, want 3:\n%s", len(lines), data)+ }+ for _, line := range lines {+ var event struct {+ Event struct {+ Action string `json:"action"`+ } `json:"event"`+ Prompt *struct {+ ID string `json:"id"`+ Text string `json:"text"`+ } `json:"prompt"`+ }+ if err := json.Unmarshal([]byte(line), &event); err != nil {+ t.Fatal(err)+ }+ if event.Prompt == nil || event.Prompt.ID != "6f1c2c1e-prompt" {+ t.Fatalf("%s prompt = %+v, want the turn's id", event.Event.Action, event.Prompt)+ }+ if event.Prompt.Text != "" {+ t.Fatalf("%s kept %d bytes of prompt text past the ceiling", event.Event.Action, len(event.Prompt.Text))+ }+ }+}diff --git a/docs/runtimes/browser-extension.mdx b/docs/runtimes/browser-extension.mdxindex 87e13684..f7e9bd51 100644--- a/docs/runtimes/browser-extension.mdx+++ b/docs/runtimes/browser-extension.mdx@@ -205,6 +205,7 @@ Coverage that is the same for both sites:| Area | Support ||------|---------|| Prompt telemetry | Supported, with full 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 || 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 |diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdxindex 8aa8556d..65f45582 100644--- a/docs/runtimes/claude-code.mdx+++ b/docs/runtimes/claude-code.mdx@@ -75,6 +75,7 @@ Beacon detects Claude Code through the `claude` executable and Claude settings p| Area | Support ||------|---------|| Prompt telemetry | Supported when emitted through Claude Code OTLP or hooks |+| Turn identity | Supported on OTLP events, where Claude Code's `prompt.id` is kept as `prompt.id` || Command, tool, and file telemetry | Supported through Claude Code OTLP with detailed tool inputs enabled || Token usage and cost | Supported through OTLP token and cost metrics, with per-model and per-session attribution || Hook lifecycle and tool telemetry | Optional through `beacon endpoint hooks install --harness claude` |diff --git a/docs/runtimes/gemini-cli.mdx b/docs/runtimes/gemini-cli.mdxindex c10f49c2..4624d7b4 100644--- a/docs/runtimes/gemini-cli.mdx+++ b/docs/runtimes/gemini-cli.mdx@@ -38,6 +38,7 @@ Gemini CLI is not currently configured through Beacon's hook adapter.| Area | Support ||------|---------|| Prompt telemetry | Supported when emitted through Gemini OTLP |+| Turn identity | Supported. Gemini CLI's `prompt_id` is promoted to `prompt.id` || Command, tool, and file telemetry | Supported for prompts, tool calls, MCP activity, file operations, and approval-related events emitted through OTLP || Token usage | Supported from the `gemini_cli.api_response` log and `gemini_cli.token.usage` counter: input, output, cache read, and thinking tokens as reasoning, per session. Gemini CLI reports no cost. See [Token usage](/cli/token-usage) for how Gemini's overlapping counts are made disjoint || Local JSONL and dashboard | Supported |