Skip to content

fix(cli): wire --debug flag to logger level #499

Merged
y1yang0 merged 1 commit into
open-telemetry:mainfrom
beep-boopp:fix/wire-debug-flag
May 18, 2026
Merged

fix(cli): wire --debug flag to logger level #499
y1yang0 merged 1 commit into
open-telemetry:mainfrom
beep-boopp:fix/wire-debug-flag

Conversation

@beep-boopp
Copy link
Copy Markdown
Contributor

@beep-boopp beep-boopp commented May 13, 2026

Description

The --debug flag is defined in the CLI but initLogger never reads it — the log level is hardcoded to slog.LevelInfo regardless. This means all Debug() calls across setup and instrument phases are silently filtered out.

This wires cmd.Bool("debug") to set slog.LevelDebug when the flag is active, Debug output goes to debug.log in the work directory, consistent with existing logging behavior.

Motivation

The flag has never actually worked, it was introduced in #50 as "-debug" (triple dash), #281 fixed the typo but the wiring to the logger was never added. There are 13 existing Debug() calls across the codebase that are currently unreachable.

Fixes #497


Checklist

  • PR title follows conventional commits format
  • Code formatted: make format
  • Linters pass: make lint
  • Tests pass: make test
  • Tests added for new functionality
  • Tests follow testing guidelines
  • Documentation updated (if applicable)

@beep-boopp beep-boopp requested a review from a team as a code owner May 13, 2026 07:44
@github-actions github-actions Bot added the scope:fix A bug that is being fixed label May 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.13%. Comparing base (08d86e9) to head (ba88777).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tool/cmd/main.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #499      +/-   ##
==========================================
+ Coverage   62.83%   63.13%   +0.29%     
==========================================
  Files          62       62              
  Lines        4765     4771       +6     
==========================================
+ Hits         2994     3012      +18     
+ Misses       1527     1509      -18     
- Partials      244      250       +6     
Flag Coverage Δ
tool 63.13% <62.50%> (+0.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Comment thread tool/cmd/main.go
@beep-boopp beep-boopp force-pushed the fix/wire-debug-flag branch from 21b72c3 to a7bcc12 Compare May 13, 2026 09:07
@beep-boopp
Copy link
Copy Markdown
Contributor Author

Hey @y1yang0 just a heads up with the stderr tee, --debug surfaces a pretty verbose existing log in find.go:122 that dumps the full build plan as a single field. Makes the terminal output noisy. Should I drop the stderr tee and keep this to just the level fix, or is the tee worth keeping?

@y1yang0
Copy link
Copy Markdown
Contributor

y1yang0 commented May 13, 2026

I prefer keeping it as the fix only

@beep-boopp beep-boopp force-pushed the fix/wire-debug-flag branch from a7bcc12 to 82e02e7 Compare May 13, 2026 12:26
Comment thread tool/cmd/main.go
@beep-boopp beep-boopp force-pushed the fix/wire-debug-flag branch from 82e02e7 to 52c8498 Compare May 13, 2026 13:03
@beep-boopp
Copy link
Copy Markdown
Contributor Author

beep-boopp commented May 14, 2026

I have added Sources: cli.EnvVars(...) and simplified the os.Getenv check. Integration test failure is a pre-existing timeout on Windows (same 600s timeout reproduces on main without my changes, tested that locally).

Copy link
Copy Markdown
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

This PR wires the CLI --debug flag into logger level selection and adds an environment variable path so child toolexec invocations can inherit debug logging.

Changes:

  • Adds OTELC_DEBUG as a shared environment variable constant.
  • Sources the --debug flag from OTELC_DEBUG.
  • Sets slog.LevelDebug and exports OTELC_DEBUG=1 when debug mode is enabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tool/util/shared.go Adds the shared OTELC_DEBUG environment variable constant.
tool/cmd/main.go Reads the debug flag/env source and uses it to configure logger level and child process propagation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tool/cmd/main.go
@beep-boopp beep-boopp changed the title fix(cli): wire --debug flag to logger level and tee to stderr fix(cli): wire --debug flag to logger level May 14, 2026
@beep-boopp
Copy link
Copy Markdown
Contributor Author

Hey @y1yang0 all review feedback has been addressed, PTAL when you have the time thank you.

@y1yang0
Copy link
Copy Markdown
Contributor

y1yang0 commented May 15, 2026

Please fix test failure

@beep-boopp beep-boopp force-pushed the fix/wire-debug-flag branch from 52c8498 to c41ce1d Compare May 15, 2026 10:46
@beep-boopp beep-boopp force-pushed the fix/wire-debug-flag branch from c41ce1d to ba88777 Compare May 15, 2026 11:17
@beep-boopp
Copy link
Copy Markdown
Contributor Author

Hey @y1yang0 so i added unit tests for initLogger covering default level, debug flag , env var propagation and cli.envVars sourcing. Remaining codecov gap is error return paths....that i cant trigger without mocking stdlib but atleast integration tests are passing now.

do let me know if any changes are to be made....

@y1yang0 y1yang0 merged commit 33a6d74 into open-telemetry:main May 18, 2026
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:fix A bug that is being fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--debug flag defined but never wired to logger level

3 participants