Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

1892 tracing #1957

Merged
merged 8 commits into from Jan 29, 2020
Merged

1892 tracing #1957

merged 8 commits into from Jan 29, 2020

Conversation

tcharding
Copy link
Collaborator

Convert code base to use tokio-rs tracing library. With this applied (after running btc_eth/happy e2e test):

Jan 29 14:12:50.122  INFO cnd::trace: Initialized tracing with level: TRACE
Jan 29 14:12:50.122  INFO cnd::seed: RootSeed file parent directory does not exist, creating recursively: /tmp/tmp-125556e02qp5UNTGu/seed.pem
Jan 29 14:12:50.122  INFO cnd::seed: No seed file found, creating at: /tmp/tmp-125556e02qp5UNTGu/seed.pem
Jan 29 14:12:50.288  INFO cnd::db: SQLite database file: /tmp/tmp-125556e02qp5UNTGu/cnd.sqlite
Jan 29 14:12:50.290  INFO cnd::network: Starting with peer_id: QmafYkp7uHUj3FghWAbPZDbRTEFtJRdH3nQF5kXBYdXQYt
Jan 29 14:12:50.293 DEBUG cnd::load_swaps: loading swaps from database ...
Jan 29 14:12:50.295  INFO cnd: Starting HTTP server on 0.0.0.0:42789
Jan 29 14:12:53.583 TRACE cnd::http_api::routes::rfc003::handlers::post_swap: initiating new request: 932784b5-8ed9-47c1-8219-f216a9e0a017
Jan 29 14:12:53.589  INFO http: 127.0.0.1:39774 "POST /swaps/rfc003 HTTP/1.1" 201 "-" "axios/0.19.0" 39.353322ms    
Jan 29 14:12:53.589 DEBUG cnd::network: Making swap request to QmQskR8UngQvXfHrvrubAACkhQNVo4D2dPowjW81hWUxSu@/ip4/127.0.0.1/tcp/33085: SwapId(932784b5-8ed9-47c1-8219-f216a9e0a017)

And we get the same total number of log lines from running btc_eth/happy e2e test as before.

Fixes: #1892

Tobin C. Harding added 5 commits January 29, 2020 14:16
Add tracing, initialize a subscriber, log a single event
'tracing initialized'.
Use tracing library for all log events.  This is simply a matter of replacing
logging calls that use `log::foo` with `tracing::foo`.
We can convert all upstream logging events to use tracing and be
available for the default subscriber simply by using the line

	LogTracer::init()?;

Connect upstream libraries to tracing using LogTracer.
Convert the current logging configuration to configure tracing instead.
Now we have tracing convert the `libp2p-comit` crate to use it.
@mergify
Copy link
Contributor

mergify bot commented Jan 29, 2020

Are you sure the changelog does not need updating?

Clippy is emitting warnings that the cognitive complexity is to high.
Refactor the error variants into a separate function.  This actually
does not clear the warning but the code is cleaner anyways.  Add an
attribute to quieten Clippy to the newly created function.
cnd/src/trace.rs Outdated

fn level_from_level_filter(level: LevelFilter) -> Level {
match level {
LevelFilter::Off => Level::ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not respecting off? Could just not initialize anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, will implement.

cnd/src/main.rs Outdated
let base_log_level = settings.logging.level;
logging::initialize(base_log_level, settings.logging.structured)?;
// We still want upstream library log messages, just only at Info level.
LogTracer::init_with_filter(LevelFilter::Info)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would see this as part of the initialization, no?
Why add this level of detail to main?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, thanks. Implemented.

Tracing library at some times causes Clippy to emit a cognitive complexity
warning.  Issue raised on the tokio-rs/tracing repo

	tokio-rs/tracing#553

Add Clippy attributes to allow cognitive complexity where needed.
@tcharding tcharding added the no-mergify Stop mergify to merge this automatically label Jan 29, 2020
Some of the initialization is in main still, do it all within the init
function.  While we are at it, lets respect `LevelFilter::Off` to allow
tracing to be turned off.
@tcharding tcharding removed the no-mergify Stop mergify to merge this automatically label Jan 29, 2020
@tcharding
Copy link
Collaborator Author

bors r+

bors bot added a commit that referenced this pull request Jan 29, 2020
1957: 1892 tracing r=tcharding a=tcharding

Convert code base to use tokio-rs tracing library.  With this applied (after running btc_eth/happy e2e test):
```
Jan 29 14:12:50.122  INFO cnd::trace: Initialized tracing with level: TRACE
Jan 29 14:12:50.122  INFO cnd::seed: RootSeed file parent directory does not exist, creating recursively: /tmp/tmp-125556e02qp5UNTGu/seed.pem
Jan 29 14:12:50.122  INFO cnd::seed: No seed file found, creating at: /tmp/tmp-125556e02qp5UNTGu/seed.pem
Jan 29 14:12:50.288  INFO cnd::db: SQLite database file: /tmp/tmp-125556e02qp5UNTGu/cnd.sqlite
Jan 29 14:12:50.290  INFO cnd::network: Starting with peer_id: QmafYkp7uHUj3FghWAbPZDbRTEFtJRdH3nQF5kXBYdXQYt
Jan 29 14:12:50.293 DEBUG cnd::load_swaps: loading swaps from database ...
Jan 29 14:12:50.295  INFO cnd: Starting HTTP server on 0.0.0.0:42789
Jan 29 14:12:53.583 TRACE cnd::http_api::routes::rfc003::handlers::post_swap: initiating new request: 932784b5-8ed9-47c1-8219-f216a9e0a017
Jan 29 14:12:53.589  INFO http: 127.0.0.1:39774 "POST /swaps/rfc003 HTTP/1.1" 201 "-" "axios/0.19.0" 39.353322ms    
Jan 29 14:12:53.589 DEBUG cnd::network: Making swap request to QmQskR8UngQvXfHrvrubAACkhQNVo4D2dPowjW81hWUxSu@/ip4/127.0.0.1/tcp/33085: SwapId(932784b5-8ed9-47c1-8219-f216a9e0a017)
```

And we get the same total number of log lines from running btc_eth/happy e2e test as before.

Fixes: #1892

Co-authored-by: Tobin C. Harding <tobin.harding@coblox.tech>
@mergify
Copy link
Contributor

mergify bot commented Jan 29, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 29, 2020

Already running a review

@bors
Copy link
Contributor

bors bot commented Jan 29, 2020

Build succeeded

@bors bors bot merged commit 4e4a353 into master Jan 29, 2020
@mergify mergify bot deleted the 1892-tracing branch January 29, 2020 22:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement tracing
3 participants