Skip to content

Make trace command logging truncation configurable via PREK_LOG_TRUNCATE_LIMIT#1679

Merged
j178 merged 5 commits intomasterfrom
copilot/fix-truncated-trace-logs
Feb 20, 2026
Merged

Make trace command logging truncation configurable via PREK_LOG_TRUNCATE_LIMIT#1679
j178 merged 5 commits intomasterfrom
copilot/fix-truncated-trace-logs

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Trace-level Executing ... lines currently truncate command arguments at a hardcoded 120 characters, which hides critical details when debugging hooks (notably docker_image entrypoint/args). This change introduces a configurable truncate limit while preserving existing default behavior.

  • Config surface: new env var

    • Added PREK_LOG_TRUNCATE_LIMIT to prek-consts (EnvVars).
  • Runtime behavior in command logging

    • Updated Cmd display formatting in crates/prek/src/process.rs to read truncation limit from PREK_LOG_TRUNCATE_LIMIT.
    • Cached the resolved truncate limit with LazyLock so env parsing happens once.
    • Kept default at 120 when unset/invalid.
    • Treated 0 as invalid and fallback to default to avoid degenerate output.
  • Documentation

    • Added PREK_LOG_TRUNCATE_LIMIT to docs/configuration.md under environment variables, including default and intent.
  • Focused unit coverage

    • Added tests for:
      • env var value parsing (valid/invalid/zero),
      • env-based resolution behavior,
      • cached-limit behavior via LazyLock,
      • env restoration guard to avoid cross-test env leakage.
const DEFAULT_COMMAND_LOG_TRUNCATE_LIMIT: usize = 120;
static COMMAND_LOG_TRUNCATE_LIMIT: LazyLock<usize> =
    LazyLock::new(command_log_truncate_limit_from_env);

fn command_log_truncate_limit() -> usize {
    *COMMAND_LOG_TRUNCATE_LIMIT
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Do not truncate trace run executions</issue_title>
<issue_description>### Summary

I was trying to debug a docker_image hook execution and was delighted to note the --log-file option.

However, turns out that the "Executing" TRACE run lines are truncated with [...] before showing the part I'm actually interested in (a case of tweaking entrypoints and arguments).

I'd suggest not truncating these lines in the trace log at all, or providing an option not to truncate.

Willing to submit a PR?

  • Yes — I’m willing to open a PR to fix this.

Platform

Ubuntu 25.10 amd64

Version

0.3.2

.pre-commit-config.yaml

N/A

Log file

2026-02-20T10:17:47.223740Z TRACE run{hook_id=... language=docker_image}: Executing `cd ... && docker run --rm --tty --user 1000:1000 --init --volume ...:/src:rw,Z --workdir /src --entrypoint ... --network [...]`
```</issue_description>

<agent_instructions>Add a new env var to prek-consts, controlling the command line log truncate limit in process.rs, current it is hardcoded to 120. Document it in docs/configuration.md env vars section.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Fix truncated TRACE run execution logs Make trace command logging truncation configurable via env var Feb 20, 2026
Copilot AI requested a review from j178 February 20, 2026 11:01
@j178
Copy link
Owner

j178 commented Feb 20, 2026

@copilot Make the env var name more concise, for example, drop the COMMAND part, try better. Cache the result in a LazyLock.

Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot Make the env var name more concise, for example, drop the COMMAND part, try better. Cache the result in a LazyLock.

Updated in c1d6713: renamed the env var to PREK_LOG_TRUNCATE_LIMIT and cached the resolved truncate limit with a module-level LazyLock in process.rs. Also updated docs/tests to match.

@j178 j178 marked this pull request as ready for review February 20, 2026 12:46
Copilot AI review requested due to automatic review settings February 20, 2026 12:46
@j178 j178 changed the title Make trace command logging truncation configurable via env var Make trace command logging truncation configurable via PREK_LOG_TRUNCATE_LIMIT Feb 20, 2026
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.64%. Comparing base (8420c6e) to head (1b99f3c).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1679   +/-   ##
=======================================
  Coverage   91.64%   91.64%           
=======================================
  Files          96       96           
  Lines       18662    18669    +7     
=======================================
+ Hits        17102    17109    +7     
  Misses       1560     1560           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j178 j178 merged commit 8c92699 into master Feb 20, 2026
51 checks passed
@j178 j178 deleted the copilot/fix-truncated-trace-logs branch February 20, 2026 12:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a user-configurable truncation limit for trace-level command logging (Executing ...) via a new environment variable, improving debuggability for long command lines (e.g., container entrypoints/args) while keeping the existing default behavior.

Changes:

  • Introduces PREK_LOG_TRUNCATE_LIMIT in prek-consts env var definitions.
  • Updates Cmd display formatting to use an env-configurable truncate threshold (cached via LazyLock).
  • Documents the new env var in docs/configuration.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
docs/configuration.md Documents PREK_LOG_TRUNCATE_LIMIT in the environment variables list.
crates/prek/src/process.rs Reads and caches truncate limit from PREK_LOG_TRUNCATE_LIMIT and applies it when formatting Executing ... trace lines.
crates/prek-consts/src/env_vars.rs Adds the new PREK_LOG_TRUNCATE_LIMIT constant to EnvVars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not truncate trace run executions

3 participants