Skip to content

Record proxied exit codes and subcommands in command telemetry - #396

Open
gtsiolis wants to merge 2 commits into
mainfrom
devx-1003-record-proxied-exit-code-and-subcommand
Open

Record proxied exit codes and subcommands in command telemetry#396
gtsiolis wants to merge 2 commits into
mainfrom
devx-1003-record-proxied-exit-code-and-subcommand

Conversation

@gtsiolis

@gtsiolis gtsiolis commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Improve command telemetry for proxied tools so failures can be attributed to the command that ran and to its real process exit code.

This addresses the diagnostic gap behind DEVX-1003: analytics showed exit status 252 frequently, but lstk_command flattened failures to exit_code=1 and proxy commands did not expose enough command-path context to identify the affected AWS service or operation.

Classifying proxied-tool failures separately from lstk failures remains out of scope and is tracked by DEVX-1004.

Root cause

Cobra cannot derive a command path below proxy commands because they disable flag parsing and forward their arguments verbatim. Telemetry therefore saw only commands such as aws or terraform.

Exit codes were also recorded before all command wrappers had finished translating errors. In JSON mode, this meant telemetry and tracing could miss the final process exit code attached by the JSON envelope.

Approach

  • Centralize exit-code resolution in cmd.ExitCode, preserving wrapped-process and JSON exit codes across process handling, command telemetry, tracing, and extension telemetry.
  • Order the JSON, tracing, and telemetry middleware so telemetry observes the final translated error while user-visible exit behavior stays unchanged.
  • Derive an optional parameters.subcommand using each proxy CLI's grammar: AWS records service + operation; known nested Terraform/SAM groups record group + action; flat or positional commands record only the top-level command.
  • Strip lstk flags and pre-command --endpoint-url, stop at flag-like arguments, cap tokens at 64 runes, and omit unsafe values so resource names, stack names, addresses, and search terms do not enter telemetry.
  • Validate the emitted event end to end with a Docker-free mock emulator and fake AWS CLI that exits 252, alongside unit coverage for exit codes, middleware ordering, grammar limits, positional-value exclusion, flags, and truncation.

Verification

  • make test — 1,444 tests passed
  • make test-integration RUN=TestAWSProxyTelemetryRecordsExitCodeAndSubcommand — passed
  • gofmt check on the changed Go files — clean
  • pre-commit secret scan — passed

Review: Human review advised because this changes the telemetry schema, middleware ordering, and the privacy boundary for proxy command tokens.

Towards DEVX-1003

Co-Authored-By: Claude noreply@anthropic.com

@gtsiolis gtsiolis added semver: patch docs: skip Pull request does not require documentation changes labels Jul 17, 2026
@gtsiolis gtsiolis self-assigned this Jul 17, 2026
@gtsiolis
gtsiolis force-pushed the devx-1003-record-proxied-exit-code-and-subcommand branch 3 times, most recently from 80c4a90 to 69fec42 Compare July 22, 2026 07:07
@gtsiolis
gtsiolis force-pushed the devx-1003-record-proxied-exit-code-and-subcommand branch 2 times, most recently from ab94007 to cca169b Compare July 28, 2026 07:11
@gtsiolis
gtsiolis marked this pull request as ready for review August 4, 2026 11:49
@gtsiolis
gtsiolis requested a review from a team as a code owner August 4, 2026 11:49
@gtsiolis
gtsiolis force-pushed the devx-1003-record-proxied-exit-code-and-subcommand branch from cca169b to 8f1ca0f Compare August 4, 2026 11:52
@gtsiolis
gtsiolis force-pushed the devx-1003-record-proxied-exit-code-and-subcommand branch from 8f1ca0f to 27fec23 Compare August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant