From f6dc35284f5f9df7f0e06591d6f229369f73bd3b Mon Sep 17 00:00:00 2001
From: Andrew Plaza <aplaza@liquidthink.net>
Date: Sat, 28 Nov 2020 09:40:24 +0100
Subject: [PATCH] Change TRACING_SET to static (#7607)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* change TRACING_SET to static

* Update primitives/io/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* modify test with nested spans

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
---
 substrate/client/executor/runtime-test/src/lib.rs     | 11 +++++++++++
 .../client/executor/src/integration_tests/mod.rs      |  9 +++++++++
 substrate/primitives/io/src/lib.rs                    |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/substrate/client/executor/runtime-test/src/lib.rs b/substrate/client/executor/runtime-test/src/lib.rs
index f4cef65b629..bfba4ef0393 100644
--- a/substrate/client/executor/runtime-test/src/lib.rs
+++ b/substrate/client/executor/runtime-test/src/lib.rs
@@ -261,6 +261,17 @@ sp_core::wasm_export_functions! {
 		wasm_tracing::exit(span_id)
 	}
 
+	fn test_nested_spans() {
+		sp_io::init_tracing();
+		let span_id = wasm_tracing::enter_span(Default::default());
+		{
+			sp_io::init_tracing();
+			let span_id = wasm_tracing::enter_span(Default::default());
+			wasm_tracing::exit(span_id);
+		}
+		wasm_tracing::exit(span_id);
+	}
+
 	fn returns_mutable_static() -> u64 {
 		unsafe {
 			MUTABLE_STATIC += 1;
diff --git a/substrate/client/executor/src/integration_tests/mod.rs b/substrate/client/executor/src/integration_tests/mod.rs
index 08771847c25..62368441f58 100644
--- a/substrate/client/executor/src/integration_tests/mod.rs
+++ b/substrate/client/executor/src/integration_tests/mod.rs
@@ -719,6 +719,15 @@ fn wasm_tracing_should_work(wasm_method: WasmExecutionMethod) {
 	assert_eq!(span_datum.target, "default");
 	assert_eq!(span_datum.name, "");
 	assert_eq!(values.bool_values.get("wasm").unwrap(), &true);
+
+	call_in_wasm(
+		"test_nested_spans",
+		Default::default(),
+		wasm_method,
+		&mut ext,
+	).unwrap();
+	let len = traces.lock().unwrap().len();
+	assert_eq!(len, 2);
 }
 
 #[test_case(WasmExecutionMethod::Interpreted)]
diff --git a/substrate/primitives/io/src/lib.rs b/substrate/primitives/io/src/lib.rs
index 382a0c4b3bd..d812baefb57 100644
--- a/substrate/primitives/io/src/lib.rs
+++ b/substrate/primitives/io/src/lib.rs
@@ -1093,7 +1093,7 @@ mod tracing_setup {
 	};
 	use super::{wasm_tracing, Crossing};
 
-	const TRACING_SET : AtomicBool = AtomicBool::new(false);
+	static TRACING_SET: AtomicBool = AtomicBool::new(false);
 
 
 	/// The PassingTracingSubscriber implements `tracing_core::Subscriber`
-- 
GitLab