Add context to log statements.
This commit is contained in:
@ -94,7 +94,7 @@ func (nc *nomadAPIClient) Execute(runnerID string,
|
||||
ctx context.Context, cmd string, tty bool,
|
||||
stdin io.Reader, stdout, stderr io.Writer,
|
||||
) (int, error) {
|
||||
log.WithField("command", strings.ReplaceAll(cmd, "\n", "")).Trace("Requesting Nomad Exec")
|
||||
log.WithContext(ctx).WithField("command", strings.ReplaceAll(cmd, "\n", "")).Trace("Requesting Nomad Exec")
|
||||
var allocations []*nomadApi.AllocationListStub
|
||||
var err error
|
||||
logging.StartSpan("nomad.execute.list", "List Allocations for id", ctx, func(_ context.Context) {
|
||||
@ -132,10 +132,10 @@ func (nc *nomadAPIClient) Execute(runnerID string,
|
||||
case err == nil:
|
||||
return exitCode, nil
|
||||
case websocket.IsCloseError(errors.Unwrap(err), websocket.CloseNormalClosure):
|
||||
log.WithField("runnerID", runnerID).WithError(err).Info("The exit code could not be received.")
|
||||
log.WithContext(ctx).WithField("runnerID", runnerID).WithError(err).Info("The exit code could not be received.")
|
||||
return 0, nil
|
||||
case errors.Is(err, context.Canceled):
|
||||
log.WithField("runnerID", runnerID).Debug("Execution canceled by context")
|
||||
log.WithContext(ctx).WithField("runnerID", runnerID).Debug("Execution canceled by context")
|
||||
return 0, nil
|
||||
default:
|
||||
return 1, fmt.Errorf("error executing command in allocation: %w", err)
|
||||
|
@ -482,7 +482,7 @@ func (a *APIClient) executeCommandInteractivelyWithStderr(allocationID string, c
|
||||
exit, err := a.Execute(allocationID, ctx, prepareCommandTTYStdErr(currentNanoTime, privilegedExecution), true,
|
||||
nullio.Reader{Ctx: readingContext}, stderr, io.Discard)
|
||||
if err != nil {
|
||||
log.WithError(err).WithField("runner", allocationID).Warn("Stderr task finished with error")
|
||||
log.WithContext(ctx).WithError(err).WithField("runner", allocationID).Warn("Stderr task finished with error")
|
||||
}
|
||||
stderrExitChan <- exit
|
||||
})
|
||||
|
@ -56,7 +56,7 @@ func (s *SentryDebugWriter) Write(p []byte) (n int, err error) {
|
||||
|
||||
match := matchAndMapTimeDebugMessage(p)
|
||||
if match == nil {
|
||||
log.WithField("data", p).Warn("Exec debug message could not be read completely")
|
||||
log.WithContext(s.Ctx).WithField("data", p).Warn("Exec debug message could not be read completely")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func (s *SentryDebugWriter) Close(exitCode int) {
|
||||
func (s *SentryDebugWriter) handleTimeDebugMessage(match map[string][]byte) {
|
||||
timestamp, err := strconv.ParseInt(string(match["time"]), 10, 64)
|
||||
if err != nil {
|
||||
log.WithField("match", match).Warn("Could not parse Unix timestamp")
|
||||
log.WithContext(s.Ctx).WithField("match", match).Warn("Could not parse Unix timestamp")
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user