Skip to content

feat(tracing): migrate logging to tracing#1308

Open
ognis1205 wants to merge 17 commits intoorhun:mainfrom
ognis1205:feat/migrate-to-tracing
Open

feat(tracing): migrate logging to tracing#1308
ognis1205 wants to merge 17 commits intoorhun:mainfrom
ognis1205:feat/migrate-to-tracing

Conversation

@ognis1205
Copy link
Collaborator

@ognis1205 ognis1205 commented Nov 21, 2025

Description

This PR migrates the logging implementation from env_logger to tracing.

The migration preserves the existing log format while extending it to include span information, enabling more structured and contextual logging without changing the default user experience.

Motivation and Context

This change is motivated by the following discussion and issues:

The goal is to modernize git-cliff's logging infrastructure by adopting tracing, while maintaining backward compatibility and avoiding unnecessary complexity in the core crate.

What Has Changed

  • The logger has been updated to emit spans in a format consistent with the existing log output.
  • Span instrumentation is applied only to methods that affect the changelog generator's semantics (e.g. changelog, release, and commit processing).
  • git-cliff-core now depends on tracing behind a feature flag.
    • When the feature is disabled, the behavior is unchanged and only the existing log output is produced.
    • When the feature is enabled, spans are created and included in the output.
  • Remote metadata progress reporting has been fully migrated to a tracing-based implementation using tracing-indicatif.
  • The progress bar implementation is intentionally kept simple.
    • While richer progress reporting is possible with tracing, implementing such behavior cleanly would require API changes outside of git-cliff-core.
    • Given the current API design, this PR avoids introducing additional complexity and leaves room for future design discussions.

How Has This Been Tested?

  • Existing unit tests were run.
  • Logging output was verified manually.

Screenshots / Logs (if applicable)

N/A

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ognis1205 ognis1205 marked this pull request as draft November 21, 2025 19:32
@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 2.06186% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.41%. Comparing base (78003e2) to head (7f6b875).

Files with missing lines Patch % Lines
git-cliff/src/logger.rs 0.00% 73 Missing ⚠️
git-cliff-core/src/changelog.rs 0.00% 21 Missing ⚠️
git-cliff-core/src/commit.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1308      +/-   ##
==========================================
+ Coverage   47.40%   47.41%   +0.01%     
==========================================
  Files          24       25       +1     
  Lines        2131     2135       +4     
==========================================
+ Hits         1010     1012       +2     
- Misses       1121     1123       +2     
Flag Coverage Δ
unit-tests 47.41% <2.07%> (+0.01%) ⬆️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@orhun
Copy link
Owner

orhun commented Nov 21, 2025

10 seconds ago I was happy that my GitHub notifications were clear and then Shingo comes in with a crazy PR!!!!!

+0 additions -0 deletions though. Love it. LGTM

@orhun orhun added this to the 2.12.0 milestone Dec 14, 2025
@orhun
Copy link
Owner

orhun commented Dec 14, 2025

planning to do any progress on this soon? (added to 2.12.0 milestone)

@ognis1205
Copy link
Collaborator Author

planning to do any progress on this soon? (added to 2.12.0 milestone)

Yeah, I'm planning to open a PR later this week.
Does that timeline work for the 2.12.0 milestone?

@orhun
Copy link
Owner

orhun commented Dec 15, 2025

yup, 2.12.0 will happen in 2026 :)
so we have a whole year!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@ognis1205
Copy link
Collaborator Author

Sorry for the delay. I'll start working on this PR today.

@orhun
Copy link
Owner

orhun commented Dec 20, 2025

No worries at all!

@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch from 5bb0f7b to f6b930d Compare December 20, 2025 21:30
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch from f6b930d to b273940 Compare January 3, 2026 19:54
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch from b273940 to b1e9f80 Compare January 12, 2026 17:02
@ognis1205 ognis1205 marked this pull request as ready for review January 13, 2026 13:44
@ognis1205 ognis1205 requested a review from orhun as a code owner January 13, 2026 13:44
@ognis1205
Copy link
Collaborator Author

This is ready for review now @orhun .

I consider this a first draft, and there are likely areas open for discussion. When you have time, I'd really appreciate your thoughts and feedback.

ognis1205

This comment was marked as resolved.

@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch 2 times, most recently from 75b4d8d to b53b100 Compare January 16, 2026 12:36
static MAX_MODULE_WIDTH: AtomicUsize = AtomicUsize::new(0);

/// Unicode braille spinner frames used by indicatif.
const SPINNER_TICKS: &[&str] = &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
Copy link
Owner

Choose a reason for hiding this comment

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

Would be great if we could keep the old arrow-styled progress indicator (for the first line in the logs at least)

I really like the detailed logging btw!

Let me know when this is ready for review

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would be great if we could keep the old arrow-styled progress indicator (for the first line in the logs at least)

That should be doable.

We can bring back the old arrow-style progress indicator, but when implemented on top of tracing / span-based instrumentation via tracing-indicatif, it would look slightly different from the previous approach:

Screenshot 2026-01-18 at 16 45 03 Screenshot 2026-01-18 at 16 45 27 Screenshot 2026-01-18 at 16 46 34 Screenshot 2026-01-18 at 16 46 57

If that's acceptable, I'm happy to revert the change accordingly. In addition to the progress indicator itself, we can of course also emit explicit logs at the beginning and end of the processing step.

In an ideal world, I'd like to include a progress indicator with percentages as well. However, with the current design, where spans and logging live inside the core SDK, that starts to get a bit messy from a design perspective. It's technically possible, but I intentionally avoided it for now to keep the core clean.

Let me know when this is ready for review

Regarding ANSI/ASCII color codes on Windows or non-TTY environments: since we were already using colored output before, I think it's reasonable to review this as-is for now.

If you're open to it, I'd really appreciate review feedback on the following points in the context of adding this to git-cliff-core as an SDK:

  • Which functions should be annotated with #[instrument] (all vs. a subset)
  • Whether span names should be explicitly set
  • Which fields are appropriate to capture on spans

From a "keep git-cliff-core as a clean SDK" perspective, another option could be to explore whether progress reporting can be handled in a less hacky way on top of env_logger, if that's feasible. Just putting it out there as an alternative.

@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch 5 times, most recently from 59d45cd to 4abd838 Compare January 25, 2026 14:48
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch from 4abd838 to e003355 Compare February 15, 2026 17:58
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch 5 times, most recently from 3a03774 to d86b39e Compare March 2, 2026 13:56
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch 3 times, most recently from 6bf6f42 to c665d67 Compare March 12, 2026 17:27
Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

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

I like how this turned out!

Some points of discussion:

  • The spinner gets red quickly I think. Wouldn't be nice to adjust the timing there?
  • The main spinner messages seem developer oriented now. Previously, it was something like "fetching data from GitHub..." but now it says things like add_remote_data, get_github_metadata and so on. I know git-cliff is mostly directed at developers, but I still think that we could avoid programmatic-looking info-level messages. Wdyt?

@ognis1205
Copy link
Collaborator Author

Thanks for the feedback!

  • The spinner gets red quickly I think. Wouldn't be nice to adjust the timing there?

No objections here. I agree it turns red a bit too quickly. I'll slow down the timing so the transition happens later.

  • The main spinner messages seem developer oriented now. Previously, it was something like "fetching data from GitHub..." but now it says things like add_remote_data, get_github_metadata and so on. I know git-cliff is mostly directed at developers, but I still think that we could avoid programmatic-looking info-level messages. Wdyt?

There is actually a reason for the current behavior. Since I implemented using tracing-indicatif, most of the macros ended up being defined in the git-cliff-core side. Because that crate also has an SDK role, I intentionally avoided defining end-user-facing messages there and instead exposed the function names directly.

That said, I don't have any objection to making the messages more human-readable. In the future, when we have a chance to refactor, I'd like to explore the idea of making git-cliff-core more "log-less" and keeping user-facing messaging closer to the CLI layer.

For now, I agree with your point and will update the messages to be more readable.

@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch 2 times, most recently from fdc3100 to b17faa0 Compare March 23, 2026 05:36
@ognis1205
Copy link
Collaborator Author

  • The spinner gets red quickly I think. Wouldn't be nice to adjust the timing there?

No objections here. I agree it turns red a bit too quickly. I'll slow down the timing so the transition happens later.

Updated the timing so that the transition now occurs after 32 seconds (8 seconds previously), making the progress display less abrupt.

  • The main spinner messages seem developer oriented now. Previously, it was something like "fetching data from GitHub..." but now it says things like add_remote_data, get_github_metadata and so on. I know git-cliff is mostly directed at developers, but I still think that we could avoid programmatic-looking info-level messages. Wdyt?

There is actually a reason for the current behavior. Since I implemented using tracing-indicatif, most of the macros ended up being defined in the git-cliff-core side. Because that crate also has an SDK role, I intentionally avoided defining end-user-facing messages there and instead exposed the function names directly.

That said, I don't have any objection to making the messages more human-readable. In the future, when we have a chance to refactor, I'd like to explore the idea of making git-cliff-core more "log-less" and keeping user-facing messaging closer to the CLI layer.

For now, I agree with your point and will update the messages to be more readable.

Implemented a macro to output non-developer friendly progress messages in tracing spans.
Previously, messages were developer-oriented. Now, the macro allows progress updates to display user-friendly text while still working with the tracing-indicatif integration.

@ognis1205 ognis1205 requested a review from orhun March 23, 2026 09:52
Signed-off-by: Shingo OKAWA <[email protected]>
Signed-off-by: Shingo OKAWA <[email protected]>
Signed-off-by: Shingo OKAWA <[email protected]>
@ognis1205 ognis1205 force-pushed the feat/migrate-to-tracing branch from a50976a to 7f6b875 Compare March 23, 2026 16:45
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.

3 participants