diff --git a/internal/k6runner/local.go b/internal/k6runner/local.go index 5fa853e14..e04c332ad 100644 --- a/internal/k6runner/local.go +++ b/internal/k6runner/local.go @@ -36,8 +36,6 @@ func (r Local) WithLogger(logger *zerolog.Logger) Runner { } func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) (*RunResponse, error) { - logger := r.logger.With().Object("checkInfo", &script.CheckInfo).Logger() - afs := afero.Afero{Fs: r.fs} checkTimeout := time.Duration(script.Settings.Timeout) * time.Millisecond @@ -52,7 +50,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) defer func() { if err := r.fs.RemoveAll(workdir); err != nil { - logger.Error().Err(err).Str("severity", "critical").Msg("cannot remove temporary directory") + r.logger.Error().Err(err).Str("severity", "critical").Msg("cannot remove temporary directory") } }() @@ -93,7 +91,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) } defer cleanup() - logger.Debug(). + r.logger.Debug(). Str("secret_config_file", configFile). Str("secrets_url", secretStore.Url). Msg("Using secret config file") @@ -119,7 +117,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) cmd.Env = k6Env(os.Environ()) start := time.Now() - logger.Info().Str("command", cmd.String()).Msg("running k6 script") + r.logger.Info().Str("command", cmd.String()).Msg("running k6 script") err = cmd.Run() duration := time.Since(start) @@ -129,7 +127,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) err = errors.Join(err, ctx.Err()) if err != nil && !isUserError(err) { - logger.Error(). + r.logger.Error(). Err(err). Dur("duration", duration). Msg("cannot run k6") @@ -157,7 +155,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) return nil, fmt.Errorf("reading k6 logs: %w", err) } if truncated { - logger.Warn(). + r.logger.Warn(). Str("filename", logsFn). Int("limitBytes", maxLogsSizeBytes). Msg("Logs output larger than limit, truncating") @@ -171,7 +169,7 @@ func (r Local) Run(ctx context.Context, script Script, secretStore SecretStore) return nil, fmt.Errorf("reading k6 metrics: %w", err) } if truncated { - logger.Warn(). + r.logger.Warn(). Str("filename", metricsFn). Int("limitBytes", maxMetricsSizeBytes). Msg("Metrics output larger than limit, truncating") diff --git a/internal/prober/browser/browser.go b/internal/prober/browser/browser.go index abfba4ba0..b04f1b075 100644 --- a/internal/prober/browser/browser.go +++ b/internal/prober/browser/browser.go @@ -66,13 +66,13 @@ func (p Prober) Name() string { func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) { secretStore, err := p.secretsRetriever(ctx) - if err != nil { p.logger.Error().Err(err).Msg("running probe") return false, 0 } - success, err := p.processor.Run(ctx, registry, logger, p.logger, secretStore) + runLogger := p.logger.With().Object("checkInfo", &p.module.Script.CheckInfo).Logger() + success, err := p.processor.Run(ctx, registry, logger, runLogger, secretStore) if err != nil { p.logger.Error().Err(err).Msg("running probe") return false, 0 diff --git a/internal/prober/multihttp/multihttp.go b/internal/prober/multihttp/multihttp.go index 87ac9abe4..ffa6b6ef6 100644 --- a/internal/prober/multihttp/multihttp.go +++ b/internal/prober/multihttp/multihttp.go @@ -89,13 +89,13 @@ func (p Prober) Name() string { func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.Registry, logger logger.Logger) (bool, float64) { secretStore, err := p.secretsRetriever(ctx) - if err != nil { p.logger.Error().Err(err).Msg("running probe") return false, 0 } - success, err := p.processor.Run(ctx, registry, logger, p.logger, secretStore) + runLogger := p.logger.With().Object("checkInfo", &p.module.Script.CheckInfo).Logger() + success, err := p.processor.Run(ctx, registry, logger, runLogger, secretStore) if err != nil { p.logger.Error().Err(err).Msg("running probe") return false, 0 diff --git a/internal/prober/scripted/scripted.go b/internal/prober/scripted/scripted.go index 3712bad84..62dba6218 100644 --- a/internal/prober/scripted/scripted.go +++ b/internal/prober/scripted/scripted.go @@ -71,7 +71,8 @@ func (p Prober) Probe(ctx context.Context, target string, registry *prometheus.R return false, 0 } - success, err := p.processor.Run(ctx, registry, logger, p.logger, secretStore) + runLogger := p.logger.With().Object("checkInfo", &p.module.Script.CheckInfo).Logger() + success, err := p.processor.Run(ctx, registry, logger, runLogger, secretStore) if err != nil { p.logger.Error().Err(err).Msg("running probe") return false, 0