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

Commit

Permalink
Add tracing logic in pallet macro for hooks and dispatchables (#8305)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Mar 23, 2021
1 parent 36d77bc commit 87cdfd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions frame/support/procedural/src/pallet/expand/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
) -> #frame_support::dispatch::DispatchResultWithPostInfo {
match self {
#(
Self::#fn_name( #( #args_name, )* ) =>
Self::#fn_name( #( #args_name, )* ) => {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!(stringify!(#fn_name))
);
<#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* )
.map(Into::into).map_err(Into::into),
.map(Into::into).map_err(Into::into)
},
)*
Self::__Ignore(_, _) => {
let _ = origin; // Use origin for empty Call enum
Expand Down
10 changes: 10 additions & 0 deletions frame/support/procedural/src/pallet/expand/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
for #pallet_ident<#type_use_gen> #where_clause
{
fn on_finalize(n: <T as #frame_system::Config>::BlockNumber) {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_finalize")
);
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
Expand Down Expand Up @@ -86,6 +89,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
fn on_initialize(
n: <T as #frame_system::Config>::BlockNumber
) -> #frame_support::weights::Weight {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_initialize")
);
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
Expand All @@ -99,6 +105,10 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
for #pallet_ident<#type_use_gen> #where_clause
{
fn on_runtime_upgrade() -> #frame_support::weights::Weight {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_runtime_update")
);

// log info about the upgrade.
let new_storage_version = #frame_support::crate_to_pallet_version!();
let pallet_name = <
Expand Down
3 changes: 3 additions & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ pub mod pallet_prelude {
/// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional
/// logic. E.g. logic to write pallet version into storage.
///
/// NOTE: The macro also adds some tracing logic when implementing the above traits. The following
/// hooks emit traces: `on_initialize`, `on_finalize` and `on_runtime_upgrade`.
///
/// # Call: `#[pallet::call]` mandatory
///
/// Implementation of pallet dispatchables.
Expand Down

0 comments on commit 87cdfd3

Please sign in to comment.