Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/nix: log all command starts and exits #2135

Merged
merged 2 commits into from
Jun 12, 2024
Merged

internal/nix: log all command starts and exits #2135

merged 2 commits into from
Jun 12, 2024

Conversation

gcurtis
Copy link
Collaborator

@gcurtis gcurtis commented Jun 10, 2024

Write logs whenever a Nix command is about to start and after it exits. Make cmd a slog.LogValuer so that it writes structured log attributes grouped under a cmd prefix.

Example logs and attributes (line breaks added for readability):

msg="nix command starting"
	cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
	cmd.path=/nix/var/nix/profiles/default/bin/nix

msg="nix command exited"
	cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
	cmd.path=/nix/var/nix/profiles/default/bin/nix
	cmd.pid=68672
	cmd.code=0
	cmd.dur=34.296041ms

Command exits are always logged at the debug level, even if the command exits with a non-zero exit code. This is because some commands might be expected to fail (for example, when checking if a path exists in the store).

Write logs whenever a Nix command is about to start and after it exits.
Make `cmd` a `slog.LogValuer` so that it writes structured log
attributes grouped under a `cmd` prefix.

Example logs and attributes (line breaks added for readability):

	msg="nix command starting"
		cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
		cmd.path=/nix/var/nix/profiles/default/bin/nix

	msg="nix command exited"
		cmd.args="nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' eval --impure --raw --expr builtins.currentSystem"
		cmd.path=/nix/var/nix/profiles/default/bin/nix
		cmd.pid=68672
		cmd.code=0
		cmd.dur=34.296041ms

Command exits are always logged at the debug level, even if the command
exits with a non-zero exit code. This is because some commands might be
expected to fail (for example, when checking if a path exists in the
store).
@gcurtis gcurtis requested review from mikeland73 and savil June 10, 2024 16:39
Signed-off-by: Greg Curtis <greg.curtis@jetpack.io>
@gcurtis gcurtis merged commit 1bc2a30 into main Jun 12, 2024
24 checks passed
@gcurtis gcurtis deleted the gcurtis/cmdlog branch June 12, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants