Skip to content

Add tracing_debug feature to expose teach-me logging configuration#386

Open
Copilot wants to merge 5 commits intomainfrom
copilot/add-default-tracing-config
Open

Add tracing_debug feature to expose teach-me logging configuration#386
Copilot wants to merge 5 commits intomainfrom
copilot/add-default-tracing-config

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Summary: Add tracing_debug feature to cargo-near-build ✅

This PR successfully implements a new tracing_debug feature for cargo-near-build that provides a default tracing configuration enabling all --teach-me messages and detailed logging.

Changes Made:

  • Added tracing_debug feature flag to cargo-near-build/Cargo.toml
  • Added tracing-subscriber as an optional dependency (behind feature flag)
  • Created tracing_debug module with init_tracing_debug() function
  • Exported function in public API with proper documentation
  • Added comprehensive documentation to README
  • Addressed code review feedback (use try_init, add comments)
  • Removed useless tests per reviewer feedback
  • Manual security review completed

Security Summary:

No security vulnerabilities introduced. The changes only add logging configuration using trusted libraries (tracing-subscriber from the Tokio project). The code:

  • Contains no user input handling
  • Performs no file system or network operations
  • Uses standard environment variable reading for RUST_LOG
  • Properly handles errors with try_init() instead of panicking

Usage:

Users can now enable detailed build logging by adding the feature to their Cargo.toml:

[dependencies]
cargo-near-build = { version = "0.11", features = ["tracing_debug"] }

And initializing it in their code:

cargo_near_build::init_tracing_debug().expect("Failed to initialize tracing");

This provides the same verbose logging as cargo near --teach-me for debugging build scripts and custom tools.

Original prompt

This section details on the original issue you should resolve

<issue_title>cargo-near-build should have a default tracing config exported under tracing_debug feature</issue_title>
<issue_description>this should enable all --teach-me messages and stuff</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 14, 2026 00:17
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Copilot AI changed the title [WIP] Add default tracing config for cargo-near-build Add tracing_debug feature to expose teach-me logging configuration Jan 14, 2026
Copilot AI requested a review from r-near January 14, 2026 00:28
@r-near
Copy link
Contributor

r-near commented Jan 14, 2026

@copilot clean up the useless tests

Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot clean up the useless tests

Removed the test file and reverted integration-tests changes in commit 3a946d1.

@r-near r-near marked this pull request as ready for review January 14, 2026 01:18
@r-near r-near requested a review from a team as a code owner January 14, 2026 01:18
Copilot AI review requested due to automatic review settings January 14, 2026 01:18
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

This PR adds a tracing_debug feature flag to cargo-near-build that provides a default tracing subscriber configuration for debugging purposes. It enables all --teach-me messages and detailed logging output, matching the behavior of cargo near --teach-me.

Changes:

  • Added tracing_debug feature flag with optional tracing-subscriber dependency
  • Created new tracing_debug module with init_tracing_debug() function
  • Updated documentation in README and lib.rs to describe the new feature

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cargo-near-build/src/tracing_debug.rs New module providing tracing configuration with SimpleFormatter and env filter setup
cargo-near-build/src/lib.rs Exports the new init_tracing_debug function under the tracing_debug feature flag
cargo-near-build/Cargo.toml Adds tracing_debug feature and optional tracing-subscriber dependency
README.md Documents the new debugging feature with usage examples
Cargo.lock Updates dependency tree with tracing-subscriber

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

Comment on lines +78 to +81
.add_directive(Level::WARN.into())
.add_directive("near_teach_me=info".parse()?)
.add_directive("near_cli_rs=info".parse()?)
.add_directive("tracing_instrument=info".parse()?);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The filter directives are duplicated from cargo-near/src/lib.rs (lines 107-111). While the comment explains this is intentional to avoid dependencies, consider extracting the filter configuration string (e.g., 'near_teach_me=info,near_cli_rs=info,tracing_instrument=info,warn') to a shared constant in a common location to ensure consistency when updates are made.

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +74
struct SimpleFormatter;

impl<S, N> FormatEvent<S, N> for SimpleFormatter
where
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'a> FormatFields<'a> + 'static,
{
fn format_event(
&self,
ctx: &FmtContext<'_, S, N>,
mut writer: Writer<'_>,
event: &Event<'_>,
) -> std::fmt::Result {
let level = *event.metadata().level();
let (icon, color_code) = match level {
Level::TRACE => ("TRACE ", "\x1b[35m"), // Magenta
Level::DEBUG => ("DEBUG ", "\x1b[34m"), // Blue
Level::INFO => ("", ""), // Default
Level::WARN => ("Warning ", "\x1b[33m"), // Yellow
Level::ERROR => ("ERROR ", "\x1b[31m"), // Red
};

write!(writer, "{}├ {}", color_code, icon)?;
write!(writer, "\x1b[0m")?;

ctx.field_format().format_fields(writer.by_ref(), event)?;

writeln!(writer)
}
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The SimpleFormatter implementation is duplicated from cargo-near/src/lib.rs. While the comment at line 43-45 acknowledges this, this creates a maintenance burden where changes to formatting in one location must be manually replicated to the other. Consider extracting SimpleFormatter to a shared internal utility crate or module that both cargo-near and cargo-near-build can depend on, even if it's not part of the public API.

Copilot uses AI. Check for mistakes.
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.

cargo-near-build should have a default tracing config exported under tracing_debug feature

3 participants