From 26fc5b2bc0bce7dc313b18e9501b7dc28d7cd58a Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Tue, 6 Oct 2026 04:26:32 +0000 Subject: [PATCH] fix(telemetry): bounded process resource attributes (no command args) buildResource used resource.WithProcess(), which also runs the SDK's command-args detector and exports the full argv as process.command_args on every metric and span. The attribute is unbounded (a `bd dep list` over thousands of ids produced a 96 KB resource attribute that crash-looped the receiving collector) and copies untrusted text such as issue titles off the command line. List the bounded process detectors instead: pid, executable name and path, runtime name, version and description. process.command_args goes, and so does process.owner, which WithProcess also added. TestBuildResource_ProcessAttributesBounded asserts the resource has no process.command_args or process.command_line and still has process.pid and process.executable.name. It fails on main with the test binary's argv in process.command_args. Closes #7277 Agent-Signature: claude-agent-sdk-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) --- engdocs/design/otel/otel-architecture.md | 2 +- internal/telemetry/telemetry.go | 12 +++++++++++- internal/telemetry/telemetry_test.go | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/engdocs/design/otel/otel-architecture.md b/engdocs/design/otel/otel-architecture.md index 66d211ed8..9f83758d8 100644 --- a/engdocs/design/otel/otel-architecture.md +++ b/engdocs/design/otel/otel-architecture.md @@ -518,7 +518,7 @@ Every factual claim in this document is backed by a specific source location. Th | Traces: stdout only when `BD_OTEL_STDOUT=true` | `telemetry.go:84-93` | | Metrics: HTTP OTLP when `BD_OTEL_METRICS_URL` set | `telemetry.go:131-139` | | Resource: `service.name`, `service.version` | `telemetry.go:73-75` | -| Resource: `WithHost()`, `WithProcess()` | `telemetry.go:76-77` | +| Resource: `WithHost()` and the bounded `WithProcess*` detectors (no `process.command_args`) | `telemetry.go` `buildResource` | | `Shutdown(ctx)` signature | `telemetry.go:162` | | `Init` called in `PersistentPreRun` | `main.go:256` | | Command span started with `bd.command`, `bd.version`, `bd.args` | `main.go:262-266` | diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index d1f5ae505..be36e3792 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -135,6 +135,11 @@ func translateLegacyEnv() []string { // Defaults are merged with the host/process detectors and finally with the // FromEnv detector, so OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES can // override anything set by the caller. +// +// The process detectors are listed one by one rather than through +// resource.WithProcess, which also exports argv as process.command_args: +// unbounded (a `bd dep list` over thousands of ids made a 96 KB attribute) +// and full of untrusted issue titles (mc-vin7r). func buildResource(ctx context.Context, serviceName, version string) (*resource.Resource, error) { return resource.New(ctx, resource.WithAttributes( @@ -142,7 +147,12 @@ func buildResource(ctx context.Context, serviceName, version string) (*resource. semconv.ServiceVersionKey.String(version), ), resource.WithHost(), - resource.WithProcess(), + resource.WithProcessPID(), + resource.WithProcessExecutableName(), + resource.WithProcessExecutablePath(), + resource.WithProcessRuntimeName(), + resource.WithProcessRuntimeVersion(), + resource.WithProcessRuntimeDescription(), resource.WithFromEnv(), ) } diff --git a/internal/telemetry/telemetry_test.go b/internal/telemetry/telemetry_test.go index 3beeb8e4a..7be3e272e 100644 --- a/internal/telemetry/telemetry_test.go +++ b/internal/telemetry/telemetry_test.go @@ -255,6 +255,29 @@ func TestBuildResource_OTELResourceAttributesMerged(t *testing.T) { } } +// TestBuildResource_ProcessAttributesBounded pins mc-vin7r: the resource +// carries no argv. process.command_args grows with the command line (a `bd dep +// list` over thousands of ids made a 96 KB attribute that crash-looped the +// collector) and copies untrusted titles out of argv; process.command_line is +// the same data joined. The bounded process attributes stay. +func TestBuildResource_ProcessAttributesBounded(t *testing.T) { + clearAllEnv(t) + res, err := buildResource(context.Background(), "bd", "1.0.0") + if err != nil { + t.Fatalf("buildResource: %v", err) + } + for _, key := range []string{"process.command_args", "process.command_line"} { + if got, ok := lookupAttr(res.Attributes(), key); ok { + t.Errorf("%s = %q, want absent", key, got.Emit()) + } + } + for _, key := range []string{"process.pid", "process.executable.name"} { + if _, ok := lookupAttr(res.Attributes(), key); !ok { + t.Errorf("%s missing", key) + } + } +} + // resetTelemetryState restores noop providers and clears registered shutdown // hooks after a test that called Init, so global OTel state doesn't leak // between tests.