Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goodspark committed Aug 23, 2023
1 parent 4ee6553 commit 9e398d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions agent/job_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ func (r *JobRunner) createEnvironment() ([]string, error) {
if r.conf.AgentConfiguration.TracingBackend != "" {
env["BUILDKITE_TRACING_BACKEND"] = r.conf.AgentConfiguration.TracingBackend
env["BUILDKITE_TRACING_SERVICE_NAME"] = r.conf.AgentConfiguration.TracingServiceName
env["BUILDKITE_TRACE_LOG_GROUPS"] = fmt.Sprintf("%t", r.conf.AgentConfiguration.TraceLogGroups)
}

// see documentation for BuildkiteMessageMax
Expand Down
16 changes: 11 additions & 5 deletions internal/job/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,14 @@ func (s *Shell) executeCommand(
tracedEnv := env.FromSlice(cmd.Env)
s.injectTraceCtx(ctx, tracedEnv)
cmd.Env = tracedEnv.ToSlice()
logToSpanWriter := &spanMakerWriter{w: w, ctx: ctx, span: nil}
defer func() { logToSpanWriter.FinishIfActive() }()
writer := w
writerCloser := func() {}
if s.TraceLogGroups {
logToSpanWriter := &spanMakerWriter{w: w, ctx: ctx, span: nil}
writer = logToSpanWriter
writerCloser = func() { logToSpanWriter.FinishIfActive() }
}
defer writerCloser()

s.cmdLock.Lock()
s.cmd = cmd
Expand All @@ -592,11 +598,11 @@ func (s *Shell) executeCommand(
// Modify process config based on execution flags
if flags.PTY {
cfg.PTY = true
cfg.Stdout = logToSpanWriter
cfg.Stdout = writer
} else {
// Show stdout if requested or via debug
if flags.Stdout {
cfg.Stdout = logToSpanWriter
cfg.Stdout = writer
} else if s.Debug {
stdOutStreamer := NewLoggerStreamer(s.Logger)
defer stdOutStreamer.Close()
Expand All @@ -605,7 +611,7 @@ func (s *Shell) executeCommand(

// Show stderr if requested or via debug
if flags.Stderr {
cfg.Stderr = logToSpanWriter
cfg.Stderr = writer
} else if s.Debug {
stdErrStreamer := NewLoggerStreamer(s.Logger)
defer stdErrStreamer.Close()
Expand Down

0 comments on commit 9e398d0

Please sign in to comment.