Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json structured logs #5784

Merged
merged 31 commits into from
Jan 9, 2024
Merged

Json structured logs #5784

merged 31 commits into from
Jan 9, 2024

Conversation

loocapro
Copy link
Contributor

@loocapro loocapro commented Dec 15, 2023

Related to: #5726.

I tried to resume all the functionalities that were a bit spread between bin/reth/src/cli/mod.rs and crates/tracing/src/lib.rs into a single component defined in crates/tracing/src/tracer.rs.

Basic usage for a json stdout tracer would be:

Tracer::new().with_stdout(LayerInfo::new(
    LogFormat::Json,
    "debug".to_string(),
    LevelFilter::INFO.into(),
    None,
));

If no layer is configured it defaults to:

impl Default for LayerInfo {
    /// Provides default values for `LayerInfo`.
    ///
    /// By default, it uses terminal format, INFO level filter,
    /// no additional filters, and no color configuration.
    fn default() -> Self {
        Self {
            format: LogFormat::Terminal,
            directive: LevelFilter::INFO.into(),
            filters: "debug".to_string(),
            color: None,
        }
    }
}

I am a bit confused on why we use log.filter and log.verbosity as cli args.

So i have included them both in the LayerInfo, but i feel like since a directive is a rule derived from a filter, I can probably get rid of one of them.

LFF (looking for feedback!) please.

CC: @shekhirin @mattsse

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this looks pretty good.

defer to @shekhirin and @onbjerg for a closer look

@mattsse
Copy link
Collaborator

mattsse commented Dec 21, 2023

friendly bump here @shekhirin @onbjerg

@shekhirin shekhirin self-requested a review December 21, 2023 12:59
Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

This looks great, just nits. Next step is integrating this into the existing logging configuration, right?

crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
@shekhirin
Copy link
Collaborator

I am a bit confused on why we use log.filter and log.verbosity as cli args.

verbosity is an easy way to display all logs for a certain level without messing with RUST_LOG

@loocapro
Copy link
Contributor Author

This looks great, just nits. Next step is integrating this into the existing logging configuration, right?

Great! Yep, I am going to proceed then!

@loocapro loocapro marked this pull request as ready for review December 24, 2023 17:43
@loocapro
Copy link
Contributor Author

Hi @shekhirin , I have managed to hook up all components.

I have also added a Tracer trait in order to standardise the init function and remove the init_test_tracing function and just have a TestTracer struct implementing the Tracer trait. If it's ok, i can proceed to replace every init_test_tracing with the TestTracer trait.

@loocapro
Copy link
Contributor Author

loocapro commented Jan 1, 2024

Hi @shekhirin gently bump here. I have managed to sync the code with latest main.

I have removed the TestTracer and just left the init_test_tracing function since it required a bit of changes around a lot of tests, but tell me if you want i can just do it.

I am a bit worried with dealing with more merge conflicts, so help me out here 😊

@mattsse mattsse requested a review from shekhirin January 2, 2024 12:26
@mattsse
Copy link
Collaborator

mattsse commented Jan 2, 2024

ah sorry about the conflicts, we should have included this much sooner.

ptal @shekhirin

Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

some questions on the API and overall simplification

bin/reth/src/args/log_args.rs Outdated Show resolved Hide resolved
bin/reth/src/args/log_args.rs Outdated Show resolved Hide resolved
bin/reth/src/args/log_args.rs Outdated Show resolved Hide resolved
bin/reth/src/args/log_args.rs Outdated Show resolved Hide resolved
crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
crates/tracing/src/lib.rs Outdated Show resolved Hide resolved
crates/tracing/src/lib.rs Outdated Show resolved Hide resolved
crates/tracing/src/lib.rs Show resolved Hide resolved
crates/tracing/src/lib.rs Show resolved Hide resolved
loocapro and others added 10 commits January 3, 2024 16:39
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
@loocapro
Copy link
Contributor Author

loocapro commented Jan 4, 2024

Hi @shekhirin ,

all review comments are resolved.

Keep in mind there is a slightly different behaviour than what it was before:

I have added log_stdout_filter cli arg which defaults to"info". Before the stdout EnvFilter was configured from the RUST_LOG env var and the verbosity cli arg.

Also the verbosity cli arg is only being used by the stdout layer.

Let me know if we can finally merge this.

Thanks a lot!!

@mattsse mattsse added A-observability Related to tracing, metrics, logs and other observability tools A-cli Related to the reth CLI labels Jan 8, 2024
crates/tracing/src/lib.rs Outdated Show resolved Hide resolved
crates/tracing/src/layers.rs Outdated Show resolved Hide resolved
@mattsse
Copy link
Collaborator

mattsse commented Jan 8, 2024

good to merge @shekhirin ?

@shekhirin
Copy link
Collaborator

@mattsse testing rn

@shekhirin shekhirin added the C-enhancement New feature or request label Jan 9, 2024
Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

LGTM, works as expected! Thank you for addressing all the review comments 😄

@shekhirin shekhirin added this pull request to the merge queue Jan 9, 2024
@shekhirin
Copy link
Collaborator

We will also need to change the CLI documentation in the book, and integrate the tracer into tests with the new RethTracer trait.

@loocapro
Copy link
Contributor Author

loocapro commented Jan 9, 2024

LGTM, works as expected! Thank you for addressing all the review comments 😄

Thank you for your reviews!

We will also need to change the CLI documentation in the book, and integrate the tracer into tests with the new RethTracer trait.

I can take care of it.

Merged via the queue into paradigmxyz:main with commit 8078c51 Jan 9, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Related to the reth CLI A-observability Related to tracing, metrics, logs and other observability tools C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants