Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
4 changes: 2 additions & 2 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sc_service::config::{
};
use sc_service::{ChainSpec, TracingReceiver, KeepBlocks, TransactionStorageMode};
use sc_telemetry::TelemetryHandle;
use sc_tracing::logging::GlobalLoggerBuilder;
use sc_tracing::logging::LoggerBuilder;
use std::net::SocketAddr;
use std::path::PathBuf;

Expand Down Expand Up @@ -576,7 +576,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
fn init<C: SubstrateCli>(&self) -> Result<sc_telemetry::TelemetryWorker> {
sp_panic_handler::set(&C::support_url(), &C::impl_version());

let mut logger = GlobalLoggerBuilder::new(self.log_filters()?);
let mut logger = LoggerBuilder::new(self.log_filters()?);
logger.with_log_reloading(!self.is_log_filter_reloading_disabled()?);

if let Some(transport) = self.telemetry_external_transport()? {
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use runner::*;
pub use sc_service::{ChainSpec, Role};
use sc_service::{Configuration, TaskExecutor};
use sc_telemetry::TelemetryHandle;
pub use sc_tracing::logging::GlobalLoggerBuilder;
pub use sc_tracing::logging::LoggerBuilder;
pub use sp_version::RuntimeVersion;
use std::io::Write;
pub use structopt;
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<C: SubstrateCli> Runner<C> {

/// Get a new [`TelemetryHandle`].
///
/// This is used when you want to register a new telemetry for a Substrate node.
/// This is used when you want to register with the [`TelemetryWorker`].
pub fn telemetry_handle(&self) -> TelemetryHandle {
self.telemetry_worker.handle()
}
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn test_add_reset_log_filter() {

// Enter log generation / filter reload
if std::env::var("TEST_LOG_FILTER").is_ok() {
sc_tracing::logging::GlobalLoggerBuilder::new("test_before_add=debug").init().unwrap();
sc_tracing::logging::LoggerBuilder::new("test_before_add=debug").init().unwrap();
for line in std::io::stdin().lock().lines() {
let line = line.expect("Failed to read bytes");
if line.contains("add_reload") {
Expand Down
12 changes: 2 additions & 10 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,7 @@ pub fn new_full_parts<TBl, TRtApi, TExecDisp>(
{
let keystore_container = KeystoreContainer::new(&config.keystore)?;

let telemetry_span = if config.telemetry_endpoints.is_some() {
Some(TelemetrySpan::new())
} else {
None
};
let telemetry_span = config.telemetry_endpoints.as_ref().map(|_| TelemetrySpan::new());
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManager::new(config.task_executor.clone(), registry, telemetry_span.clone())?
Expand Down Expand Up @@ -383,11 +379,7 @@ pub fn new_light_parts<TBl, TRtApi, TExecDisp>(
TExecDisp: NativeExecutionDispatch + 'static,
{
let keystore_container = KeystoreContainer::new(&config.keystore)?;
let telemetry_span = if config.telemetry_endpoints.is_some() {
Some(TelemetrySpan::new())
} else {
None
};
let telemetry_span = config.telemetry_endpoints.as_ref().map(|_| TelemetrySpan::new());
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManager::new(config.task_executor.clone(), registry, telemetry_span.clone())?
Expand Down
7 changes: 2 additions & 5 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,8 @@ impl Configuration {
return None;
}

match self.telemetry_endpoints.as_ref() {
// Don't initialise telemetry if `telemetry_endpoints` == Some([])
Some(endpoints) if !endpoints.is_empty() => Some(endpoints),
_ => None,
}
// Don't initialise telemetry if `telemetry_endpoints` == Some([])
self.telemetry_endpoints.as_ref().filter(|x| !x.is_empty())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh there it is @dvdplm . See! I knew I did it. It was just in another PR

}
}

Expand Down
2 changes: 1 addition & 1 deletion client/service/src/task_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub struct TaskManager {
/// terminates and gracefully shutdown. Also ends the parent `future()` if a child's essential
/// task fails.
children: Vec<TaskManager>,
/// A telemetry handle used to enter the telemetry span when a task is spawned.
/// A `TelemetrySpan` used to enter the telemetry span when a task is spawned.
telemetry_span: Option<TelemetrySpan>,
}

Expand Down
26 changes: 13 additions & 13 deletions client/telemetry/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# sc-telemetry

Substrate's client telemetry is a part of substrate that allows logging telemetry information
with a [Polkadot telemetry](https://github.com/paritytech/substrate-telemetry).
Substrate's client telemetry is a part of substrate that allows ingesting telemetry data
with for example [Polkadot telemetry](https://github.com/paritytech/substrate-telemetry).

It works using Tokio's [tracing](https://github.com/tokio-rs/tracing/). The telemetry
information uses tracing's logging to report the telemetry which is then retrieved by a
tracing's `Layer`. This layer will then send the data through an asynchronous channel and to a
background task called [`TelemetryWorker`] which will send the information to the telemetry
server.
It works using Tokio's [tracing](https://github.com/tokio-rs/tracing/) library. The telemetry
information uses tracing's logging to report the telemetry data which is then retrieved by a
tracing `Layer`. This layer will then send the data through an asynchronous channel to a
background task called [`TelemetryWorker`] which will send the information to the configured
remote telemetry servers.

If multiple substrate nodes are running, it uses a tracing's `Span` to identify which substrate
node is reporting the telemetry. Every task spawned using sc-service's `TaskManager`
automatically inherit this span.
If multiple substrate nodes are running in the same process, it uses a `tracing::Span` to
identify which substrate node is reporting the telemetry. Every task spawned using sc-service's
`TaskManager` automatically inherit this span.

Substrate's nodes initialize/register to the [`TelemetryWorker`] using a [`TelemetryHandle`].
Substrate's nodes initialize/register with the [`TelemetryWorker`] using a [`TelemetryHandle`].
This handle can be cloned and passed around. It uses an asynchronous channel to communicate with
the running [`TelemetryWorker`] dedicated to registration. Registering a telemetry can happen at
any point in time during the execution.
the running [`TelemetryWorker`] dedicated to registration. Registering can happen at any point
in time during the process execution.

License: GPL-3.0-or-later WITH Classpath-exception-2.0
3 changes: 2 additions & 1 deletion client/telemetry/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use serde::{Deserialize, Deserializer, Serialize};
/// The URL string can be either a URL or a multiaddress.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct TelemetryEndpoints(
#[serde(deserialize_with = "url_or_multiaddr_deser")] pub(crate) Vec<(Multiaddr, u8)>,
#[serde(deserialize_with = "url_or_multiaddr_deser")]
pub(crate) Vec<(Multiaddr, u8)>,
);

/// Custom deserializer for TelemetryEndpoints, used to convert urls or multiaddr to multiaddr.
Expand Down
2 changes: 1 addition & 1 deletion client/telemetry/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct TelemetryLayer(Mutex<mpsc::Sender<(Id, u8, String)>>);
impl TelemetryLayer {
/// Create a new [`TelemetryLayer`] and [`TelemetryWorker`].
///
/// If not provided, the `buffer_size` will be 16 by default.
/// The `buffer_size` defaults to 16.
///
/// The [`ExtTransport`] is used in WASM contexts where we need some binding between the
/// networking provided by the operating system or environment and libp2p.
Expand Down
30 changes: 15 additions & 15 deletions client/telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Substrate's client telemetry is a part of substrate that allows logging telemetry information
//! with a [Polkadot telemetry](https://github.com/paritytech/substrate-telemetry).
//! Substrate's client telemetry is a part of substrate that allows ingesting telemetry data
//! with for example [Polkadot telemetry](https://github.com/paritytech/substrate-telemetry).
//!
//! It works using Tokio's [tracing](https://github.com/tokio-rs/tracing/). The telemetry
//! information uses tracing's logging to report the telemetry which is then retrieved by a
//! tracing's `Layer`. This layer will then send the data through an asynchronous channel and to a
//! background task called [`TelemetryWorker`] which will send the information to the telemetry
//! server.
//! It works using Tokio's [tracing](https://github.com/tokio-rs/tracing/) library. The telemetry
//! information uses tracing's logging to report the telemetry data which is then retrieved by a
//! tracing `Layer`. This layer will then send the data through an asynchronous channel to a
//! background task called [`TelemetryWorker`] which will send the information to the configured
//! remote telemetry servers.
//!
//! If multiple substrate nodes are running, it uses a tracing's `Span` to identify which substrate
//! node is reporting the telemetry. Every task spawned using sc-service's `TaskManager`
//! automatically inherit this span.
//! If multiple substrate nodes are running in the same process, it uses a `tracing::Span` to
//! identify which substrate node is reporting the telemetry. Every task spawned using sc-service's
//! `TaskManager` automatically inherit this span.
//!
//! Substrate's nodes initialize/register to the [`TelemetryWorker`] using a [`TelemetryHandle`].
//! Substrate's nodes initialize/register with the [`TelemetryWorker`] using a [`TelemetryHandle`].
//! This handle can be cloned and passed around. It uses an asynchronous channel to communicate with
//! the running [`TelemetryWorker`] dedicated to registration. Registering a telemetry can happen at
//! any point in time during the execution.
//! the running [`TelemetryWorker`] dedicated to registration. Registering can happen at any point
//! in time during the process execution.

#![warn(missing_docs)]

Expand Down Expand Up @@ -115,7 +115,7 @@ pub struct ConnectionMessage {

/// Telemetry worker.
///
/// It should be ran as a background task using the [`TelemetryWorker::run`] method. This method
/// It should run as a background task using the [`TelemetryWorker::run`] method. This method
/// will consume the object and any further attempts of initializing a new telemetry through its
/// handle will fail (without being fatal).
#[derive(Debug)]
Expand Down Expand Up @@ -143,7 +143,7 @@ impl TelemetryWorker {

/// Get a new [`TelemetryHandle`].
///
/// This is used when you want to register a new telemetry for a Substrate node.
/// This is used when you want to register with the [`TelemetryWorker`].
pub fn handle(&self) -> TelemetryHandle {
TelemetryHandle {
message_sender: self.register_sender.clone(),
Expand Down
2 changes: 1 addition & 1 deletion client/tracing/src/logging/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(crate) fn set_reload_handle(handle: Handle<EnvFilter, SCSubscriber>) {
let _ = FILTER_RELOAD_HANDLE.set(handle);
}

// The layered Subscriber as built up in `init_logger()`.
// The layered Subscriber as built up in `GlobalLogger::init()`.
// Used in the reload `Handle`.
type SCSubscriber<
N = tracing_fmt::format::DefaultFields,
Expand Down
15 changes: 12 additions & 3 deletions client/tracing/src/logging/layers/prefix_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ where
S: Subscriber + for<'a> LookupSpan<'a>,
{
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let span = ctx
.span(id)
.expect("new_span has been called for this span; qed");
let span = match ctx.span(id) {
Some(span) => span,
None => {
// this shouldn't happen!
debug_assert!(
false,
"newly created span with ID {:?} did not exist in the registry; this is a bug!",
id
);
return;
}
};

if span.name() != PREFIX_LOG_SPAN {
return;
Expand Down
Loading