Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +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() {
let telemetry_span = if config.telemetry_endpoints().is_some() {
Some(TelemetrySpan::new())
} else {
None
Expand Down Expand Up @@ -383,7 +383,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() {
let telemetry_span = if config.telemetry_endpoints().is_some() {
Some(TelemetrySpan::new())
} else {
None
Expand Down
18 changes: 14 additions & 4 deletions client/service/src/task_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ impl SpawnTaskHandle {
metrics.tasks_ended.with_label_values(&[name, "finished"]).inc_by(0);
}

let telemetry_span = self.telemetry_span.clone();
let future = async move {
let _telemetry_entered = telemetry_span.as_ref().map(|x| x.enter());

if let Some(metrics) = metrics {
// Add some wrappers around `task`.
let task = {
Expand Down Expand Up @@ -127,7 +124,20 @@ impl SpawnTaskHandle {
}
};

let join_handle = self.executor.spawn(Box::pin(future.in_current_span()), task_type);
let future: Pin<Box<dyn Future<Output = ()> + Send>> =
if let Some(telemetry_span) = self.telemetry_span.clone() {
// this will preserve the telemetry span and by extension all of its parents as they
// are linked together upon creation
// this is used by sc_telemetry::layer::TelemetryLayer
Box::pin(future.instrument(telemetry_span.span()))
} else {
// this will preserve the current span (if any) and by extension all of its parents
// as they are linked together upon creation
// this is used by sc_tracing::logging::prefix_logs_with
Box::pin(future.in_current_span())
};

let join_handle = self.executor.spawn(future, task_type);
let mut task_notifier = self.task_notifier.clone();
self.executor.spawn(
Box::pin(async move {
Expand Down
5 changes: 5 additions & 0 deletions client/telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ impl TelemetrySpan {
pub fn new() -> Self {
Self(tracing::info_span!(TELEMETRY_LOG_SPAN))
}

/// Return a clone of the underlying `tracing::Span` instance.
pub fn span(&self) -> tracing::Span {
self.0.clone()
}
}

/// Message sent when the connection (re-)establishes.
Expand Down