Skip to content

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

Reduce Codex telemetry noise

shukieshahe334c4b5b1af
diff --git a/README.md b/README.md
index b4ca0e4c..ce138697 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,14 @@ easy to inspect. Advanced deployments can opt back into those low-level OTLP
metrics with `beacon endpoint install --include-runtime-metrics` or
`beacon endpoint repair --include-runtime-metrics`.
+Codex CLI can also emit high-volume internal spans for startup, dispatch, model
+requests, streaming, and transport activity. Beacon keeps the default Codex path
+low-noise by recording semantic Codex log events for sessions, prompts,
+approvals, and tool results while dropping Codex spans. For troubleshooting
+Codex OTLP internals, opt back into those spans with
+`beacon endpoint install --include-codex-spans` or
+`beacon endpoint repair --include-codex-spans`.
+
## Dashboard
Beacon includes a local, read-only dashboard for validating endpoint activity
diff --git a/cli/beacon/cmd/endpoint.go b/cli/beacon/cmd/endpoint.go
index 6159c12c..b94b4bc0 100644
--- a/cli/beacon/cmd/endpoint.go
+++ b/cli/beacon/cmd/endpoint.go
@@ -37,6 +37,7 @@ var endpointOpts struct {
httpPort int
collectorPath string
includeRuntimeMetrics bool
+ includeCodexSpans bool
keepLogs bool
keepConfig bool
noStart bool
@@ -315,6 +316,7 @@ func init() {
endpointInstallCmd.Flags().IntVar(&endpointOpts.httpPort, "otlp-http-port", endpointconfig.DefaultHTTPPort, "Local OTLP HTTP port")
endpointInstallCmd.Flags().StringVar(&endpointOpts.collectorPath, "collector", "", "Path to a beacon-otelcol binary")
endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeRuntimeMetrics, "include-runtime-metrics", false, "Include generic process/runtime OTLP metrics in the runtime JSONL log")
+ endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeCodexSpans, "include-codex-spans", false, "Include high-volume Codex OTLP spans for troubleshooting")
endpointInstallCmd.Flags().BoolVar(&endpointOpts.noStart, "no-start", false, "Write files without starting the launchd service")
endpointInstallCmd.Flags().StringVar(&endpointOpts.contentRetention, "content-retention", "full", "Content retention mode: metadata, redacted, or full")
registerSplunkFlags(endpointInstallCmd)
@@ -323,6 +325,7 @@ func init() {
endpointRepairCmd.Flags().IntVar(&endpointOpts.httpPort, "otlp-http-port", endpointconfig.DefaultHTTPPort, "Local OTLP HTTP port")
endpointRepairCmd.Flags().StringVar(&endpointOpts.collectorPath, "collector", "", "Path to a beacon-otelcol binary")
endpointRepairCmd.Flags().BoolVar(&endpointOpts.includeRuntimeMetrics, "include-runtime-metrics", false, "Include generic process/runtime OTLP metrics in the runtime JSONL log")
+ endpointRepairCmd.Flags().BoolVar(&endpointOpts.includeCodexSpans, "include-codex-spans", false, "Include high-volume Codex OTLP spans for troubleshooting")
endpointRepairCmd.Flags().BoolVar(&endpointOpts.noStart, "no-start", false, "Write files without starting the launchd service")
endpointRepairCmd.Flags().StringVar(&endpointOpts.contentRetention, "content-retention", "full", "Content retention mode: metadata, redacted, or full")
registerSplunkFlags(endpointRepairCmd)
@@ -718,6 +721,7 @@ func runEndpointInstall(cmd *cobra.Command, args []string) error {
StartService: !endpointOpts.noStart,
ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
+ IncludeCodexSpans: endpointOpts.includeCodexSpans,
SplunkHEC: splunkHECOptions(),
})
if err != nil {
@@ -840,6 +844,7 @@ func runEndpointRepair(cmd *cobra.Command, args []string) error {
StartService: !endpointOpts.noStart,
ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
+ IncludeCodexSpans: endpointOpts.includeCodexSpans,
SplunkHEC: splunkHECOptions(),
})
if err != nil {
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index fff4653c..f3b6f957 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -193,11 +193,14 @@ func TestEndpointInstallAndRepairSupportSplunkFlags(t *testing.T) {
}
}
-func TestEndpointInstallAndRepairSupportRuntimeMetricsFlag(t *testing.T) {
+func TestEndpointInstallAndRepairSupportDebugTelemetryFlags(t *testing.T) {
for _, cmd := range []*cobra.Command{endpointInstallCmd, endpointRepairCmd} {
if cmd.Flags().Lookup("include-runtime-metrics") == nil {
t.Fatalf("%s command missing --include-runtime-metrics flag", cmd.Use)
}
+ if cmd.Flags().Lookup("include-codex-spans") == nil {
+ t.Fatalf("%s command missing --include-codex-spans flag", cmd.Use)
+ }
}
}
diff --git a/cli/beacon/internal/endpoint/collector/collector.go b/cli/beacon/internal/endpoint/collector/collector.go
index ed4cf0ae..66818b2a 100644
--- a/cli/beacon/internal/endpoint/collector/collector.go
+++ b/cli/beacon/internal/endpoint/collector/collector.go
@@ -119,6 +119,10 @@ func ConfigYAML(cfg endpointconfig.Config) string {
if cfg.Collector.IncludeRuntimeMetrics {
runtimeMetricsYAML = " include_runtime_metrics: true\n"
}
+ codexSpansYAML := ""
+ if cfg.Collector.IncludeCodexSpans {
+ codexSpansYAML = " include_codex_spans: true\n"
+ }
return fmt.Sprintf(`receivers:
otlp:
protocols:
@@ -165,7 +169,7 @@ service:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: %s
-`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, runtimeMetricsYAML+splunkExporter, exporters, exporters, exporters)
+`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, runtimeMetricsYAML+codexSpansYAML+splunkExporter, exporters, exporters, exporters)
}
func splunkHECYAML(cfg endpointconfig.Config) string {
diff --git a/cli/beacon/internal/endpoint/collector/collector_test.go b/cli/beacon/internal/endpoint/collector/collector_test.go
index bfc858ba..0efbbe19 100644
--- a/cli/beacon/internal/endpoint/collector/collector_test.go
+++ b/cli/beacon/internal/endpoint/collector/collector_test.go
@@ -52,6 +52,9 @@ func TestConfigYAMLIncludesReleaseContractFields(t *testing.T) {
if strings.Contains(yaml, "include_runtime_metrics") {
t.Fatalf("ConfigYAML should omit runtime metrics option unless explicitly enabled:\n%s", yaml)
}
+ if strings.Contains(yaml, "include_codex_spans") {
+ t.Fatalf("ConfigYAML should omit Codex span option unless explicitly enabled:\n%s", yaml)
+ }
}
func TestConfigYAMLIncludesRuntimeMetricsOptIn(t *testing.T) {
@@ -64,6 +67,16 @@ func TestConfigYAMLIncludesRuntimeMetricsOptIn(t *testing.T) {
}
}
+func TestConfigYAMLIncludesCodexSpansOptIn(t *testing.T) {
+ cfg := testConfig(t)
+ cfg.Collector.IncludeCodexSpans = true
+
+ yaml := ConfigYAML(cfg)
+ if !strings.Contains(yaml, "include_codex_spans: true") {
+ t.Fatalf("ConfigYAML missing Codex spans opt-in:\n%s", yaml)
+ }
+}
+
func TestConfigYAMLIncludesSplunkHECWhenConfigured(t *testing.T) {
cfg := testConfig(t)
cfg.Destinations = &endpointconfig.Destinations{SplunkHEC: &endpointconfig.SplunkHEC{
diff --git a/cli/beacon/internal/endpoint/config/config.go b/cli/beacon/internal/endpoint/config/config.go
index 2f987fb0..8127e837 100644
--- a/cli/beacon/internal/endpoint/config/config.go
+++ b/cli/beacon/internal/endpoint/config/config.go
@@ -44,6 +44,7 @@ type Collector struct {
HTTPPort int `json:"http_port"`
SpoolPath string `json:"spool_path,omitempty"`
IncludeRuntimeMetrics bool `json:"include_runtime_metrics,omitempty"`
+ IncludeCodexSpans bool `json:"include_codex_spans,omitempty"`
}
type Destinations struct {
diff --git a/cli/beacon/internal/endpoint/config/config_test.go b/cli/beacon/internal/endpoint/config/config_test.go
index 05acc4ee..15d81575 100644
--- a/cli/beacon/internal/endpoint/config/config_test.go
+++ b/cli/beacon/internal/endpoint/config/config_test.go
@@ -40,6 +40,7 @@ func TestSaveLoadRoundTrip(t *testing.T) {
cfg := Default(true, logPath)
cfg.Collector.BinaryPath = filepath.Join(home, "bin", "otelcol")
cfg.Collector.IncludeRuntimeMetrics = true
+ cfg.Collector.IncludeCodexSpans = true
cfg.EventCategories = []string{"tool", "session"}
cfg.ContentRetention = ContentRetentionRedacted
@@ -64,6 +65,9 @@ func TestSaveLoadRoundTrip(t *testing.T) {
if !loaded.Collector.IncludeRuntimeMetrics {
t.Fatal("IncludeRuntimeMetrics = false, want true")
}
+ if !loaded.Collector.IncludeCodexSpans {
+ t.Fatal("IncludeCodexSpans = false, want true")
+ }
if len(loaded.EventCategories) != 2 || loaded.EventCategories[1] != "session" {
t.Fatalf("EventCategories did not round-trip: %#v", loaded.EventCategories)
}
diff --git a/cli/beacon/internal/endpoint/elastic/elastic_test.go b/cli/beacon/internal/endpoint/elastic/elastic_test.go
index dff7b713..31868fe8 100644
--- a/cli/beacon/internal/endpoint/elastic/elastic_test.go
+++ b/cli/beacon/internal/endpoint/elastic/elastic_test.go
@@ -83,7 +83,7 @@ func TestPackJSONFilesAreValid(t *testing.T) {
func TestKibanaAssetsAreParseableNDJSON(t *testing.T) {
scanner := bufio.NewScanner(strings.NewReader(mustRead("pack/kibana-assets.ndjson")))
line := 0
- var foundDataView bool
+ var foundDataView, foundPromptColumn bool
for scanner.Scan() {
line++
var doc map[string]interface{}
@@ -102,6 +102,21 @@ func TestKibanaAssetsAreParseableNDJSON(t *testing.T) {
foundDataView = true
}
}
+ if doc["type"] == "search" {
+ attrs, ok := doc["attributes"].(map[string]interface{})
+ if !ok {
+ t.Fatalf("kibana search missing attributes: %#v", doc)
+ }
+ columns, ok := attrs["columns"].([]interface{})
+ if !ok {
+ t.Fatalf("kibana search missing columns: %#v", attrs)
+ }
+ for _, column := range columns {
+ if column == "beacon.prompt.text" {
+ foundPromptColumn = true
+ }
+ }
+ }
}
if err := scanner.Err(); err != nil {
t.Fatal(err)
@@ -112,6 +127,9 @@ func TestKibanaAssetsAreParseableNDJSON(t *testing.T) {
if !foundDataView {
t.Fatal("kibana-assets.ndjson should include the Beacon Endpoint Events data view")
}
+ if !foundPromptColumn {
+ t.Fatal("kibana saved search should expose beacon.prompt.text so prompts are visible in Elastic")
+ }
}
func TestPackREADMEUsesIngestedFieldNames(t *testing.T) {
diff --git a/cli/beacon/internal/endpoint/elastic/pack/kibana-assets.ndjson b/cli/beacon/internal/endpoint/elastic/pack/kibana-assets.ndjson
index cc685eae..19f8c3f9 100644
--- a/cli/beacon/internal/endpoint/elastic/pack/kibana-assets.ndjson
+++ b/cli/beacon/internal/endpoint/elastic/pack/kibana-assets.ndjson
@@ -1,2 +1,2 @@
{"type":"index-pattern","id":"beacon-endpoint-data-view","attributes":{"title":"logs-beacon.endpoint-*","timeFieldName":"@timestamp","name":"Beacon Endpoint Events"},"references":[],"coreMigrationVersion":"8.8.0","typeMigrationVersion":"8.0.0"}
-{"type":"search","id":"beacon-all-agent-activity","attributes":{"title":"Beacon: all agent activity","description":"All Beacon endpoint events","columns":["@timestamp","event.action","beacon.harness.name","user.name","message"],"sort":[["@timestamp","desc"]],"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"language\":\"kuery\",\"query\":\"event.dataset: beacon.endpoint\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"}},"references":[{"name":"kibanaSavedObjectMeta.searchSourceJSON.index","type":"index-pattern","id":"beacon-endpoint-data-view"}],"coreMigrationVersion":"8.8.0","typeMigrationVersion":"8.0.0"}
+{"type":"search","id":"beacon-all-agent-activity","attributes":{"title":"Beacon: all agent activity","description":"All Beacon endpoint events","columns":["@timestamp","event.action","beacon.harness.name","beacon.prompt.text","user.name","message"],"sort":[["@timestamp","desc"]],"kibanaSavedObjectMeta":{"searchSourceJSON":"{\"query\":{\"language\":\"kuery\",\"query\":\"event.dataset: beacon.endpoint\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"}},"references":[{"name":"kibanaSavedObjectMeta.searchSourceJSON.index","type":"index-pattern","id":"beacon-endpoint-data-view"}],"coreMigrationVersion":"8.8.0","typeMigrationVersion":"8.0.0"}
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.go
index 19a0da71..46e4da32 100644
--- a/cli/beacon/internal/endpoint/harness/harness.go
+++ b/cli/beacon/internal/endpoint/harness/harness.go
@@ -369,12 +369,6 @@ func codexOTELBlock(endpoint string, logUserPrompt bool) []string {
"",
"[otel.exporter.\"otlp-grpc\"]",
fmt.Sprintf("endpoint = %q", endpoint),
- "",
- "[otel.trace_exporter.\"otlp-grpc\"]",
- fmt.Sprintf("endpoint = %q", endpoint),
- "",
- "[otel.metrics_exporter.\"otlp-grpc\"]",
- fmt.Sprintf("endpoint = %q", endpoint),
}
}
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index d9e8d443..42326165 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -175,14 +175,20 @@ func TestConfigureCodexWritesTelemetryBlockAndBackup(t *testing.T) {
"environment = \"dev\"",
"log_user_prompt = true",
"[otel.exporter.\"otlp-grpc\"]",
- "[otel.trace_exporter.\"otlp-grpc\"]",
- "[otel.metrics_exporter.\"otlp-grpc\"]",
"endpoint = \"http://127.0.0.1:4317\"",
} {
if !strings.Contains(text, want) {
t.Fatalf("codex config missing %q:\n%s", want, text)
}
}
+ for _, noisy := range []string{
+ "[otel.trace_exporter.\"otlp-grpc\"]",
+ "[otel.metrics_exporter.\"otlp-grpc\"]",
+ } {
+ if strings.Contains(text, noisy) {
+ t.Fatalf("codex config should not enable noisy exporter %q:\n%s", noisy, text)
+ }
+ }
backups, err := filepath.Glob(path + ".beacon.*.bak")
if err != nil {
t.Fatalf("glob backups: %v", err)
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index 4920f617..5f87f859 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -28,6 +28,7 @@ type InstallOptions struct {
StartService bool
ContentRetention endpointconfig.ContentRetention
IncludeRuntimeMetrics bool
+ IncludeCodexSpans bool
SplunkHEC *endpointconfig.SplunkHEC
}
@@ -281,6 +282,7 @@ func buildConfig(opts InstallOptions) endpointconfig.Config {
}
cfg.Collector.BinaryPath = opts.CollectorPath
cfg.Collector.IncludeRuntimeMetrics = opts.IncludeRuntimeMetrics
+ cfg.Collector.IncludeCodexSpans = opts.IncludeCodexSpans
if opts.ContentRetention != "" {
cfg.ContentRetention = opts.ContentRetention
}
diff --git a/collector-builder/exporter/beaconjsonexporter/README.md b/collector-builder/exporter/beaconjsonexporter/README.md
index e6213781..258a8b67 100644
--- a/collector-builder/exporter/beaconjsonexporter/README.md
+++ b/collector-builder/exporter/beaconjsonexporter/README.md
@@ -20,6 +20,16 @@ Required behavior:
- Redact common secrets and cap event size before writing.
- Emit health failure events when write failures occur.
+Noise controls:
+
+- Generic process/runtime metrics are dropped by default unless
+ `include_runtime_metrics: true` is set.
+- Codex spans are dropped by default because Codex semantic logs carry the
+ endpoint activity Beacon needs. Set `include_codex_spans: true` only when
+ troubleshooting Codex OTLP internals.
+- Codex metrics and transport/startup/debug logs remain suppressed by default so
+ one prompt does not flood the endpoint runtime log.
+
The production implementation should live here and be included by
`collector-builder/builder.yaml`.
diff --git a/collector-builder/exporter/beaconjsonexporter/config.go b/collector-builder/exporter/beaconjsonexporter/config.go
index a3858d04..9a827c89 100644
--- a/collector-builder/exporter/beaconjsonexporter/config.go
+++ b/collector-builder/exporter/beaconjsonexporter/config.go
@@ -15,6 +15,7 @@ type Config struct {
RedactSecrets bool `mapstructure:"redact_secrets"`
ContentRetention string `mapstructure:"content_retention"`
IncludeRuntimeMetrics bool `mapstructure:"include_runtime_metrics"`
+ IncludeCodexSpans bool `mapstructure:"include_codex_spans"`
}
func createDefaultConfig() *Config {
diff --git a/collector-builder/exporter/beaconjsonexporter/exporter.go b/collector-builder/exporter/beaconjsonexporter/exporter.go
index 4aa4d8f2..84cf7f17 100644
--- a/collector-builder/exporter/beaconjsonexporter/exporter.go
+++ b/collector-builder/exporter/beaconjsonexporter/exporter.go
@@ -2,6 +2,7 @@ package beaconjsonexporter
import (
"context"
+ "encoding/json"
"fmt"
"strings"
"time"
@@ -21,6 +22,25 @@ type beaconExporter struct {
logger *zap.Logger
}
+const (
+ codexConversationStarts = "codex.conversation_starts"
+ codexUserPrompt = "codex.user_prompt"
+ codexToolDecision = "codex.tool_decision"
+ codexToolResult = "codex.tool_result"
+)
+
+var allowedCodexLogEvents = map[string]struct{}{
+ codexConversationStarts: {},
+ codexUserPrompt: {},
+ codexToolDecision: {},
+ codexToolResult: {},
+}
+
+var noisyCodexLogMessages = []string{
+ "runtime metrics reset skipped",
+ "flushing otel metrics",
+}
+
func newExporter(raw component.Config, set exporter.Settings) (*beaconExporter, error) {
cfg, ok := raw.(*Config)
if !ok {
@@ -60,6 +80,9 @@ func (e *beaconExporter) consumeLogs(ctx context.Context, logs plog.Logs) error
scopeLogs := resourceLogs.ScopeLogs().At(j)
for k := 0; k < scopeLogs.LogRecords().Len(); k++ {
record := scopeLogs.LogRecords().At(k)
+ if shouldDropLog(resourceAttrs, record) {
+ continue
+ }
event := e.eventFromLog(resourceAttrs, record)
if err := e.writer.append(event); err != nil && firstErr == nil {
firstErr = err
@@ -80,7 +103,7 @@ func (e *beaconExporter) consumeTraces(ctx context.Context, traces ptrace.Traces
scopeSpans := resourceSpans.ScopeSpans().At(j)
for k := 0; k < scopeSpans.Spans().Len(); k++ {
span := scopeSpans.Spans().At(k)
- if shouldDropSpan(resourceAttrs, span) {
+ if e.shouldDropSpan(resourceAttrs, span) {
continue
}
event := e.eventFromSpan(resourceAttrs, span)
@@ -103,7 +126,7 @@ func (e *beaconExporter) consumeMetrics(ctx context.Context, metrics pmetric.Met
scopeMetrics := resourceMetrics.ScopeMetrics().At(j)
for k := 0; k < scopeMetrics.Metrics().Len(); k++ {
metric := scopeMetrics.Metrics().At(k)
- if !e.cfg.IncludeRuntimeMetrics && shouldDropRuntimeMetric(metric.Name()) {
+ if shouldDropMetric(resourceAttrs, metric.Name(), e.cfg.IncludeRuntimeMetrics) {
continue
}
event := e.eventFromMetric(resourceAttrs, metric)
@@ -116,6 +139,43 @@ func (e *beaconExporter) consumeMetrics(ctx context.Context, metrics pmetric.Met
return firstErr
}
+func shouldDropLog(resourceAttrs map[string]interface{}, record plog.LogRecord) bool {
+ attrs := mergeMaps(resourceAttrs, attrsToMap(record.Attributes()))
+ if harnessName(attrs, record.Body().AsString()) != "codex_cli" {
+ return false
+ }
+ return isNoisyCodexLog(attrs, record.Body().AsString())
+}
+
+func isNoisyCodexLog(attrs map[string]interface{}, body string) bool {
+ eventName := codexLogEventName(attrs)
+ if eventName == "" {
+ message := strings.ToLower(firstNonEmpty(body, firstString(attrs, "message", "log.message")))
+ for _, noisy := range noisyCodexLogMessages {
+ if strings.Contains(message, noisy) {
+ return true
+ }
+ }
+ return false
+ }
+ if _, ok := allowedCodexLogEvents[eventName]; ok {
+ return false
+ }
+ // Codex adds new observability events over time. Keep endpoint activity quiet
+ // unless a Codex log event is explicitly mapped into Beacon's stable schema.
+ return strings.HasPrefix(eventName, "codex.")
+}
+
+func shouldDropMetric(resourceAttrs map[string]interface{}, name string, includeRuntimeMetrics bool) bool {
+ if shouldDropCodexMetric(resourceAttrs, name) {
+ return true
+ }
+ if !includeRuntimeMetrics && shouldDropRuntimeMetric(name) {
+ return true
+ }
+ return false
+}
+
func shouldDropRuntimeMetric(name string) bool {
normalized := strings.ToLower(strings.TrimSpace(name))
if normalized == "" {
@@ -135,6 +195,14 @@ func shouldDropRuntimeMetric(name string) bool {
return false
}
+func shouldDropCodexMetric(resourceAttrs map[string]interface{}, name string) bool {
+ if harnessName(resourceAttrs, name) != "codex_cli" {
+ return false
+ }
+ normalized := strings.ToLower(strings.TrimSpace(name))
+ return strings.HasPrefix(normalized, "codex.")
+}
+
func (e *beaconExporter) eventFromLog(resourceAttrs map[string]interface{}, record plog.LogRecord) beaconEvent {
attrs := mergeMaps(resourceAttrs, attrsToMap(record.Attributes()))
ts := timestamp(record.Timestamp().AsTime())
@@ -150,6 +218,7 @@ func (e *beaconExporter) eventFromLog(resourceAttrs map[string]interface{}, reco
"otel_signal": "logs",
"severity": record.SeverityText(),
})
+ normalizeCodexLogEvent(&event, attrs)
return event
}
@@ -172,67 +241,94 @@ func (e *beaconExporter) eventFromSpan(resourceAttrs map[string]interface{}, spa
return event
}
-func shouldDropSpan(resourceAttrs map[string]interface{}, span ptrace.Span) bool {
+func (e *beaconExporter) shouldDropSpan(resourceAttrs map[string]interface{}, span ptrace.Span) bool {
attrs := mergeMaps(resourceAttrs, attrsToMap(span.Attributes()))
if harnessName(attrs, span.Name()) != "codex_cli" {
return false
}
- return isCodexInternalSpan(span.Name())
+ // Codex spans are high-volume internals that duplicate the semantic Codex log
+ // events Beacon uses for session, prompt, approval, and tool activity. Keep
+ // them disabled by default, but allow opt-in troubleshooting capture.
+ return !e.cfg.IncludeCodexSpans
}
-func isCodexInternalSpan(name string) bool {
- normalized := strings.ToLower(strings.TrimSpace(name))
- if normalized == "" {
- return true
- }
- keepPrefixes := []string{
- "codex.",
- "op.dispatch",
- "session_task.",
- "model_client.",
- "run_turn",
- "run_sampling_request",
- "try_run_sampling_request",
- "stream_request",
- "handle_responses",
- }
- for _, prefix := range keepPrefixes {
- if strings.HasPrefix(normalized, prefix) {
- return false
+func normalizeCodexLogEvent(event *beaconEvent, attrs map[string]interface{}) {
+ if event == nil || event.Harness.Name != "codex_cli" {
+ return
+ }
+ switch codexLogEventName(attrs) {
+ case codexConversationStarts:
+ event.Event.Action = "session.started"
+ event.Event.Category = "session"
+ event.Message = "Codex session started"
+ case codexUserPrompt:
+ event.Event.Action = "prompt.submitted"
+ event.Event.Category = "prompt"
+ if prompt := firstString(attrs, "prompt", "gen_ai.prompt", "user_prompt", "input.prompt"); prompt != "" {
+ event.Message = prompt
+ } else {
+ event.Message = "Codex prompt submitted"
}
+ case codexToolDecision:
+ decision := firstString(attrs, "decision")
+ if strings.EqualFold(decision, "denied") || strings.EqualFold(decision, "deny") {
+ event.Event.Action = "approval.denied"
+ } else {
+ event.Event.Action = "approval.requested"
+ }
+ event.Event.Category = "approval"
+ event.Message = "Codex tool decision"
+ if event.Approval == nil {
+ event.Approval = &approvalInfo{}
+ }
+ event.Approval.Required = true
+ event.Approval.Decision = decision
+ event.Approval.Reason = firstString(attrs, "source", "approval_mode", "active_approval_mode")
+ case codexToolResult:
+ normalizeCodexToolResult(event, attrs)
}
- dropExact := map[string]struct{}{
- "receiving": {},
- "receiving_stream": {},
- "poll": {},
- "poll_ready": {},
- "popped": {},
- "pop_frame": {},
- "reserve_capacity": {},
- "try_assign_capacity": {},
- "try_reclaim_frame": {},
- "assign_connection_capacity": {},
- "updating stream flow": {},
- "updating connection flow": {},
- "recv_stream_window_update": {},
- "recv_connection_window_update": {},
- "send_data": {},
- }
- if _, ok := dropExact[normalized]; ok {
- return true
- }
- dropPrefixes := []string{
- "framedread::",
- "framedwrite::",
- "hpack::",
- "prioritize::",
+}
+
+func codexLogEventName(attrs map[string]interface{}) string {
+ return strings.ToLower(firstString(attrs, "event.name"))
+}
+
+func normalizeCodexToolResult(event *beaconEvent, attrs map[string]interface{}) {
+ toolName := firstString(attrs, "tool.name", "tool_name", "function_name", "tool", "mcp_server")
+ args := firstString(attrs, "arguments", "function_args", "tool.command", "command")
+ event.Event.Action = "tool.invoked"
+ event.Event.Category = "tool"
+ if event.Tool == nil {
+ event.Tool = &toolInfo{}
+ }
+ event.Tool.Name = toolName
+ event.Tool.Command = args
+ if command := codexShellCommand(toolName, args); command != "" {
+ event.Event.Action = "command.executed"
+ event.Event.Category = "command"
+ event.Command = &commandInfo{Command: command}
}
- for _, prefix := range dropPrefixes {
- if strings.HasPrefix(normalized, prefix) {
- return true
+ event.Message = firstNonEmpty(toolName, "Codex tool result")
+}
+
+func codexShellCommand(toolName, args string) string {
+ if strings.EqualFold(toolName, "shell") {
+ if cmd := codexArgumentCommand(args); cmd != "" {
+ return cmd
}
+ return args
}
- return false
+ return codexArgumentCommand(args)
+}
+
+func codexArgumentCommand(args string) string {
+ var payload struct {
+ Cmd string `json:"cmd"`
+ }
+ if err := json.Unmarshal([]byte(args), &payload); err != nil {
+ return ""
+ }
+ return strings.TrimSpace(payload.Cmd)
}
func (e *beaconExporter) eventFromMetric(resourceAttrs map[string]interface{}, metric pmetric.Metric) beaconEvent {
diff --git a/collector-builder/exporter/beaconjsonexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
index 0b06cc66..72f67b15 100644
--- a/collector-builder/exporter/beaconjsonexporter/exporter_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
@@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"testing"
+ "time"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/plog"
@@ -283,7 +284,7 @@ func TestConsumeMetricsIncludesRuntimeMetricsWhenConfigured(t *testing.T) {
}
}
-func TestConsumeMetricsKeepsAgentMetricsByDefault(t *testing.T) {
+func TestConsumeMetricsDropsCodexMetricsByDefault(t *testing.T) {
path := filepath.Join(t.TempDir(), "runtime.jsonl")
exp, err := newExporter(&Config{
Path: path,
@@ -297,19 +298,27 @@ func TestConsumeMetricsKeepsAgentMetricsByDefault(t *testing.T) {
}
metrics := pmetric.NewMetrics()
- metric := metrics.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
- metric.SetName("codex.tool.call.duration_ms")
+ rm := metrics.ResourceMetrics().AppendEmpty()
+ rm.Resource().Attributes().PutStr("service.name", "codex-cli")
+ sm := rm.ScopeMetrics().AppendEmpty()
+ for _, name := range []string{
+ "codex.turn.memory",
+ "codex.turn.token_usage",
+ "codex.websocket.event.duration_ms",
+ "codex.remote_models.load_cache.duration_ms",
+ "codex.tool.call.duration_ms",
+ } {
+ sm.Metrics().AppendEmpty().SetName(name)
+ }
if err := exp.consumeMetrics(context.Background(), metrics); err != nil {
t.Fatalf("consumeMetrics returned error: %v", err)
}
- data, err := os.ReadFile(path)
- if err != nil {
+ if data, err := os.ReadFile(path); err == nil && len(strings.TrimSpace(string(data))) > 0 {
+ t.Fatalf("codex metrics should have been dropped, wrote: %s", string(data))
+ } else if err != nil && !os.IsNotExist(err) {
t.Fatalf("read runtime log: %v", err)
}
- if !strings.Contains(string(data), "codex.tool.call.duration_ms") {
- t.Fatalf("agent metric was not written: %s", string(data))
- }
}
func TestInferActionMapsCodexUserInputToPrompt(t *testing.T) {
@@ -329,7 +338,7 @@ func TestInferActionMapsCodexOpAttributeToPrompt(t *testing.T) {
}
}
-func TestEventFromSpanMapsCodexUserInputToPrompt(t *testing.T) {
+func TestConsumeTracesDropsCodexUserInputSpan(t *testing.T) {
path := filepath.Join(t.TempDir(), "runtime.jsonl")
exp, err := newExporter(&Config{
Path: path,
@@ -350,6 +359,38 @@ func TestEventFromSpanMapsCodexUserInputToPrompt(t *testing.T) {
rs.Resource().Attributes().PutStr("service.name", "codex-cli")
span.CopyTo(rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty())
+ if err := exp.consumeTraces(context.Background(), traces); err != nil {
+ t.Fatalf("consumeTraces returned error: %v", err)
+ }
+ if data, err := os.ReadFile(path); err == nil && len(strings.TrimSpace(string(data))) > 0 {
+ t.Fatalf("Codex user input span should have been dropped, wrote: %s", string(data))
+ } else if err != nil && !os.IsNotExist(err) {
+ t.Fatalf("read runtime log: %v", err)
+ }
+}
+
+func TestConsumeTracesIncludesCodexSpansWhenConfigured(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ exp, err := newExporter(&Config{
+ Path: path,
+ MaxEventBytes: defaultMaxEventBytes,
+ RotateBytes: defaultRotateBytes,
+ RedactSecrets: true,
+ ContentRetention: "full",
+ IncludeCodexSpans: true,
+ }, exporter.Settings{})
+ if err != nil {
+ t.Fatalf("newExporter returned error: %v", err)
+ }
+
+ span := testSpan("op.dispatch.user_input_with_turn_context")
+ span.Attributes().PutStr("prompt", "summarize token=codex-secret")
+
+ traces := ptrace.NewTraces()
+ rs := traces.ResourceSpans().AppendEmpty()
+ rs.Resource().Attributes().PutStr("service.name", "codex-cli")
+ span.CopyTo(rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty())
+
if err := exp.consumeTraces(context.Background(), traces); err != nil {
t.Fatalf("consumeTraces returned error: %v", err)
}
@@ -364,14 +405,112 @@ func TestEventFromSpanMapsCodexUserInputToPrompt(t *testing.T) {
if event.Event.Action != "prompt.submitted" {
t.Fatalf("span action = %q, want prompt.submitted", event.Event.Action)
}
- if event.Event.Category != "prompt" {
- t.Fatalf("span category = %q, want prompt", event.Event.Category)
+ if event.Raw["otel_signal"] != "traces" || event.Raw["span_name"] != "op.dispatch.user_input_with_turn_context" {
+ t.Fatalf("trace raw payload missing: %#v", event.Raw)
}
- if event.Harness.Name != "codex_cli" {
- t.Fatalf("harness = %q, want codex_cli", event.Harness.Name)
+}
+
+func TestConsumeLogsMapsCodexSemanticEventsAndDropsTransportNoise(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ exp, err := newExporter(&Config{
+ Path: path,
+ MaxEventBytes: defaultMaxEventBytes,
+ RotateBytes: defaultRotateBytes,
+ RedactSecrets: true,
+ ContentRetention: "full",
+ }, exporter.Settings{})
+ if err != nil {
+ t.Fatalf("newExporter returned error: %v", err)
}
- if event.Prompt == nil || event.Prompt.Text != "summarize token=[REDACTED]" {
- t.Fatalf("prompt = %#v, want redacted Codex prompt", event.Prompt)
+
+ logs := plog.NewLogs()
+ rl := logs.ResourceLogs().AppendEmpty()
+ rl.Resource().Attributes().PutStr("service.name", "codex_cli_rs")
+ sl := rl.ScopeLogs().AppendEmpty()
+ for _, eventName := range []string{
+ "codex.conversation_starts",
+ "codex.user_prompt",
+ "codex.tool_decision",
+ "codex.tool_result",
+ "codex.startup_phase",
+ "codex.turn_ttft",
+ "codex.websocket_event",
+ "codex.sse_event",
+ } {
+ rec := sl.LogRecords().AppendEmpty()
+ rec.Attributes().PutStr("event.name", eventName)
+ rec.Attributes().PutStr("conversation.id", "codex-session")
+ rec.Attributes().PutStr("model", "gpt-5.5")
+ switch eventName {
+ case "codex.user_prompt":
+ rec.Body().SetStr("op.dispatch.user_input_with_turn_context")
+ rec.Attributes().PutStr("prompt", "look up weather token=codex-secret")
+ case "codex.tool_decision":
+ rec.Attributes().PutStr("decision", "approved")
+ rec.Attributes().PutStr("source", "Config")
+ case "codex.tool_result":
+ rec.Attributes().PutStr("tool", "shell")
+ rec.Attributes().PutStr("arguments", `{"cmd":"date"}`)
+ }
+ }
+ debug := sl.LogRecords().AppendEmpty()
+ debug.Body().SetStr("runtime metrics reset skipped: runtime metrics snapshot reader is not enabled")
+ flush := sl.LogRecords().AppendEmpty()
+ flush.Body().SetStr("flushing OTEL metrics")
+
+ 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.Fatalf("read runtime log: %v", err)
+ }
+ text := string(data)
+ for _, noisy := range []string{"codex.startup_phase", "codex.turn_ttft", "codex.websocket_event", "codex.sse_event", "runtime metrics reset skipped", "flushing OTEL metrics"} {
+ if strings.Contains(text, noisy) {
+ t.Fatalf("noisy Codex event %q was written: %s", noisy, text)
+ }
+ }
+
+ var actions []string
+ for _, line := range strings.Split(strings.TrimSpace(text), "\n") {
+ var event beaconEvent
+ if err := json.Unmarshal([]byte(line), &event); err != nil {
+ t.Fatalf("unmarshal event: %v", err)
+ }
+ actions = append(actions, event.Event.Action)
+ if event.Event.Action == "prompt.submitted" {
+ if event.Prompt == nil || event.Prompt.Text != "look up weather token=[REDACTED]" {
+ t.Fatalf("prompt = %#v, want redacted typed prompt", event.Prompt)
+ }
+ if event.Message != "look up weather token=[REDACTED]" {
+ t.Fatalf("prompt message = %q, want prompt text", event.Message)
+ }
+ }
+ }
+ wantActions := []string{"session.started", "prompt.submitted", "approval.requested", "command.executed"}
+ for _, want := range wantActions {
+ if !containsString(actions, want) {
+ t.Fatalf("actions = %#v, want %q", actions, want)
+ }
+ }
+}
+
+func TestCodexToolResultExtractsShellCommand(t *testing.T) {
+ event := newBeaconEvent("tool.invoked", "tool", "info", "codex_cli", time.Now())
+ normalizeCodexToolResult(&event, map[string]interface{}{
+ "tool": "shell",
+ "arguments": `{"cmd":"date","workdir":"/tmp"}`,
+ })
+
+ if event.Event.Action != "command.executed" || event.Event.Category != "command" {
+ t.Fatalf("unexpected action/category: %#v", event.Event)
+ }
+ if event.Command == nil || event.Command.Command != "date" {
+ t.Fatalf("command = %#v, want parsed date command", event.Command)
+ }
+ if event.Tool == nil || event.Tool.Command != `{"cmd":"date","workdir":"/tmp"}` {
+ t.Fatalf("tool payload not preserved: %#v", event.Tool)
}
}
@@ -531,16 +670,24 @@ func TestMetadataRetentionDropsRawAttributes(t *testing.T) {
func TestCodexInternalSpanFilter(t *testing.T) {
codexAttrs := map[string]interface{}{"service.name": "codex-cli"}
+ exp := &beaconExporter{cfg: &Config{}}
- if !shouldDropSpan(codexAttrs, testSpan("FramedRead::poll_next")) {
+ if !exp.shouldDropSpan(codexAttrs, testSpan("FramedRead::poll_next")) {
t.Fatal("expected Codex transport span to be dropped")
}
- if shouldDropSpan(codexAttrs, testSpan("session_task.turn")) {
- t.Fatal("expected meaningful Codex session span to be kept")
+ if !exp.shouldDropSpan(codexAttrs, testSpan("session_task.turn")) {
+ t.Fatal("expected Codex session_task span to be dropped")
+ }
+ if !exp.shouldDropSpan(codexAttrs, testSpan("op.dispatch.user_input_with_turn_context")) {
+ t.Fatal("expected Codex user input span to be dropped")
}
- if shouldDropSpan(map[string]interface{}{"service.name": "other-agent"}, testSpan("FramedRead::poll_next")) {
+ if exp.shouldDropSpan(map[string]interface{}{"service.name": "other-agent"}, testSpan("FramedRead::poll_next")) {
t.Fatal("expected non-Codex span to be kept")
}
+ debugExp := &beaconExporter{cfg: &Config{IncludeCodexSpans: true}}
+ if debugExp.shouldDropSpan(codexAttrs, testSpan("session_task.turn")) {
+ t.Fatal("expected Codex span to be kept when configured")
+ }
}
func TestConsumeTracesDropsCodexInternalSpans(t *testing.T) {
@@ -562,21 +709,18 @@ func TestConsumeTracesDropsCodexInternalSpans(t *testing.T) {
spans := rs.ScopeSpans().AppendEmpty().Spans()
spans.AppendEmpty().SetName("FramedRead::poll_next")
spans.AppendEmpty().SetName("session_task.turn")
+ spans.AppendEmpty().SetName("run_sampling_request")
+ spans.AppendEmpty().SetName("handle_responses")
+ spans.AppendEmpty().SetName("op.dispatch.user_input_with_turn_context")
if err := exp.consumeTraces(context.Background(), traces); err != nil {
t.Fatalf("consumeTraces returned error: %v", err)
}
- data, err := os.ReadFile(path)
- if err != nil {
+ if data, err := os.ReadFile(path); err == nil && len(strings.TrimSpace(string(data))) > 0 {
+ t.Fatalf("Codex spans should have been dropped, wrote: %s", string(data))
+ } else if err != nil && !os.IsNotExist(err) {
t.Fatalf("read runtime log: %v", err)
}
- text := string(data)
- if strings.Contains(text, "FramedRead::poll_next") {
- t.Fatalf("transport span was written: %s", text)
- }
- if !strings.Contains(text, "session_task.turn") {
- t.Fatalf("meaningful span was not written: %s", text)
- }
}
func testSpan(name string) ptrace.Span {
@@ -625,3 +769,12 @@ func TestHarnessNameSeparatesClaudeCodeAndCowork(t *testing.T) {
})
}
}
+
+func containsString(values []string, want string) bool {
+ for _, value := range values {
+ if value == want {
+ return true
+ }
+ }
+ return false
+}