diff --git a/agent/job_runner.go b/agent/job_runner.go index 2731afcf5e..eb851edc99 100644 --- a/agent/job_runner.go +++ b/agent/job_runner.go @@ -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 diff --git a/internal/job/shell/shell.go b/internal/job/shell/shell.go index 5bccac0fa9..ec73e306da 100644 --- a/internal/job/shell/shell.go +++ b/internal/job/shell/shell.go @@ -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 @@ -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() @@ -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()