Skip to content

Add tracing spans and structured fields to Ninja subprocess execution #384

Description

@coderabbitai

Background

The NETSUKE_NINJA feature (PR #323) improved observability around Ninja subprocess execution. The following have already been implemented in PR #323:

  • command_span creates a "ninja_subprocess" tracing span with stable low-cardinality fields: operation, ninja_program, redacted_arg_count, suppress_stderr, failure_category = field::Empty
  • Spawn and exit failures record failure_category = "spawn" and failure_category = "exit_status" as structured span fields
  • log_command_execution, log_command_spawn_failure, log_command_exit_failure emit structured tracing events with operation and ninja_program fields

Remaining required work

Two acceptance criteria from the original description remain unmet:

1. Log NETSUKE_NINJA resolution at the env-var boundary

resolve_ninja_program_utf8_with in src/runner/process/mod.rs silently picks the env-var value or falls back to NINJA_PROGRAM with no trace event. Add a debug! event at that boundary, e.g.:

fn resolve_ninja_program_utf8_with<F>(mut read_env: F) -> Utf8PathBuf
where
    F: FnMut(&str) -> Option<OsString>,
{
    match read_env(NINJA_ENV).and_then(|value| {
        Utf8PathBuf::from_path_buf(PathBuf::from(value)).ok()
    }) {
        Some(path) => {
            tracing::debug!(
                ninja_program = %path,
                source = "env",
                "Resolved Ninja program from {NINJA_ENV}"
            );
            path
        }
        None => {
            tracing::debug!(
                ninja_program = NINJA_PROGRAM,
                source = "default",
                "NETSUKE_NINJA unset or non-UTF-8; using default Ninja program"
            );
            Utf8PathBuf::from(NINJA_PROGRAM)
        }
    }
}

2. Demote high-cardinality args/paths from the log event message

log_command_execution currently emits the full redacted_command string (which includes the build file path and target list) in the message body. Move high-cardinality data to a debug! companion event rather than including it in the info! span event message. The info! event should carry only stable low-cardinality fields; the redacted_command string should be emitted separately at debug! level.

Acceptance criteria

  • resolve_ninja_program_utf8_with emits a debug! event at the env-var resolution boundary with ninja_program and source fields
  • log_command_execution no longer includes redacted_command in its info! message body; that string is emitted at debug! level instead
  • Existing tests continue to pass under make check-fmt && make lint && make test
  • No broad lint suppressions beyond narrowly scoped #[expect(..., reason = "...")]

Backlinks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions