Added telemetry system to get information about issues.
This commit is contained in:
@@ -15,6 +15,8 @@ import threading
|
||||
import time
|
||||
from typing import Callable, Mapping, Sequence, TextIO
|
||||
|
||||
from .telemetry import current_telemetry
|
||||
|
||||
|
||||
OutputLineFilter = Callable[[str], str | None]
|
||||
MAX_CAPTURE_CHARACTERS = 1024 * 1024
|
||||
@@ -85,9 +87,16 @@ class CommandError(RuntimeError):
|
||||
class CommandRunner:
|
||||
"""Run argument arrays with timeouts and append-only JSONL logging."""
|
||||
|
||||
def __init__(self, log_path: Path, *, dry_run: bool = False) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
log_path: Path,
|
||||
*,
|
||||
dry_run: bool = False,
|
||||
operation: str | None = None,
|
||||
) -> None:
|
||||
self.log_path = log_path
|
||||
self.dry_run = dry_run
|
||||
self.operation = operation
|
||||
|
||||
def run(
|
||||
self,
|
||||
@@ -100,6 +109,7 @@ class CommandRunner:
|
||||
stream_output: bool = False,
|
||||
output_line_filter: OutputLineFilter | None = None,
|
||||
pass_fds: Sequence[int] = (),
|
||||
telemetry_stage: str | None = None,
|
||||
) -> CommandOutcome:
|
||||
arguments = [str(value) for value in argv]
|
||||
if not arguments:
|
||||
@@ -169,6 +179,18 @@ class CommandRunner:
|
||||
dry_run=False,
|
||||
)
|
||||
self._record(outcome, cwd, overrides)
|
||||
if outcome.timed_out or outcome.returncode != 0:
|
||||
telemetry = current_telemetry()
|
||||
if telemetry is not None:
|
||||
telemetry.report_subprocess_failure(
|
||||
"subprocess_failed",
|
||||
outcome,
|
||||
command=outcome.argv[:1],
|
||||
metadata={
|
||||
"operation": self.operation or "subprocess",
|
||||
**({"stage": telemetry_stage} if telemetry_stage else {}),
|
||||
},
|
||||
)
|
||||
if check and (outcome.timed_out or outcome.returncode != 0):
|
||||
raise CommandError(outcome)
|
||||
return outcome
|
||||
|
||||
Reference in New Issue
Block a user