nervosnetwork / fiber

15 stars 8 forks source link

Remove log macros and fix log node prefix #127

Closed chenyukang closed 2 months ago

chenyukang commented 2 months ago

There are two drawbacks for https://github.com/nervosnetwork/cfn-node/pull/120

  1. we're losing source file and line number in log event
  2. we macros don't support all argument format: https://docs.rs/tracing/latest/tracing/macro.info.html

There are several methods to propagate the span to spawned tasks:

  1. instrument when using tokio spawn or actor span:

    Actor::spawn_linked(...).instrument(span).await;
  2. instrument with macors for a function

    #[tracing::instrument(name = "Actor", skip(self, myself, args), fields(id = crate::get_node_prefix()))]
    async fn pre_start(
        &self,
        myself: ActorRef<Self::Msg>,
        args: Self::Arguments,
    ) -> Result<Self::State, ActorProcessingErr> {
    ...
    }

This PR use a trivial hack to achieve it, I think it's more general since developers may forget to set instrument for actors.