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(ci): override inherited per-signal OTLP routing (#1128)
Rudy Mizrahi Celeklif26a931578ad
diff --git a/cli/beacon/internal/ci/harness.go b/cli/beacon/internal/ci/harness.goindex 476113ad..8cffb078 100644--- a/cli/beacon/internal/ci/harness.go+++ b/cli/beacon/internal/ci/harness.go@@ -7,6 +7,7 @@ import ("path/filepath""strings"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudeotel""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema")@@ -25,28 +26,12 @@ type HarnessConfig struct {Paths map[string]string `json:"paths,omitempty"`}-func ClaudeEnv(base []string, endpoint string) []string {- env := envMap(base)- return flattenEnv(claudeEnv(env, env, endpoint))-}--// claudeEnv sets Claude Code's telemetry variables in env. caller is the environment the session-// runs under, which is where a deliberately tuned export timing is read from; it is env itself-// unless env holds only what is being added to that environment.+// claudeEnv adds Claude Code's telemetry variables to env, the overlay laid over caller, which is+// the environment the session runs under and where a deliberately tuned export timing is read from.func claudeEnv(env, caller map[string]string, endpoint string) map[string]string {- env["CLAUDE_CODE_ENABLE_TELEMETRY"] = "1"- env["OTEL_LOGS_EXPORTER"] = "otlp"- env["OTEL_METRICS_EXPORTER"] = "otlp"- // Delta temporality keeps token usage counters per-interval so downstream- // aggregation can sum datapoints without deduping cumulative series.- env["OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"] = "delta"- env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc"- env["OTEL_EXPORTER_OTLP_ENDPOINT"] = endpoint- delete(env, "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT")- delete(env, "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT")- delete(env, "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT")- env["OTEL_LOG_TOOL_DETAILS"] = "1"- env["OTEL_LOG_USER_PROMPTS"] = "1"+ for key, value := range claudeotel.OTLPEnv(endpoint, caller) {+ env[key] = value+ }for key, value := range claudeEnvDefaults {if strings.TrimSpace(caller[key]) != "" {value = caller[key]@@ -227,16 +212,6 @@ func percentEncodeResourceValue(value string) string {return strings.ReplaceAll(url.QueryEscape(value), "+", "%20")}-// inlineRawBodies reports whether an OTEL_LOG_RAW_API_BODIES value has Claude Code put API bodies-// inline in its log events, rather than leave them off or write them to files Beacon never reads.-func inlineRawBodies(value string) bool {- switch strings.ToLower(strings.TrimSpace(value)) {- case "1", "true":- return true- }- return false-}-func envMap(values []string) map[string]string {out := map[string]string{}for _, value := range values {diff --git a/cli/beacon/internal/ci/harness_test.go b/cli/beacon/internal/ci/harness_test.goindex 33a4d6b5..57979898 100644--- a/cli/beacon/internal/ci/harness_test.go+++ b/cli/beacon/internal/ci/harness_test.go@@ -8,22 +8,32 @@ import ()func TestClaudeEnvIncludesDetailedToolAndPromptLogging(t *testing.T) {- env := strings.Join(ClaudeEnv([]string{"PATH=/bin", "OTEL_LOG_TOOL_DETAILS=0", "OTEL_LOG_USER_PROMPTS=0"}, "http://127.0.0.1:4317"), "\n")- for _, want := range []string{- "CLAUDE_CODE_ENABLE_TELEMETRY=1",- "OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317",- "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta",- "OTEL_LOG_TOOL_DETAILS=1",- "OTEL_LOG_USER_PROMPTS=1",+ env := claudeConfigEnv(t, []string{"PATH=/bin", "OTEL_LOG_TOOL_DETAILS=0", "OTEL_LOG_USER_PROMPTS=0"})+ for key, want := range map[string]string{+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",+ "OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:4317",+ "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "delta",+ "OTEL_LOG_TOOL_DETAILS": "1",+ "OTEL_LOG_USER_PROMPTS": "1",} {- if !strings.Contains(env, want) {- t.Fatalf("ClaudeEnv missing %q in:\n%s", want, env)+ if env[key] != want {+ t.Fatalf("%s = %q, want %q in %v", key, env[key], want, env)}}}+// claudeConfigEnv is what ci exec lays over base for a Claude session.+func claudeConfigEnv(t *testing.T, base []string) map[string]string {+ t.Helper()+ cfg, err := BuildHarnessConfig(base, "claude", "http://127.0.0.1:4317", t.TempDir(), nil)+ if err != nil {+ t.Fatal(err)+ }+ return cfg.Env+}+// ci exec builds the child's env through BuildHarnessConfig and lays it over the caller's own, so a-// value the caller set survives only if BuildHarnessConfig hands it to ClaudeEnv.+// value the caller set survives only if BuildHarnessConfig decides the overlay against that environment.func TestBuildHarnessConfigKeepsTheCallersClaudeDefaults(t *testing.T) {base := []string{"OTEL_METRIC_EXPORT_INTERVAL=30000", "OTEL_LOG_RAW_API_BODIES=1", "SECRET_TOKEN=not-copied"}cfg, err := BuildHarnessConfig(base, "claude", "http://127.0.0.1:4317", t.TempDir(), nil)@@ -91,7 +101,7 @@ func TestNormalizeHarnessesSupportsClaudeAndCodexAliases(t *testing.T) {// five or ten, so without these nothing is exported on a timer and every event rides on the flush at// shutdown -- a race that three dispatched runs of the same commit lost twice.func TestClaudeEnvExportsOnATimerShorterThanASession(t *testing.T) {- env := envMap(ClaudeEnv(nil, "http://127.0.0.1:4317"))+ env := claudeConfigEnv(t, nil)for key, want := range map[string]string{"OTEL_METRIC_EXPORT_INTERVAL": "5000",@@ -114,7 +124,7 @@ func TestClaudeEnvDoesNotOverrideDeliberateExportTuning(t *testing.T) {"OTEL_METRIC_EXPORT_INTERVAL": "30000","OTEL_BSP_SCHEDULE_DELAY": "250",})- env := envMap(ClaudeEnv(base, "http://127.0.0.1:4317"))+ env := claudeConfigEnv(t, base)if env["OTEL_METRIC_EXPORT_INTERVAL"] != "30000" {t.Fatalf("OTEL_METRIC_EXPORT_INTERVAL = %q, want the caller's 30000", env["OTEL_METRIC_EXPORT_INTERVAL"])diff --git a/cli/beacon/internal/ci/session.go b/cli/beacon/internal/ci/session.goindex a0bf1a46..d24d01ed 100644--- a/cli/beacon/internal/ci/session.go+++ b/cli/beacon/internal/ci/session.go@@ -14,6 +14,7 @@ import ("syscall""time"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudeotel"endpointcollector "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/collector"endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"@@ -139,7 +140,7 @@ func Provision(opts Options) (*Session, error) {// A CI job opts in to model-context capture by setting OTEL_LOG_RAW_API_BODIES itself, and the// collector is this job's alone, so it keeps what the job asked Claude Code to send. Without// this the collector would drop every body the job turned on.- cfg.ClaudeCaptureModelContext = inlineRawBodies(os.Getenv("OTEL_LOG_RAW_API_BODIES"))+ cfg.ClaudeCaptureModelContext = claudeotel.InlineRawBodies(os.Getenv("OTEL_LOG_RAW_API_BODIES"))forward, err := normalizeForward(opts.Forward)if err != nil {return nil, errdiff --git a/cli/beacon/internal/ci/signal_routing_test.go b/cli/beacon/internal/ci/signal_routing_test.gonew file mode 100644index 00000000..854d1399--- /dev/null+++ b/cli/beacon/internal/ci/signal_routing_test.go@@ -0,0 +1,111 @@+package ci++import (+ "context"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+)++var signalRoutingKeys = []string{+ "OTEL_EXPORTER_OTLP_HEADERS",+ "BETA_TRACING_ENDPOINT",+ "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", "OTEL_EXPORTER_OTLP_LOGS_HEADERS",+ "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", "OTEL_EXPORTER_OTLP_METRICS_HEADERS",+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "OTEL_EXPORTER_OTLP_TRACES_HEADERS",+}++func TestRunChildOverridesInheritedSignalRouting(t *testing.T) {+ testenv.RequirePOSIXExecutableFixtures(t)+ for _, signal := range []string{"LOGS", "METRICS", "TRACES"} {+ t.Setenv("OTEL_EXPORTER_OTLP_"+signal+"_ENDPOINT", "https://old-collector.invalid/v1/"+signal)+ t.Setenv("OTEL_EXPORTER_OTLP_"+signal+"_PROTOCOL", "http/protobuf")+ t.Setenv("OTEL_EXPORTER_OTLP_"+signal+"_HEADERS", "x-signal-token=secret")+ }+ t.Setenv("OTEL_EXPORTER_OTLP_HEADERS", "Authorization=Bearer secret")+ t.Setenv("BETA_TRACING_ENDPOINT", "https://old-collector.invalid/beta")+ t.Setenv("OTEL_LOG_RAW_API_BODIES", "1")+ output := filepath.Join(t.TempDir(), "child-env")+ child := fakeExecutable(t, "capture-env", "#!/bin/sh\nenv > \"$1\"\n")+ session := &Session{Harness: "claude", BaseDir: t.TempDir(), GRPCEndpoint: "http://127.0.0.1:54317"}+ code, err := session.RunChild(context.Background(), []string{child, output}, nil, nil)+ if err != nil || code != 0 {+ t.Fatalf("child: code=%d error=%v", code, err)+ }+ data, err := os.ReadFile(output)+ if err != nil {+ t.Fatal(err)+ }+ env := envMap(strings.Split(string(data), "\n"))+ if env["OTEL_EXPORTER_OTLP_ENDPOINT"] != session.GRPCEndpoint {+ t.Fatal("missing CI collector endpoint")+ }+ for _, key := range signalRoutingKeys {+ want := ""+ if strings.HasSuffix(key, "_PROTOCOL") {+ want = "grpc"+ }+ if got := env[key]; got != want {+ t.Errorf("%s = %q, want %q", key, got, want)+ }+ }+ if env["OTEL_LOG_RAW_API_BODIES"] != "1" {+ t.Fatal("lost caller's independent capture opt-in")+ }+}++func TestSavedSessionExportsNeutralizeSignalEndpointOverrides(t *testing.T) {+ base := []string{"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://old-collector.invalid/logs", "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http/protobuf"}+ cfg, err := BuildHarnessConfig(base, "claude,codex", "http://127.0.0.1:54317", t.TempDir(), nil)+ if err != nil {+ t.Fatal(err)+ }+ session := &Session{BaseDir: t.TempDir(), Env: cfg.Env, Paths: cfg.Paths}+ state := filepath.Join(t.TempDir(), "session.json")+ if err := session.SaveState(state); err != nil {+ t.Fatal(err)+ }+ restored, err := LoadState(state)+ if err != nil {+ t.Fatal(err)+ }+ env := envMap(base)+ for key, value := range restored.Exports() {+ env[key] = value+ }+ if env["OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"] != "" || env["OTEL_EXPORTER_OTLP_LOGS_PROTOCOL"] != "grpc" {+ t.Fatalf("saved exports preserve inherited signal routing: %v", env)+ }+}++// ci start writes the overlay to $GITHUB_ENV for every later step, so a key the job never set must+// not appear there, even as an empty value.+func TestClaudeConfigAddsNoRoutingOverridesTheCallerDidNotNeed(t *testing.T) {+ cfg, err := BuildHarnessConfig([]string{"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT= "}, "claude", "http://127.0.0.1:54317", t.TempDir(), nil)+ if err != nil {+ t.Fatal(err)+ }+ for _, key := range signalRoutingKeys {+ if value, ok := cfg.Env[key]; ok {+ t.Errorf("config sets %s=%q though the caller did not route that signal", key, value)+ }+ }+}++// Codex takes its endpoint from the generated config.toml, which its OTLP exporter prefers to any+// per-signal environment variable, so a Codex-only session leaves the caller's routing alone.+func TestCodexOnlyConfigLeavesInheritedSignalRoutingAlone(t *testing.T) {+ base := []string{"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://old-collector.invalid/logs", "OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer secret"}+ cfg, err := BuildHarnessConfig(base, "codex", "http://127.0.0.1:54317", t.TempDir(), nil)+ if err != nil {+ t.Fatal(err)+ }+ for _, key := range signalRoutingKeys {+ if value, ok := cfg.Env[key]; ok {+ t.Errorf("Codex-only config sets %s=%q", key, value)+ }+ }+}diff --git a/cli/beacon/internal/claudeotel/claudeotel.go b/cli/beacon/internal/claudeotel/claudeotel.gonew file mode 100644index 00000000..8c971f1b--- /dev/null+++ b/cli/beacon/internal/claudeotel/claudeotel.go@@ -0,0 +1,71 @@+// Package claudeotel builds the environment that sends Claude Code's OpenTelemetry export to a+// Beacon collector. `beacon ci` lays it over a CI job's environment and `beacon endpoint` writes it+// into Claude Code's settings.json, so both send every signal to the same place.+package claudeotel++import "strings"++// protocol is the one Beacon's collector endpoint speaks.+const protocol = "grpc"++var signals = []string{"LOGS", "METRICS", "TRACES"}++// OTLPEnv returns the variables that send Claude Code's logs, metrics and traces to endpoint.+//+// caller is the environment Claude Code would otherwise run with. Claude Code lets a per-signal+// endpoint or protocol replace the generic one, merges per-signal headers into the generic ones, and+// sends detailed beta tracing to BETA_TRACING_ENDPOINT instead of through its exporters. Any of these+// set there would send a signal past the collector, or hand the collector credentials meant for+// another one, so each that caller sets is cancelled here: Claude Code and the OpenTelemetry SDK treat+// an empty value as unset. Variables caller leaves unset are not written, so nothing new reaches+// other programs that inherit the result.+func OTLPEnv(endpoint string, caller map[string]string) map[string]string {+ env := map[string]string{+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",+ "OTEL_LOGS_EXPORTER": "otlp",+ "OTEL_METRICS_EXPORTER": "otlp",+ // Delta temporality keeps token usage counters per-interval so downstream+ // aggregation can sum datapoints without deduping cumulative series.+ "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "delta",+ "OTEL_EXPORTER_OTLP_PROTOCOL": protocol,+ "OTEL_EXPORTER_OTLP_ENDPOINT": endpoint,+ // Tool details expose the command, file path, URL, search pattern, and MCP+ // identity/arguments needed to reconstruct agent activity from OTel events.+ "OTEL_LOG_TOOL_DETAILS": "1",+ "OTEL_LOG_USER_PROMPTS": "1",+ }+ override := func(key, value string) {+ if strings.TrimSpace(caller[key]) != "" {+ env[key] = value+ }+ }+ override("OTEL_EXPORTER_OTLP_HEADERS", "")+ for _, signal := range signals {+ override("OTEL_EXPORTER_OTLP_"+signal+"_PROTOCOL", protocol)+ override("OTEL_EXPORTER_OTLP_"+signal+"_HEADERS", "")+ }+ for _, key := range RedirectKeys() {+ override(key, "")+ }+ return env+}++// RedirectKeys are the variables that send a Claude Code signal somewhere other than+// OTEL_EXPORTER_OTLP_ENDPOINT.+func RedirectKeys() []string {+ keys := make([]string, 0, len(signals)+1)+ for _, signal := range signals {+ keys = append(keys, "OTEL_EXPORTER_OTLP_"+signal+"_ENDPOINT")+ }+ return append(keys, "BETA_TRACING_ENDPOINT")+}++// InlineRawBodies reports whether an OTEL_LOG_RAW_API_BODIES value has Claude Code put API bodies+// inline in its log events, rather than leave them off or write them to files Beacon never reads.+func InlineRawBodies(value string) bool {+ switch strings.ToLower(strings.TrimSpace(value)) {+ case "1", "true":+ return true+ }+ return false+}diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.goindex 7e9737af..f5d404e4 100644--- a/cli/beacon/internal/endpoint/harness/harness.go+++ b/cli/beacon/internal/endpoint/harness/harness.go@@ -11,6 +11,7 @@ import ("strings""time"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudeotel""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/devinsession"@@ -405,18 +406,21 @@ func ConfigureClaude(opts ConfigureOptions) (string, error) {if env == nil {env = map[string]interface{}{}}- env["CLAUDE_CODE_ENABLE_TELEMETRY"] = "1"- env["OTEL_LOGS_EXPORTER"] = "otlp"- env["OTEL_METRICS_EXPORTER"] = "otlp"- // Delta temporality keeps token usage counters per-interval so downstream- // aggregation can sum datapoints without deduping cumulative series.- env["OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"] = "delta"- env["OTEL_EXPORTER_OTLP_PROTOCOL"] = "grpc"- env["OTEL_EXPORTER_OTLP_ENDPOINT"] = opts.Endpoint- // Tool details expose the command, file path, URL, search pattern, and MCP- // identity/arguments needed to reconstruct agent activity from OTel events.- env["OTEL_LOG_TOOL_DETAILS"] = "1"- env["OTEL_LOG_USER_PROMPTS"] = "1"+ // Claude Code runs with the user's shell environment, and a value in settings.json replaces the+ // same variable from there. The routing a session would otherwise get is both, as far as Beacon+ // can see the shell from here.+ caller := map[string]string{}+ for _, entry := range os.Environ() {+ if key, value, ok := strings.Cut(entry, "="); ok {+ caller[key] = value+ }+ }+ for key, value := range env {+ caller[key] = fmt.Sprint(value)+ }+ for key, value := range claudeotel.OTLPEnv(opts.Endpoint, caller) {+ env[key] = value+ }// Inline API bodies carry the page WebFetch sends to its summarizer model and the// MCP tool definitions the model is shown, the only place Claude Code reports// either, and also the system prompt and the whole conversation. The collector's@@ -427,12 +431,12 @@ func ConfigureClaude(opts ConfigureOptions) (string, error) {switch {case opts.CaptureModelContext && !configured:env["OTEL_LOG_RAW_API_BODIES"] = "1"- case !opts.CaptureModelContext && claudeInlineRawBodies(rawBodies):+ case !opts.CaptureModelContext && claudeotel.InlineRawBodies(fmt.Sprint(rawBodies)):delete(env, "OTEL_LOG_RAW_API_BODIES")}contentLimit, limited := env["CLAUDE_CODE_OTEL_CONTENT_MAX_LENGTH"]switch {- case opts.CaptureModelContext && !limited && claudeInlineRawBodies(env["OTEL_LOG_RAW_API_BODIES"]):+ case opts.CaptureModelContext && !limited && claudeotel.InlineRawBodies(fmt.Sprint(env["OTEL_LOG_RAW_API_BODIES"])):env["CLAUDE_CODE_OTEL_CONTENT_MAX_LENGTH"] = claudeModelContextContentLimitcase !opts.CaptureModelContext && fmt.Sprint(contentLimit) == claudeModelContextContentLimit:delete(env, "CLAUDE_CODE_OTEL_CONTENT_MAX_LENGTH")@@ -560,13 +564,22 @@ func claudeStatus(path string) (TelemetryStatus, string) {if fmt.Sprint(env["CLAUDE_CODE_ENABLE_TELEMETRY"]) != "1" {return TelemetryDisabled, "CLAUDE_CODE_ENABLE_TELEMETRY is not enabled"}- if !strings.Contains(fmt.Sprint(env["OTEL_EXPORTER_OTLP_ENDPOINT"]), "127.0.0.1") &&- !strings.Contains(fmt.Sprint(env["OTEL_EXPORTER_OTLP_ENDPOINT"]), "localhost") {+ if !localOTLPEndpoint(env["OTEL_EXPORTER_OTLP_ENDPOINT"]) {return TelemetryMisconfigured, "OTLP endpoint does not point to localhost"}+ for _, key := range claudeotel.RedirectKeys() {+ if value, set := env[key]; set && strings.TrimSpace(fmt.Sprint(value)) != "" && !localOTLPEndpoint(value) {+ return TelemetryMisconfigured, key + " sends Claude telemetry away from localhost"+ }+ }return TelemetryEnabled, "Claude telemetry is configured for local OTLP"}+func localOTLPEndpoint(value interface{}) bool {+ endpoint := fmt.Sprint(value)+ return strings.Contains(endpoint, "127.0.0.1") || strings.Contains(endpoint, "localhost")+}+func codexStatus(path string) (TelemetryStatus, string) {data, err := os.ReadFile(path)if err != nil {@@ -798,16 +811,6 @@ func commandVersion(path string) string {// per session.const claudeModelContextContentLimit = "262144"-// claudeInlineRawBodies reports whether an OTEL_LOG_RAW_API_BODIES value has Claude Code put-// API bodies inline in its log events, rather than leave them off or write them to files.-func claudeInlineRawBodies(value interface{}) bool {- switch strings.ToLower(strings.TrimSpace(fmt.Sprint(value))) {- case "1", "true":- return true- }- return false-}-// decodeSettings parses a harness's JSON settings file. The error names the file so the user// knows which one to fix.func decodeSettings(product, path string, data []byte) (map[string]interface{}, error) {diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.goindex 2fe1c437..ddd9cd43 100644--- a/cli/beacon/internal/endpoint/harness/harness_test.go+++ b/cli/beacon/internal/endpoint/harness/harness_test.go@@ -169,6 +169,93 @@ func TestConfigureClaudeWritesTelemetryEnvAndBackup(t *testing.T) {}}+var claudeRoutingKeys = []string{+ "OTEL_EXPORTER_OTLP_HEADERS",+ "BETA_TRACING_ENDPOINT",+ "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", "OTEL_EXPORTER_OTLP_LOGS_HEADERS",+ "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", "OTEL_EXPORTER_OTLP_METRICS_HEADERS",+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", "OTEL_EXPORTER_OTLP_TRACES_HEADERS",+}++// configureClaudeOver writes settings.json with env, clears the routing variables from this+// process's environment, and returns the settings path.+func configureClaudeOver(t *testing.T, env string) string {+ t.Helper()+ home := t.TempDir()+ testenv.SetHome(t, home)+ for _, key := range claudeRoutingKeys {+ t.Setenv(key, "")+ }+ path := filepath.Join(home, ".claude", "settings.json")+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(path, []byte(`{"env":`+env+`}`), 0600); err != nil {+ t.Fatal(err)+ }+ return path+}++func readClaudeEnv(t *testing.T, path string) map[string]string {+ t.Helper()+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ var settings map[string]map[string]string+ if err := json.Unmarshal(data, &settings); err != nil {+ t.Fatal(err)+ }+ return settings["env"]+}++// Claude Code lets a per-signal endpoint, protocol or headers variable replace or join the generic+// one, so one left in settings.json or the shell sends that signal past the local collector.+func TestConfigureClaudeOverridesPerSignalRouting(t *testing.T) {+ path := configureClaudeOver(t, `{+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",+ "OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:4317",+ "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://siem.example.com/v1/logs",+ "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/protobuf",+ "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer secret"+ }`)+ t.Setenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://shell.example.com/v1/traces")+ if status, msg := claudeStatus(path); status != TelemetryMisconfigured {+ t.Fatalf("claudeStatus before configure = %q (%s), want %q while logs go to the SIEM", status, msg, TelemetryMisconfigured)+ }++ if _, err := ConfigureClaude(ConfigureOptions{Endpoint: "http://127.0.0.1:4317", UserMode: true}); err != nil {+ t.Fatal(err)+ }+ env := readClaudeEnv(t, path)+ for key, want := range map[string]string{+ "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "",+ "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "grpc",+ "OTEL_EXPORTER_OTLP_HEADERS": "",+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "",+ } {+ if got, set := env[key]; !set || got != want {+ t.Errorf("env[%s] = %q (set=%v), want %q", key, got, set, want)+ }+ }+ if status, msg := claudeStatus(path); status != TelemetryEnabled {+ t.Fatalf("claudeStatus after configure = %q (%s), want %q", status, msg, TelemetryEnabled)+ }+}++func TestConfigureClaudeAddsNoRoutingOverridesNobodySet(t *testing.T) {+ path := configureClaudeOver(t, `{"EXISTING": "1"}`)+ if _, err := ConfigureClaude(ConfigureOptions{Endpoint: "http://127.0.0.1:4317", UserMode: true}); err != nil {+ t.Fatal(err)+ }+ env := readClaudeEnv(t, path)+ for _, key := range claudeRoutingKeys {+ if value, set := env[key]; set {+ t.Errorf("settings.json env sets %s=%q though nothing routed that signal", key, value)+ }+ }+}+// Model-context capture is opt-in. The opt-in sets inline API bodies only where nothing is set, and// install without it removes an inline setting, so a repair without the flag turns capture off.// Neither overrides 0 or file:<dir>.@@ -308,6 +395,9 @@ func TestClaudeStatusVariants(t *testing.T) {{name: "disabled", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"0"}}`, status: TelemetryDisabled},{name: "remote endpoint", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"https://example.com"}}`, status: TelemetryMisconfigured},{name: "enabled", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:4317"}}`, status: TelemetryEnabled},+ {name: "per-signal remote endpoint", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:4317","OTEL_EXPORTER_OTLP_LOGS_ENDPOINT":"https://example.com/v1/logs"}}`, status: TelemetryMisconfigured},+ {name: "beta tracing remote endpoint", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:4317","BETA_TRACING_ENDPOINT":"https://example.com"}}`, status: TelemetryMisconfigured},+ {name: "per-signal endpoint cancelled", body: `{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:4317","OTEL_EXPORTER_OTLP_LOGS_ENDPOINT":""}}`, status: TelemetryEnabled},}for _, tt := range tests {diff --git a/docs/cli/ci.mdx b/docs/cli/ci.mdxindex e09a589e..d2c0d866 100644--- a/docs/cli/ci.mdx+++ b/docs/cli/ci.mdx@@ -86,6 +86,10 @@ See the [Claude Code Security Review session workflow](https://github.com/asympt</Card></Columns>+## Collector routing++When Claude telemetry is selected, `ci exec` and `ci start` send every Claude Code signal to the session’s local collector. If the job’s environment sets a per-signal endpoint, protocol, or headers variable (such as `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`), `OTEL_EXPORTER_OTLP_HEADERS`, or `BETA_TRACING_ENDPOINT`, Beacon cancels it for Claude Code and for the steps that follow `ci start`. Variables the job did not set are left unset.+## Artifact pathsBy default, Beacon writes CI artifacts under `$RUNNER_TEMP/beacon` when `RUNNER_TEMP` is set. Otherwise it uses the system temp directory.diff --git a/docs/runtimes/claude-code.mdx b/docs/runtimes/claude-code.mdxindex c0b585cd..2cde1061 100644--- a/docs/runtimes/claude-code.mdx+++ b/docs/runtimes/claude-code.mdx@@ -70,6 +70,8 @@ Beacon detects Claude Code through the `claude` executable and Claude settings p`beacon endpoint install` configures Claude telemetry settings so Claude Code sends OTLP data to the local collector. It enables detailed tool logging so tool-result events include inputs such as Bash commands, file paths, URLs, search patterns, and MCP server/tool arguments. Claude bounds or truncates some input values.+If `~/.claude/settings.json` or the environment install runs in sets a per-signal endpoint, protocol, or headers variable (such as `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`), `OTEL_EXPORTER_OTLP_HEADERS`, or `BETA_TRACING_ENDPOINT`, install cancels it in `settings.json`, since Claude Code would otherwise send that signal to another collector. A variable exported only in a shell that install did not run in is not seen. `beacon endpoint status` reports Claude Code as misconfigured while `settings.json` sends a signal away from localhost.+`beacon endpoint hooks install --harness claude` adds Beacon-managed Claude Code hooks while preserving existing Claude settings and non-Beacon hooks. `beacon endpoint hooks uninstall --harness claude` removes only Beacon-managed Claude hook entries. Install, repair, and uninstall write every non-Beacon hook back exactly as they found it, including `http`, `prompt`, and `agent` hooks and any fields Beacon does not use itself, such as an http hook's `url` and `headers`.### Model context from API bodiesdiff --git a/packaging/macos/jamf/scripts/full-cleanup.sh b/packaging/macos/jamf/scripts/full-cleanup.shindex c8f9c695..f9215399 100755--- a/packaging/macos/jamf/scripts/full-cleanup.sh+++ b/packaging/macos/jamf/scripts/full-cleanup.sh@@ -361,6 +361,17 @@ for key in []:env.pop(key, None)+# Install cancels per-signal routing it found by writing these values. Remove only those, so a+# value someone set after install stays.+cancelled = {"OTEL_EXPORTER_OTLP_HEADERS": "", "BETA_TRACING_ENDPOINT": ""}+for signal in ("LOGS", "METRICS", "TRACES"):+ cancelled[f"OTEL_EXPORTER_OTLP_{signal}_ENDPOINT"] = ""+ cancelled[f"OTEL_EXPORTER_OTLP_{signal}_PROTOCOL"] = "grpc"+ cancelled[f"OTEL_EXPORTER_OTLP_{signal}_HEADERS"] = ""+for key, value in cancelled.items():+ if key in env and env[key] == value:+ env.pop(key)+data["env"] = envtry:replace_verified_text(diff --git a/packaging/macos/test-endpoint-scripts.sh b/packaging/macos/test-endpoint-scripts.shindex 8b08626e..859ffe47 100644--- a/packaging/macos/test-endpoint-scripts.sh+++ b/packaging/macos/test-endpoint-scripts.sh@@ -185,7 +185,7 @@ FULL_CLEANUP_LOCAL_RUNTIME="$TMP_DIR/full-cleanup-local-runtime"mkdir -p "$FULL_CLEANUP_LOCAL_HOME/.claude" "$FULL_CLEANUP_LOCAL_CONFIG/Endpoint" "$FULL_CLEANUP_LOCAL_RUNTIME"printf '%s\n' '{"collector":{"grpc_port":54317,"http_port":54318}}' \>"$FULL_CLEANUP_LOCAL_CONFIG/Endpoint/config.json"-printf '%s\n' '{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:54318/","OTEL_LOGS_EXPORTER":"otlp","UNRELATED":"kept"}}' \+printf '%s\n' '{"env":{"CLAUDE_CODE_ENABLE_TELEMETRY":"1","OTEL_EXPORTER_OTLP_ENDPOINT":"http://127.0.0.1:54318/","OTEL_LOGS_EXPORTER":"otlp","OTEL_EXPORTER_OTLP_LOGS_ENDPOINT":"","OTEL_EXPORTER_OTLP_LOGS_PROTOCOL":"grpc","OTEL_EXPORTER_OTLP_TRACES_ENDPOINT":"https://later.example.com","UNRELATED":"kept"}}' \>"$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json"printf '%s\n' secret-prompt >"$FULL_CLEANUP_LOCAL_RUNTIME/runtime.jsonl"PATH="$FULL_CLEANUP_USER_BIN:$FULL_CLEANUP_BIN:$PATH" \@@ -202,8 +202,9 @@ RUNTIME_DIR="$FULL_CLEANUP_LOCAL_RUNTIME" \SYSTEM_CONFIG_DIR="$FULL_CLEANUP_LOCAL_CONFIG" \OPT_BEACON_DIR="$TMP_DIR/full-cleanup-local-opt" \"$FULL_CLEANUP_SCRIPT" >/dev/null 2>&1-if grep -q -e OTEL_EXPORTER_OTLP_ENDPOINT -e CLAUDE_CODE_ENABLE_TELEMETRY -e OTEL_LOGS_EXPORTER "$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json" ||- ! grep -q '"UNRELATED": "kept"' "$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json"; then+if grep -q -e OTEL_EXPORTER_OTLP_ENDPOINT -e CLAUDE_CODE_ENABLE_TELEMETRY -e OTEL_LOGS_EXPORTER -e OTEL_EXPORTER_OTLP_LOGS_ "$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json" ||+ ! grep -q '"UNRELATED": "kept"' "$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json" ||+ ! grep -q '"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT": "https://later.example.com"' "$FULL_CLEANUP_LOCAL_HOME/.claude/settings.json"; thenecho "full cleanup should remove only the Claude OTLP settings that point at the installed Beacon collector" >&2exit 1fi