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) <noreply@anthropic.com>
This commit is contained in:
parent
e72cd8b315
commit
26fc5b2bc0
3 changed files with 35 additions and 2 deletions
|
|
@ -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` |
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue