Skip to content

Conversation

@SuperFluffy
Copy link
Contributor

@SuperFluffy SuperFluffy commented Dec 21, 2023

Summary

Add a custom lint using the dylint tool to detect and warn about debug-formatted fields in tracing events.

Background

Debug-formatted fields in tracing events are bad practice. They are hard to read and parse, and they surface language-specific implementation details that have no place in observability.

The present lint only acts on debug-formatted fields in tracing::event! macros (which includes macros like info! and warn! that are implemented in terms of it). Debug-formatted fields in #[instrument] proc macros will be detected in a separate lint.

Changes

  • Implement a custom lint using dylint that flags that debug-formatted fields in tracing::event! macros
  • Adds tests for the lint
  • Add a github job to run dylints (the lint failing does currently not fail CI)
  • Add a default-members field to the virtual workspace so that the lints are exempt from most CI jobs (the lints require a nightly rust)

Testing

This patch provides compiletest-rs macros that correctly detects debug-formatted fields in event macros and not in instrument-proc-macros.

@SuperFluffy SuperFluffy force-pushed the superfluffy/lint-trace-fields branch from 14dc0c4 to 69d4d52 Compare December 28, 2023 17:54
@github-actions github-actions bot added the ci issues that are related to ci and github workflows label Dec 28, 2023
@SuperFluffy SuperFluffy changed the title WIP: lint debug fields in tracing events feat(ci lint debug fields in tracing events Dec 28, 2023
@SuperFluffy SuperFluffy changed the title feat(ci lint debug fields in tracing events feat(ci): lint debug fields in tracing events Dec 28, 2023
@SuperFluffy SuperFluffy marked this pull request as ready for review December 28, 2023 19:36
@SuperFluffy SuperFluffy requested review from a team, joroshiba and noot as code owners December 28, 2023 19:36
Comment on lines +3 to +11
#[derive(Clone, Copy, Debug)]
struct Wrapped(&'static str);

fn main() {
let field = Wrapped("wrapped");
info!(field = tracing::field::debug(field), "using the function");
info!(field = ?field, "using the sigil");
info!(?field, "using shorthand with sigil");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this for? just testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this ui/main.rs produces some output when compiled. https://github.com/Manishearth/compiletest-rs then tests the output against ui/main.stderr.

This is to make sure that all the cases that I want the lint to catch are caught.

Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

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

looks good! the if_chain is cool :D

@SuperFluffy SuperFluffy force-pushed the superfluffy/lint-trace-fields branch from 3f36314 to 1054e81 Compare January 2, 2024 22:07
@SuperFluffy SuperFluffy merged commit 095b63b into main Jan 3, 2024
@SuperFluffy SuperFluffy deleted the superfluffy/lint-trace-fields branch January 3, 2024 11:58
SuperFluffy added a commit that referenced this pull request Jan 3, 2024
## Summary
Build images using a Cargo.toml without a default-members entry.

## Background
We use cargo-chef to prepare recipes for each individual binary so that
only its dependencies are built and cached. PR
#664 introduced the
`default-members` entry so that cargo invocations by default don't
target the lints (as they require a nightly compiler). But this breaks
cargo-chef because it leaves default-members intact, leading to cargo
compilation issues.

## Changes
- Create a special `containerfiles/Cargo.toml` file that is derived from
the root `Cargo.toml` but with its `default-members` entry removed
- Update `containerfiles/Dockerfile` to run `cargo chef prepare` against
`containerfiles/Cargo.toml`
- Add a just entry to remove `workspace.default-members` from
`Cargo.toml`, format it with `taplo`, and write it to
`containerfiles/Cargo.toml`
- Add a github job that ensures that `containerfiles/Cargo.toml` is in
sync with `Cargo.toml`

## Testing
- Docker builds were broken and now work again (verified by building
locally and in CI)
- Commited a modified `containerfiles/Cargo.toml` and observed the
github action trigger

## Related Issues
PR causing the build to break:
#664
sgranfield4403-3 added a commit to sgranfield4403-3/astria that referenced this pull request Oct 2, 2025
## Summary
Build images using a Cargo.toml without a default-members entry.

## Background
We use cargo-chef to prepare recipes for each individual binary so that
only its dependencies are built and cached. PR
astriaorg/astria#664 introduced the
`default-members` entry so that cargo invocations by default don't
target the lints (as they require a nightly compiler). But this breaks
cargo-chef because it leaves default-members intact, leading to cargo
compilation issues.

## Changes
- Create a special `containerfiles/Cargo.toml` file that is derived from
the root `Cargo.toml` but with its `default-members` entry removed
- Update `containerfiles/Dockerfile` to run `cargo chef prepare` against
`containerfiles/Cargo.toml`
- Add a just entry to remove `workspace.default-members` from
`Cargo.toml`, format it with `taplo`, and write it to
`containerfiles/Cargo.toml`
- Add a github job that ensures that `containerfiles/Cargo.toml` is in
sync with `Cargo.toml`

## Testing
- Docker builds were broken and now work again (verified by building
locally and in CI)
- Commited a modified `containerfiles/Cargo.toml` and observed the
github action trigger

## Related Issues
PR causing the build to break:
astriaorg/astria#664
AngieD101 added a commit to AngieD101/astria that referenced this pull request Oct 10, 2025
## Summary
Build images using a Cargo.toml without a default-members entry.

## Background
We use cargo-chef to prepare recipes for each individual binary so that
only its dependencies are built and cached. PR
astriaorg/astria#664 introduced the
`default-members` entry so that cargo invocations by default don't
target the lints (as they require a nightly compiler). But this breaks
cargo-chef because it leaves default-members intact, leading to cargo
compilation issues.

## Changes
- Create a special `containerfiles/Cargo.toml` file that is derived from
the root `Cargo.toml` but with its `default-members` entry removed
- Update `containerfiles/Dockerfile` to run `cargo chef prepare` against
`containerfiles/Cargo.toml`
- Add a just entry to remove `workspace.default-members` from
`Cargo.toml`, format it with `taplo`, and write it to
`containerfiles/Cargo.toml`
- Add a github job that ensures that `containerfiles/Cargo.toml` is in
sync with `Cargo.toml`

## Testing
- Docker builds were broken and now work again (verified by building
locally and in CI)
- Commited a modified `containerfiles/Cargo.toml` and observed the
github action trigger

## Related Issues
PR causing the build to break:
astriaorg/astria#664
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci issues that are related to ci and github workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants