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
fix endpoint telemetry signal quality
shukieshah5564c805f331
diff --git a/cli/beacon/cmd/endpoint.go b/cli/beacon/cmd/endpoint.goindex 023d7855..9e3e632d 100644--- a/cli/beacon/cmd/endpoint.go+++ b/cli/beacon/cmd/endpoint.go@@ -31,6 +31,7 @@ var endpointOpts struct {grpcPort inthttpPort intcollectorPath string+ includeRuntimeMetrics boolkeepLogs boolkeepConfig boolnoStart bool@@ -263,6 +264,7 @@ func init() {endpointInstallCmd.Flags().IntVar(&endpointOpts.grpcPort, "otlp-grpc-port", endpointconfig.DefaultGRPCPort, "Local OTLP gRPC port")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.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)@@ -270,6 +272,7 @@ func init() {endpointRepairCmd.Flags().IntVar(&endpointOpts.grpcPort, "otlp-grpc-port", endpointconfig.DefaultGRPCPort, "Local OTLP gRPC port")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.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)@@ -426,15 +429,16 @@ func runEndpointDashboard(cmd *cobra.Command, args []string) error {func runEndpointInstall(cmd *cobra.Command, args []string) error {result, err := lifecycle.Install(lifecycle.InstallOptions{- UserMode: endpointUserMode(),- LogPath: endpointOpts.logPath,- Harnesses: splitCSV(endpointOpts.harnesses),- GRPCPort: endpointOpts.grpcPort,- HTTPPort: endpointOpts.httpPort,- CollectorPath: endpointOpts.collectorPath,- StartService: !endpointOpts.noStart,- ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),- SplunkHEC: splunkHECOptions(),+ UserMode: endpointUserMode(),+ LogPath: endpointOpts.logPath,+ Harnesses: splitCSV(endpointOpts.harnesses),+ GRPCPort: endpointOpts.grpcPort,+ HTTPPort: endpointOpts.httpPort,+ CollectorPath: endpointOpts.collectorPath,+ StartService: !endpointOpts.noStart,+ ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),+ IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,+ SplunkHEC: splunkHECOptions(),})if err != nil {return err@@ -547,15 +551,16 @@ func runEndpointUninstall(cmd *cobra.Command, args []string) error {func runEndpointRepair(cmd *cobra.Command, args []string) error {result, err := lifecycle.Repair(lifecycle.InstallOptions{- UserMode: endpointUserMode(),- LogPath: endpointOpts.logPath,- Harnesses: splitCSV(endpointOpts.harnesses),- GRPCPort: endpointOpts.grpcPort,- HTTPPort: endpointOpts.httpPort,- CollectorPath: endpointOpts.collectorPath,- StartService: !endpointOpts.noStart,- ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),- SplunkHEC: splunkHECOptions(),+ UserMode: endpointUserMode(),+ LogPath: endpointOpts.logPath,+ Harnesses: splitCSV(endpointOpts.harnesses),+ GRPCPort: endpointOpts.grpcPort,+ HTTPPort: endpointOpts.httpPort,+ CollectorPath: endpointOpts.collectorPath,+ StartService: !endpointOpts.noStart,+ ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),+ IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,+ SplunkHEC: splunkHECOptions(),})if err != nil {return errdiff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.goindex db5a6bea..98ac217a 100644--- a/cli/beacon/cmd/endpoint_test.go+++ b/cli/beacon/cmd/endpoint_test.go@@ -116,6 +116,14 @@ func TestEndpointInstallAndRepairSupportSplunkFlags(t *testing.T) {}}+func TestEndpointInstallAndRepairSupportRuntimeMetricsFlag(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)+ }+ }+}+func TestEndpointCommandsDefaultToUserMode(t *testing.T) {for _, cmd := range []*cobra.Command{endpointInstallCmd, endpointStatusCmd, endpointDashboardCmd, endpointHooksInstallCmd} {userFlag := cmd.Flags().Lookup("user")diff --git a/cli/beacon/internal/endpoint/collector/collector.go b/cli/beacon/internal/endpoint/collector/collector.goindex 9b195af5..598ea5f7 100644--- a/cli/beacon/internal/endpoint/collector/collector.go+++ b/cli/beacon/internal/endpoint/collector/collector.go@@ -138,6 +138,7 @@ exporters:rotate_bytes: 10485760redact_secrets: truecontent_retention: %q+ include_runtime_metrics: %t%sextensions:health_check:@@ -161,7 +162,7 @@ service:receivers: [otlp]processors: [memory_limiter, batch]exporters: %s-`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, splunkExporter, exporters, exporters, exporters)+`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, cfg.Collector.IncludeRuntimeMetrics, 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.goindex 5c13dde1..4216930a 100644--- a/cli/beacon/internal/endpoint/collector/collector_test.go+++ b/cli/beacon/internal/endpoint/collector/collector_test.go@@ -41,6 +41,7 @@ func TestConfigYAMLIncludesReleaseContractFields(t *testing.T) {"max_event_bytes: 65536","rotate_bytes: 10485760","redact_secrets: true",+ "include_runtime_metrics: false","level: none","receivers: [otlp]","exporters: [beaconjson]",@@ -51,6 +52,16 @@ func TestConfigYAMLIncludesReleaseContractFields(t *testing.T) {}}+func TestConfigYAMLIncludesRuntimeMetricsOptIn(t *testing.T) {+ cfg := testConfig(t)+ cfg.Collector.IncludeRuntimeMetrics = true++ yaml := ConfigYAML(cfg)+ if !strings.Contains(yaml, "include_runtime_metrics: true") {+ t.Fatalf("ConfigYAML missing runtime metrics 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.goindex 95135f81..2f987fb0 100644--- a/cli/beacon/internal/endpoint/config/config.go+++ b/cli/beacon/internal/endpoint/config/config.go@@ -38,11 +38,12 @@ type Config struct {}type Collector struct {- BinaryPath string `json:"binary_path,omitempty"`- ConfigPath string `json:"config_path,omitempty"`- GRPCPort int `json:"grpc_port"`- HTTPPort int `json:"http_port"`- SpoolPath string `json:"spool_path,omitempty"`+ BinaryPath string `json:"binary_path,omitempty"`+ ConfigPath string `json:"config_path,omitempty"`+ GRPCPort int `json:"grpc_port"`+ HTTPPort int `json:"http_port"`+ SpoolPath string `json:"spool_path,omitempty"`+ IncludeRuntimeMetrics bool `json:"include_runtime_metrics,omitempty"`}type Destinations struct {diff --git a/cli/beacon/internal/endpoint/config/config_test.go b/cli/beacon/internal/endpoint/config/config_test.goindex 9977cab1..05acc4ee 100644--- a/cli/beacon/internal/endpoint/config/config_test.go+++ b/cli/beacon/internal/endpoint/config/config_test.go@@ -39,6 +39,7 @@ func TestSaveLoadRoundTrip(t *testing.T) {cfg := Default(true, logPath)cfg.Collector.BinaryPath = filepath.Join(home, "bin", "otelcol")+ cfg.Collector.IncludeRuntimeMetrics = truecfg.EventCategories = []string{"tool", "session"}cfg.ContentRetention = ContentRetentionRedacted@@ -60,6 +61,9 @@ func TestSaveLoadRoundTrip(t *testing.T) {if loaded.Collector.BinaryPath != cfg.Collector.BinaryPath {t.Fatalf("BinaryPath = %q, want %q", loaded.Collector.BinaryPath, cfg.Collector.BinaryPath)}+ if !loaded.Collector.IncludeRuntimeMetrics {+ t.Fatal("IncludeRuntimeMetrics = 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/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.goindex 12239c1f..6e9f9051 100644--- a/cli/beacon/internal/endpoint/harness/harness.go+++ b/cli/beacon/internal/endpoint/harness/harness.go@@ -167,6 +167,11 @@ func ConfigureClaude(opts ConfigureOptions) (string, error) {env["OTEL_METRICS_EXPORTER"] = "otlp"env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc"env["OTEL_EXPORTER_OTLP_ENDPOINT"] = opts.Endpoint+ if opts.ContentRetention == "metadata" {+ delete(env, "OTEL_LOG_USER_PROMPTS")+ } else {+ env["OTEL_LOG_USER_PROMPTS"] = "1"+ }settings["env"] = envif err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {return "", errdiff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.goindex f0126f13..2fca39e4 100644--- a/cli/beacon/internal/endpoint/harness/harness_test.go+++ b/cli/beacon/internal/endpoint/harness/harness_test.go@@ -68,6 +68,7 @@ func TestConfigureClaudeWritesTelemetryEnvAndBackup(t *testing.T) {"OTEL_METRICS_EXPORTER": "otlp","OTEL_EXPORTER_OTLP_PROTOCOL": "grpc","OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:4317",+ "OTEL_LOG_USER_PROMPTS": "1",} {if got := env[key]; got != want {t.Fatalf("env[%s] = %q, want %q; env=%#v", key, got, want, env)@@ -82,6 +83,41 @@ func TestConfigureClaudeWritesTelemetryEnvAndBackup(t *testing.T) {}}+func TestConfigureClaudeDisablesPromptLoggingForMetadataRetention(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ path := filepath.Join(home, ".claude", "settings.json")+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ t.Fatalf("mkdir claude config dir: %v", err)+ }+ if err := os.WriteFile(path, []byte(`{"env":{"OTEL_LOG_USER_PROMPTS":"1"}}`), 0600); err != nil {+ t.Fatalf("write existing claude config: %v", err)+ }++ written, err := ConfigureClaude(ConfigureOptions{+ Endpoint: "http://127.0.0.1:4317",+ UserMode: true,+ ContentRetention: "metadata",+ })+ if err != nil {+ t.Fatalf("ConfigureClaude returned error: %v", err)+ }+ if written != path {+ t.Fatalf("ConfigureClaude path = %q, want %q", written, path)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatalf("read claude config: %v", err)+ }+ var settings map[string]map[string]string+ if err := json.Unmarshal(data, &settings); err != nil {+ t.Fatalf("unmarshal claude config: %v", err)+ }+ if _, ok := settings["env"]["OTEL_LOG_USER_PROMPTS"]; ok {+ t.Fatalf("metadata retention should remove OTEL_LOG_USER_PROMPTS: %#v", settings["env"])+ }+}+func TestClaudeStatusVariants(t *testing.T) {dir := t.TempDir()tests := []struct {diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.goindex 73f7765f..608efd4b 100644--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go@@ -19,15 +19,16 @@ import ()type InstallOptions struct {- UserMode bool- LogPath string- Harnesses []string- GRPCPort int- HTTPPort int- CollectorPath string- StartService bool- ContentRetention endpointconfig.ContentRetention- SplunkHEC *endpointconfig.SplunkHEC+ UserMode bool+ LogPath string+ Harnesses []string+ GRPCPort int+ HTTPPort int+ CollectorPath string+ StartService bool+ ContentRetention endpointconfig.ContentRetention+ IncludeRuntimeMetrics bool+ SplunkHEC *endpointconfig.SplunkHEC}type UninstallOptions struct {@@ -279,6 +280,7 @@ func buildConfig(opts InstallOptions) endpointconfig.Config {cfg.Collector.HTTPPort = opts.HTTPPort}cfg.Collector.BinaryPath = opts.CollectorPath+ cfg.Collector.IncludeRuntimeMetrics = opts.IncludeRuntimeMetricsif opts.ContentRetention != "" {cfg.ContentRetention = opts.ContentRetention}@@ -358,7 +360,7 @@ func configureHarnesses(cfg endpointconfig.Config) ([]string, error) {for _, name := range cfg.Harnesses {switch name {case "claude", "claude_code":- path, err := harness.ConfigureClaude(harness.ConfigureOptions{Endpoint: endpoint, UserMode: cfg.UserMode})+ path, err := harness.ConfigureClaude(harness.ConfigureOptions{Endpoint: endpoint, UserMode: cfg.UserMode, ContentRetention: string(cfg.ContentRetention)})if err != nil {return paths, err}diff --git a/collector-builder/exporter/beaconjsonexporter/config.go b/collector-builder/exporter/beaconjsonexporter/config.goindex 8b03b61f..a3858d04 100644--- a/collector-builder/exporter/beaconjsonexporter/config.go+++ b/collector-builder/exporter/beaconjsonexporter/config.go@@ -9,11 +9,12 @@ const (// Config controls local JSONL export for Beacon endpoint events.type Config struct {- Path string `mapstructure:"path"`- MaxEventBytes int `mapstructure:"max_event_bytes"`- RotateBytes int64 `mapstructure:"rotate_bytes"`- RedactSecrets bool `mapstructure:"redact_secrets"`- ContentRetention string `mapstructure:"content_retention"`+ Path string `mapstructure:"path"`+ MaxEventBytes int `mapstructure:"max_event_bytes"`+ RotateBytes int64 `mapstructure:"rotate_bytes"`+ RedactSecrets bool `mapstructure:"redact_secrets"`+ ContentRetention string `mapstructure:"content_retention"`+ IncludeRuntimeMetrics bool `mapstructure:"include_runtime_metrics"`}func createDefaultConfig() *Config {diff --git a/collector-builder/exporter/beaconjsonexporter/exporter.go b/collector-builder/exporter/beaconjsonexporter/exporter.goindex a7f03403..85b3be25 100644--- a/collector-builder/exporter/beaconjsonexporter/exporter.go+++ b/collector-builder/exporter/beaconjsonexporter/exporter.go@@ -103,6 +103,9 @@ func (e *beaconExporter) consumeMetrics(ctx context.Context, metrics pmetric.MetscopeMetrics := resourceMetrics.ScopeMetrics().At(j)for k := 0; k < scopeMetrics.Metrics().Len(); k++ {metric := scopeMetrics.Metrics().At(k)+ if !e.cfg.IncludeRuntimeMetrics && shouldDropRuntimeMetric(metric.Name()) {+ continue+ }event := e.eventFromMetric(resourceAttrs, metric)if err := e.writer.append(event); err != nil && firstErr == nil {firstErr = err@@ -113,6 +116,25 @@ func (e *beaconExporter) consumeMetrics(ctx context.Context, metrics pmetric.Metreturn firstErr}+func shouldDropRuntimeMetric(name string) bool {+ normalized := strings.ToLower(strings.TrimSpace(name))+ if normalized == "" {+ return false+ }+ dropPrefixes := []string{+ "process.",+ "nodejs.",+ "runtime.nodejs.",+ "v8js.",+ }+ for _, prefix := range dropPrefixes {+ if strings.HasPrefix(normalized, prefix) {+ return true+ }+ }+ return false+}+func (e *beaconExporter) eventFromLog(resourceAttrs map[string]interface{}, record plog.LogRecord) beaconEvent {attrs := mergeMaps(resourceAttrs, attrsToMap(record.Attributes()))ts := timestamp(record.Timestamp().AsTime())diff --git a/collector-builder/exporter/beaconjsonexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/exporter_test.goindex 30b7a91d..ed731111 100644--- a/collector-builder/exporter/beaconjsonexporter/exporter_test.go+++ b/collector-builder/exporter/beaconjsonexporter/exporter_test.go@@ -216,6 +216,102 @@ func TestEventFromMetricDefaultsToObservedAction(t *testing.T) {}}+func TestConsumeMetricsDropsRuntimeMetricsByDefault(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)+ }++ metrics := pmetric.NewMetrics()+ rm := metrics.ResourceMetrics().AppendEmpty()+ rm.Resource().Attributes().PutStr("service.name", "unknown_service:node")+ rm.Resource().Attributes().PutStr("process.command", "/tmp/mcp-server-elasticsearch")+ sm := rm.ScopeMetrics().AppendEmpty()+ for _, name := range []string{+ "process.cpu.utilization",+ "process.memory.usage",+ "nodejs.eventloop.utilization",+ "v8js.memory.heap.used",+ } {+ sm.Metrics().AppendEmpty().SetName(name)+ }++ if err := exp.consumeMetrics(context.Background(), metrics); err != nil {+ t.Fatalf("consumeMetrics returned error: %v", err)+ }+ if data, err := os.ReadFile(path); err == nil && len(strings.TrimSpace(string(data))) > 0 {+ t.Fatalf("runtime metrics should have been dropped, wrote: %s", string(data))+ } else if err != nil && !os.IsNotExist(err) {+ t.Fatalf("read runtime log: %v", err)+ }+}++func TestConsumeMetricsIncludesRuntimeMetricsWhenConfigured(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ exp, err := newExporter(&Config{+ Path: path,+ MaxEventBytes: defaultMaxEventBytes,+ RotateBytes: defaultRotateBytes,+ RedactSecrets: true,+ ContentRetention: "full",+ IncludeRuntimeMetrics: true,+ }, exporter.Settings{})+ if err != nil {+ t.Fatalf("newExporter returned error: %v", err)+ }++ metrics := pmetric.NewMetrics()+ metric := metrics.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()+ metric.SetName("nodejs.eventloop.utilization")++ if err := exp.consumeMetrics(context.Background(), metrics); err != nil {+ t.Fatalf("consumeMetrics returned error: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatalf("read runtime log: %v", err)+ }+ if !strings.Contains(string(data), "nodejs.eventloop.utilization") {+ t.Fatalf("runtime metric was not written: %s", string(data))+ }+}++func TestConsumeMetricsKeepsAgentMetricsByDefault(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ exp, err := newExporter(&Config{+ Path: path,+ MaxEventBytes: defaultMaxEventBytes,+ RotateBytes: defaultRotateBytes,+ RedactSecrets: true,+ ContentRetention: "metadata",+ }, exporter.Settings{})+ if err != nil {+ t.Fatalf("newExporter returned error: %v", err)+ }++ metrics := pmetric.NewMetrics()+ metric := metrics.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()+ metric.SetName("codex.tool.call.duration_ms")++ if err := exp.consumeMetrics(context.Background(), metrics); err != nil {+ t.Fatalf("consumeMetrics returned error: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ 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) {attrs := map[string]interface{}{"service.name": "codex_cli_rs"}if got := inferAction(attrs, "op.dispatch.user_input_with_turn_context"); got != "prompt.submitted" {