Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add tracing logic in pallet macro for hooks and dispatchables #8305

Merged
merged 7 commits into from
Mar 23, 2021

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Mar 9, 2021

Fix #8303

decl_module add some tracing logic. This tracing is now also expanded in pallet macro.

Note that the tracing slightly differ between dispatchables from decl_module as the logic of the dispatchable function is not changed in the pallet macro.
Instead the trace is entered in the UnfilteredDispatch implementation (which is the implementation called when dispatching an extrinsic)

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Mar 9, 2021
@gui1117 gui1117 added B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Mar 9, 2021
@gui1117 gui1117 changed the title Add tracing logic in pallet macro for hooks Add tracing logic in pallet macro for hooks and dispatchables Mar 9, 2021
@emostov
Copy link
Contributor

emostov commented Mar 9, 2021

Does it make sense to add some tests to show how the traces in the new macro compare with the old macro?

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Test would be nice, but since I think we can and should drop support for decl_ in the next release, fine without it as well.

@dvdplm
Copy link
Contributor

dvdplm commented Mar 10, 2021

cc @insipx

@bkchr
Copy link
Member

bkchr commented Mar 10, 2021

Test would be nice, but since I think we can and should drop support for decl_ in the next release, fine without it as well.

If someone is relying on this stuff, we need a test for this.

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 10, 2021

I can't find any test for now, I think I can do something similar to https://github.com/paritytech/substrate/blob/master/primitives/api/test/tests/runtime_calls.rs#L220
Is there a more simple way to check the trace in tests ? like by initializing tracing_subscriber in some way which writes to some local vec instead of stderr ?

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 10, 2021

I agree that test should be better but considering decl_module doesn't test them either, I think it can be move to another PR/issue: paritytech/polkadot-sdk#333

@bkchr
Copy link
Member

bkchr commented Mar 10, 2021

like by initializing tracing_subscriber in some way which writes to some local vec instead of stderr ?

Yeah that also works.

But the issue is okay for now.

@emostov
Copy link
Contributor

emostov commented Mar 11, 2021

Just wanted to document here a difference with the spans from old vs new macro I noticed:

2021-03-11 11:30:24.833  TRACE tokio-runtime-worker sc_tracing: pallet_timestamp::pallet: on_initialize, time: 7194, id: 38281146588463105, parent_id: None    
2021-03-11 11:30:24.833  TRACE tokio-runtime-worker sc_tracing: pallet_babe: on_initialize, time: 43113, id: 40532946402148353, parent_id: None

new macro targets: pallet_{{pallet name}}::pallet
old macro targets: pallet_{{pallet name}}

Guillaume mentioned offline using something like

<T::PalletInfo as frame_support::traits::PalletInfo>::name::<#pallet_ident<#type_use_gen>>()

to see if that gets the correct target name. I am going to give that a go.

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 11, 2021

if need the pallet name better to trace it explicitly instead of just tracing: on_initialize.
the new macro define the function in the module pallet that's why it is written in the tracing.

@shawntabrizi
Copy link
Member

I am out of the loop on who is relying on these traces and why we need tests?

I mean tests are great, but are people taking a dependency on trace information to trigger some workflows?

@emostov
Copy link
Contributor

emostov commented Mar 15, 2021

I am out of the loop on who is relying on these traces and why we need tests?

@shawntabrizi As of now, the current designs for balance reconciliation (and general state change auditing) rely on tracking DB read/writes via traces. A fragile approach, but it is the current approach.

Also to follow up on my earlier comments, I am happy with this PR as is. Tests are nice but given the current status quo I don't think they should be a blocker.
As discussed offline with @dvdplm, @insipix - there may be merit in adding the instantiated pallets name (i.e. how it is named in the runtime) to the spans as values in order to correctly attribute events; however that is beyond the scope of this PR.

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

lgtm

frame/support/src/lib.rs Outdated Show resolved Hide resolved
@gui1117
Copy link
Contributor Author

gui1117 commented Mar 23, 2021

bot merge

@ghost
Copy link

ghost commented Mar 23, 2021

Waiting for commit status.

@gui1117 gui1117 added D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit A8-mergeoncegreen and removed A0-please_review Pull request needs code review. A7-needspolkadotpr labels Mar 23, 2021
@ghost
Copy link

ghost commented Mar 23, 2021

Checks failed; merge aborted.

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 23, 2021

bot merge

@ghost
Copy link

ghost commented Mar 23, 2021

Checks failed; merge aborted.

@gui1117 gui1117 merged commit 87cdfd3 into master Mar 23, 2021
@gui1117 gui1117 deleted the gui-span-hooks branch March 23, 2021 14:53
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
…tech#8305)

* span in hooks

* add span for dispatchable

* Update frame/support/src/lib.rs

* Update frame/support/src/lib.rs

Co-authored-by: David <dvdplm@gmail.com>

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: David <dvdplm@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traces for hooks not implemented
7 participants