-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: os/exec: add GODEBUG flag to print a line to STDERR for each command started #56301
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
Comments
For what it's worth, I would also have found this useful a few times. For example, when debugging why a Go tool isn't working the way I expect it too, or when it's surprisingly slow, it's very useful to be able to tell what Would there also be lines printed out when commands finish, with stats like elapsed time or cpu user/system time? I would find those useful too, at times. |
What precedent does this set? How do we choose which elements of the library need special annoations? A GODEBUG element for every file we open? Every chdir that executes? Every regular expression we parse? This proposal suggests the wrong solution, or at least the wrong location, to fix something that may actually deserve attention. Since pretty much everyone uses something like Cobra for CLIs these days, isn't that a better place to manage logging? |
These all provide value, which is why But almost every time, the only reason I actually wanted this logging was so that I could debug my program. (Perhaps this experience doesn't resonate with others.) As you say, one possible solution for this is to simply provide a logging wrapper. A third-party library could do it, too. My suggestion of (The other benefit over relying external tooling such as Another alternative, which I didn't previously consider, is to make |
I more-or-less agree with @robpike. This sounds useful, but also somewhat arbitrary in a big space of other similar potentially useful traces. Here's another thought: runtime/trace is very heavyweight from capturing this right now, but imagine if it were lighter weight, allowed filtering to only these events you care about, and could potentially integrate better with logging? |
Right, that would be ideal. (Well, that and also something to print it for you without having to launch the trace viewer.) It might also make sense to support I stand by spawning subprocesses being unfortunately hard, and the nice thing about |
What about something analogous to httptrace? package exec
type Trace struct {
OnCommandStarted func(context.Context, *CommandStartedEvent)
}
type CommandStartedEvent struct {
Command *Cmd
}
func WithTrace(ctx context.Context, trace *Trace) context.Context {
// ...
} Then The |
I think we want to expose this trace programmatically, not just for ingestion by humans, the better solution is to try and expose all tracing information programmatically. Then, as @prattmic suggests, we can just track this in regular My argument for |
This proposal has been added to the active column of the proposals project |
It sounds like there are serious objections to library code printing to stderr based on GODEBUG. We did that for the runtime and GC, but we probably shouldn't keep doing it. Finding a way to get this information into runtime/trace sounds like a reasonable plan. Do we know what that would look like? Should this wait for a redesign of runtime/trace? |
I think exposing this in As a result, this might want to wait on a redesign of |
Going to mark this as a likely decline for the GODEBUG, but we should return to this general idea with tracing. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
This came out of a conversation with @aclements about trying to understand what commands
cmd/dist
runs, but I've found such a thing to be useful forx/benchmarks/sweet
as well (and had to implement my own wrapper to get this functionality).These use-cases suggest this might be a more generally useful flag for debugging CLI tools that frequently start commands, especially when the logic for how those commands are constructed is somewhat complex.
The alternative is to use something like
strace
or whatever your platform provides, but this typically introduces additional overheads and it's a bit more indirect (i.e.syscall.Exec
andos/exec.Command
typically have different intents).The text was updated successfully, but these errors were encountered: