Add tracing logic in pallet macro for hooks and dispatchables (#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>
This commit is contained in:
Guillaume Thiolliere
2021-03-23 15:53:46 +01:00
committed by GitHub
parent 1f911ddb61
commit 1602f8dd2d
3 changed files with 19 additions and 2 deletions
@@ -162,9 +162,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
) -> #frame_support::dispatch::DispatchResultWithPostInfo { ) -> #frame_support::dispatch::DispatchResultWithPostInfo {
match self { 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, )* ) <#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(_, _) => { Self::__Ignore(_, _) => {
let _ = origin; // Use origin for empty Call enum let _ = origin; // Use origin for empty Call enum
@@ -55,6 +55,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
for #pallet_ident<#type_use_gen> #where_clause for #pallet_ident<#type_use_gen> #where_clause
{ {
fn on_finalize(n: <T as #frame_system::Config>::BlockNumber) { 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< Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber <T as #frame_system::Config>::BlockNumber
@@ -86,6 +89,9 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
fn on_initialize( fn on_initialize(
n: <T as #frame_system::Config>::BlockNumber n: <T as #frame_system::Config>::BlockNumber
) -> #frame_support::weights::Weight { ) -> #frame_support::weights::Weight {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_initialize")
);
< <
Self as #frame_support::traits::Hooks< Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber <T as #frame_system::Config>::BlockNumber
@@ -99,6 +105,10 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
for #pallet_ident<#type_use_gen> #where_clause for #pallet_ident<#type_use_gen> #where_clause
{ {
fn on_runtime_upgrade() -> #frame_support::weights::Weight { 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. // log info about the upgrade.
let new_storage_version = #frame_support::crate_to_pallet_version!(); let new_storage_version = #frame_support::crate_to_pallet_version!();
let pallet_name = < let pallet_name = <
+3
View File
@@ -1229,6 +1229,9 @@ pub mod pallet_prelude {
/// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional /// NOTE: OnRuntimeUpgrade is implemented with `Hooks::on_runtime_upgrade` and some additional
/// logic. E.g. logic to write pallet version into storage. /// 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 /// # Call: `#[pallet::call]` mandatory
/// ///
/// Implementation of pallet dispatchables. /// Implementation of pallet dispatchables.