diff --git a/Cargo.lock b/Cargo.lock index dee751b..e99ac24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.67" @@ -90,6 +96,7 @@ name = "skywalking-core" version = "0.1.0" dependencies = [ "base64", + "lazy_static", "rand", ] diff --git a/Cargo.toml b/Cargo.toml index 007e2b9..629476f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http:#www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + [workspace] members = [ - "tracing-core", + "core", ] \ No newline at end of file diff --git a/README.md b/README.md index efef7df..f9ca49d 100644 --- a/README.md +++ b/README.md @@ -37,23 +37,43 @@ manipulate the RPC header/metadata to make the key/value sent to the server side ## Extractable Extractable is used(optional) when the entry span creates. The Extractable fetches the value of the given key from the propagated -context. Typically, Extractable implementation would read the RPC header/metadata, which sent from the client side. +context. Typically, Extractable implementation would read the RPC header/metadata, which sent from the client side. # APIs -## Tracing Core APIs +## High-Level APIs +High level APIs are targeting convenient usages. These APIs use the ThreadLocal to propagate the context, so users could +create span at any moment, and the context will finish automatically once the first created span of this thread stopped. + +```rust +ContextManager::tracing_entry("op1", Some(&injector), |mut span| { + // Use span freely in this closure + // Span's start/end time is set automatically with this closure start/end(s). + span.tag(Tag::new(String::from("tag1"), String::from("value1"))); + + ContextManager::tracing_exit("op2", "127.0.0.1:8080", Some(&extractor), |mut span| { + span.set_component_id(33); + }); + + ContextManager::tracing_local("op3", |mut span| {}); +}); +``` + +## Low-Level Core APIs Tracing core APIs are 100% manual control tracing APIs. Users could use them to trace any process by following SkyWalking core concepts. +Low Level APIs request users to create and hold the context and span by the codes manually. + ```rust -let mut context = TracingContext::new(&reporter).unwrap(); -let span1 = context.create_entry_span("op1", None, Some(&MockerHeader {})); +let mut context = TracingContext::new(reporter.service_instance_id()).unwrap(); +let span1 = context.create_entry_span("op1", None, Some(&dyn injector)); { assert_eq!(span1.span_id(), 0); let mut span2 = context.create_local_span("op2", Some(&span1)); span2.tag(Tag::new(String::from("tag1"), String::from("value1"))); { assert_eq!(span2.span_id(), 1); - let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&HeaderCarrier {})); + let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&dyn extractor)); assert_eq!(span3.span_id(), 2); context.finish_span(span3); diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 0000000..c187379 --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http:#www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[package] +name = "skywalking-core" +version = "0.1.0" +authors = ["Apache Software Foundation (ASF)"] +edition = "2018" +description = "SkyWalking tracing core APIs. Provide the way to build SkyWalking native format traces/spans and propagated context." +license = "Apache 2.0" + +[dependencies] +rand = "0.7.3" +base64 = "0.11.0" +lazy_static = "1.4.0" \ No newline at end of file diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 0000000..f94e272 --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,17 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod skywalking; + diff --git a/core/src/skywalking/agent/context_manager.rs b/core/src/skywalking/agent/context_manager.rs new file mode 100644 index 0000000..5c5df7f --- /dev/null +++ b/core/src/skywalking/agent/context_manager.rs @@ -0,0 +1,265 @@ +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::borrow::{Borrow, BorrowMut}; +use std::cell::RefCell; +use std::rc::Rc; + +use lazy_static::lazy_static; + +use crate::skywalking::agent::reporter::Reporter; +use crate::skywalking::core::{Context, ContextListener, Extractable, Injectable, Span, TracingContext}; +use crate::skywalking::core::span::TracingSpan; + +/// Thread Local tracing context. Host the context and propagate it in each thread if needed. +thread_local!( static CTX: RefCell = RefCell::new(CurrentTracingContext::new())); +/// Global reporter +/// Status: WIP +lazy_static! { + static ref SKYWALKING_REPORTER : Reporter = { + Reporter::new() + }; +} + +pub struct ContextManager {} + +impl ContextManager { + /// Run a closure under an entry span observing. + /// Span is automatically created, started and ended around the closure f. + pub fn tracing_entry(operation_name: &str, extractor: Option<&dyn Extractable>, f: F) + where F: FnOnce(&mut Box) { + CTX.with(|context| { + let span; + { + // Borrow mut ref has to end in this specific scope, as the context is nested used in f + let mut mut_context = context.borrow_mut(); + let parent_span_id = mut_context.parent_span_id(); + span = mut_context.create_entry_span(operation_name, parent_span_id, extractor); + } + match span { + None => {} + Some(mut s) => { + s.start(); + f(s.borrow_mut()); + s.end(); + + let is_first_span = s.span_id() == 0; + let mut mut_context = context.borrow_mut(); + mut_context.finish_span(s); + + if is_first_span { + mut_context.finish(); + } + } + }; + }); + } + + /// Run a closure under an exit span observing. + /// Span is automatically created, started and ended around the closure f. + pub fn tracing_exit(operation_name: &str, peer: &str, injector: Option<&dyn Injectable>, f: F) + where F: FnOnce(&mut Box) { + CTX.with(|context| { + let span; + { + // Borrow mut ref has to end in this specific scope, as the context is nested used in f + let mut mut_context = context.borrow_mut(); + let parent_span_id = mut_context.parent_span_id(); + span = mut_context.create_exit_span(operation_name, parent_span_id, peer, injector); + } + match span { + None => {} + Some(mut s) => { + s.start(); + f(s.borrow_mut()); + s.end(); + + let is_first_span = s.span_id() == 0; + + let mut mut_context = context.borrow_mut(); + mut_context.finish_span(s); + + if is_first_span { + mut_context.finish(); + } + } + }; + }); + } + + /// Run a closure under a local span observing. + /// Span is automatically created, started and ended around the closure f. + pub fn tracing_local(operation_name: &str, f: F) + where F: FnOnce(&mut Box) { + CTX.with(|context| { + let span; + { + // Borrow mut ref has to end in this specific scope, as the context is nested used in f + let mut mut_context = context.borrow_mut(); + let parent_span_id = mut_context.parent_span_id(); + span = mut_context.create_local(operation_name, parent_span_id); + } + match span { + None => {} + Some(mut s) => { + s.start(); + f(s.borrow_mut()); + s.end(); + + let is_first_span = s.span_id() == 0; + + let mut mut_context = context.borrow_mut(); + mut_context.finish_span(s); + + if is_first_span { + mut_context.finish(); + } + } + }; + }); + } +} + +struct CurrentTracingContext { + option: Option>, +} + +struct WorkingContext { + context: Box, + span_stack: Vec, +} + +impl CurrentTracingContext { + /// Create the tracing context in the thread local at the first time. + fn new() -> Self { + CurrentTracingContext { + option: match TracingContext::new(SKYWALKING_REPORTER.service_instance_id()) { + Some(tx) => { + Some(Box::new(WorkingContext { + context: Box::new(tx), + span_stack: Vec::new(), + })) + } + None => { None } + }, + } + } + + /// Delegate to the tracing core entry span creation method, if current context is valid. + fn create_entry_span(&mut self, operation_name: &str, parent_span_id: Option, extractor: Option<&dyn Extractable>) -> Option> { + match self.option.borrow_mut() { + None => { None } + Some(wx) => { + let span = wx.context.create_entry_span(operation_name, parent_span_id, extractor); + wx.span_stack.push(span.span_id()); + Some(span) + } + } + } + + /// Delegate to the tracing core exit span creation method, if current context is valid. + fn create_exit_span(&mut self, operation_name: &str, parent_span_id: Option, peer: &str, injector: Option<&dyn Injectable>) -> Option> { + match self.option.borrow_mut() { + None => { None } + Some(wx) => { + let span = wx.context.create_exit_span(operation_name, parent_span_id, peer, injector); + wx.span_stack.push(span.span_id()); + Some(span) + } + } + } + + /// Delegate to the tracing core local span creation method, if current context is valid. + fn create_local(&mut self, operation_name: &str, parent_span_id: Option) -> Option> { + match self.option.borrow_mut() { + None => { None } + Some(wx) => { + let span = wx.context.create_local_span(operation_name, parent_span_id); + wx.span_stack.push(span.span_id()); + Some(span) + } + } + } + + /// Delegate to the tracing core span finish method, if current context is valid. + fn finish_span(&mut self, span: Box) { + match self.option.borrow_mut() { + None => {} + Some(wx) => { + wx.context.finish_span(span); + wx.span_stack.pop(); + } + }; + } + + /// Fetch the parent span id, to be used in next new span. + /// The span id(s) are saved in the span_stack by following as same the stack-style as span creation sequence. + fn parent_span_id(&self) -> Option { + match self.option.borrow() { + None => { None } + Some(wx) => { + match wx.span_stack.last() { + None => { None } + Some(span_id) => { Some(span_id.clone()) } + } + } + } + } + + /// Finish the current tracing context, including + /// 1. Clear up the context + /// 2. Transfer the context to profobuf format and pass to reporter. + fn finish(&mut self) { + match self.option.borrow_mut() { + None => {} + Some(wx) => { + let tracingContext = &wx.context; + + wx.span_stack.clear(); + + // TODO: Transfer tracingContext to protobuf + } + } + self.option = None; + } +} + + +#[cfg(test)] +mod context_tests { + use crate::skywalking::agent::context_manager::*; + use crate::skywalking::core::{ContextListener, Tag, TracingContext}; + + #[test] + fn test_context_manager() { + ContextManager::tracing_entry("op1", None, |mut span| { + span.tag(Tag::new(String::from("tag1"), String::from("value1"))); + + ContextManager::tracing_exit("op2", "127.0.0.1:8080", None, |mut span| { + span.set_component_id(33); + }); + + ContextManager::tracing_local("op3", |mut span| {}); + }); + } + + struct MockReporter {} + + impl ContextListener for MockReporter { + fn service_instance_id(&self) -> Option { + Some(1) + } + + fn report_trace(&self, finished_context: Box) {} + } +} diff --git a/core/src/skywalking/agent/mod.rs b/core/src/skywalking/agent/mod.rs new file mode 100644 index 0000000..7cf36a6 --- /dev/null +++ b/core/src/skywalking/agent/mod.rs @@ -0,0 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub use context_manager::ContextManager; + +pub mod context_manager; +pub mod reporter; + diff --git a/core/src/skywalking/agent/reporter.rs b/core/src/skywalking/agent/reporter.rs new file mode 100644 index 0000000..cf26f3f --- /dev/null +++ b/core/src/skywalking/agent/reporter.rs @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::skywalking::core::{ContextListener, TracingContext}; + +pub struct Reporter {} + +impl ContextListener for Reporter { + fn service_instance_id(&self) -> Option { + Some(1) + } + + fn report_trace(&self, finished_context: Box) { + unimplemented!() + } +} + +impl Reporter { + pub fn new() -> Self { + Reporter {} + } +} \ No newline at end of file diff --git a/tracing-core/src/context.rs b/core/src/skywalking/core/context.rs similarity index 76% rename from tracing-core/src/context.rs rename to core/src/skywalking/core/context.rs index 47a2ed8..a9465b3 100644 --- a/tracing-core/src/context.rs +++ b/core/src/skywalking/core/context.rs @@ -15,21 +15,22 @@ use base64::{decode, encode}; -use crate::{ContextListener, ID, Span}; -use crate::context_carrier::{Extractable, Injectable}; -use crate::id::IDGenerator; -use crate::segment_ref::SegmentRef; -use crate::span::TracingSpan; +use crate::skywalking::agent::reporter::Reporter; +use crate::skywalking::core::{ID, Span}; +use crate::skywalking::core::context_carrier::{Extractable, Injectable}; +use crate::skywalking::core::id::IDGenerator; +use crate::skywalking::core::segment_ref::SegmentRef; +use crate::skywalking::core::span::TracingSpan; /// Context represents the context of a tracing process. /// All new span belonging to this tracing context should be created through this context. pub trait Context { /// Create an entry span belonging this context - fn create_entry_span(&mut self, operation_name: &str, parent: Option<&Box>, extractor: Option<&dyn Extractable>) -> Box; + fn create_entry_span(&mut self, operation_name: &str, parent_span_id: Option, extractor: Option<&dyn Extractable>) -> Box; /// Create an exit span belonging this context - fn create_exit_span(&mut self, operation_name: &str, parent: Option<&Box>, peer: &str, injector: Option<&dyn Injectable>) -> Box; + fn create_exit_span(&mut self, operation_name: &str, parent_span_id: Option, peer: &str, injector: Option<&dyn Injectable>) -> Box; /// Create an local span belonging this context - fn create_local_span(&mut self, operation_name: &str, parent: Option<&Box>) -> Box; + fn create_local_span(&mut self, operation_name: &str, parent_span_id: Option) -> Box; /// Finish the given span. The span is only being accept if it belongs to this context. /// Return err if the span was created by another context. fn finish_span(&mut self, span: Box); @@ -51,9 +52,8 @@ pub struct TracingContext { impl TracingContext { /// Create a new instance - pub fn new(reporter: &dyn ContextListener) -> Option { - let instance_id = reporter.service_instance_id(); - match instance_id { + pub fn new(service_instance_id: Option) -> Option { + match service_instance_id { None => { None } Some(id) => { Some(TracingContext { @@ -100,10 +100,10 @@ impl TracingContext { /// Default implementation of Context impl Context for TracingContext { - fn create_entry_span(&mut self, operation_name: &str, parent: Option<&Box>, extractor: Option<&dyn Extractable>) -> Box { - let mut entry_span = TracingSpan::new_entry_span(operation_name, self.next_span_id(), match parent { + fn create_entry_span(&mut self, operation_name: &str, parent_span_id: Option, extractor: Option<&dyn Extractable>) -> Box { + let mut entry_span = TracingSpan::new_entry_span(operation_name, self.next_span_id(), match parent_span_id { None => { -1 } - Some(s) => { s.span_id() } + Some(s) => { s } }); if extractor.is_some() { @@ -125,10 +125,10 @@ impl Context for TracingContext { Box::new(entry_span) } - fn create_exit_span(&mut self, operation_name: &str, parent: Option<&Box>, peer: &str, injector: Option<&dyn Injectable>) -> Box { - let exit_span = TracingSpan::new_exit_span(operation_name, self.next_span_id(), match parent { + fn create_exit_span(&mut self, operation_name: &str, parent_span_id: Option, peer: &str, injector: Option<&dyn Injectable>) -> Box { + let exit_span = TracingSpan::new_exit_span(operation_name, self.next_span_id(), match parent_span_id { None => { -1 } - Some(s) => { s.span_id() } + Some(s) => { s } }, peer); if injector.is_some() { @@ -138,10 +138,10 @@ impl Context for TracingContext { Box::new(exit_span) } - fn create_local_span(&mut self, operation_name: &str, parent: Option<&Box>) -> Box { - Box::new(TracingSpan::new_local_span(operation_name, self.next_span_id(), match parent { + fn create_local_span(&mut self, operation_name: &str, parent_span_id: Option) -> Box { + Box::new(TracingSpan::new_local_span(operation_name, self.next_span_id(), match parent_span_id { None => { -1 } - Some(s) => { s.span_id() } + Some(s) => { s } })) } @@ -158,20 +158,20 @@ mod context_tests { use std::sync::mpsc; use std::sync::mpsc::{Receiver, Sender}; - use crate::{Context, ContextListener, Extractable, ID, Injectable, Tag, TracingContext}; + use crate::skywalking::core::{Context, ContextListener, Extractable, ID, Injectable, Tag, TracingContext}; #[test] fn test_context_stack() { let reporter = MockReporter::new(); - let mut context = TracingContext::new(&reporter).unwrap(); + let mut context = TracingContext::new(reporter.service_instance_id()).unwrap(); let span1 = context.create_entry_span("op1", None, Some(&MockerHeader {})); { assert_eq!(span1.span_id(), 0); - let mut span2 = context.create_local_span("op2", Some(&span1)); + let mut span2 = context.create_local_span("op2", Some(span1.span_id())); span2.tag(Tag::new(String::from("tag1"), String::from("value1"))); { assert_eq!(span2.span_id(), 1); - let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&HeaderCarrier {})); + let span3 = context.create_exit_span("op3", Some(span2.span_id()), "127.0.0.1:8080", Some(&HeaderCarrier {})); assert_eq!(span3.span_id(), 2); context.finish_span(span3); @@ -180,7 +180,7 @@ mod context_tests { } context.finish_span(span1); - reporter.report_trace(context); + reporter.report_trace(Box::new(context)); // context has moved into reporter. Can't be used again. let received_context = reporter.recv.recv().unwrap(); @@ -190,13 +190,13 @@ mod context_tests { #[test] fn test_no_context() { - let context = TracingContext::new(&MockRegisterPending {}); + let context = TracingContext::new(None); assert_eq!(context.is_none(), true); } struct MockReporter { - sender: Box>, - recv: Box>, + sender: Box>>, + recv: Box>>, } impl MockReporter { @@ -214,7 +214,7 @@ mod context_tests { Some(1) } - fn report_trace(&self, finished_context: TracingContext) { + fn report_trace(&self, finished_context: Box) { self.sender.send(finished_context); } } @@ -235,16 +235,4 @@ mod context_tests { assert_eq!(value.len() > 0, true); } } - - struct MockRegisterPending {} - - impl ContextListener for MockRegisterPending { - fn service_instance_id(&self) -> Option { - None - } - - fn report_trace(&self, finished_context: TracingContext) { - unimplemented!() - } - } } \ No newline at end of file diff --git a/tracing-core/src/context_carrier.rs b/core/src/skywalking/core/context_carrier.rs similarity index 100% rename from tracing-core/src/context_carrier.rs rename to core/src/skywalking/core/context_carrier.rs diff --git a/tracing-core/src/context_listener.rs b/core/src/skywalking/core/context_listener.rs similarity index 92% rename from tracing-core/src/context_listener.rs rename to core/src/skywalking/core/context_listener.rs index 9eab7f3..9cb5842 100644 --- a/tracing-core/src/context_listener.rs +++ b/core/src/skywalking/core/context_listener.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::TracingContext; +use crate::skywalking::core::TracingContext; ///Report bridge defines the traits for the skywalking-report @@ -26,5 +26,5 @@ pub trait ContextListener { /// Move the finished and inactive context to the reporter. /// The reporter should use async way to transport the data to the backend through HTTP, gRPC or SkyWalking forwarder. - fn report_trace(&self, finished_context: TracingContext); + fn report_trace(&self, finished_context: Box); } diff --git a/tracing-core/src/id.rs b/core/src/skywalking/core/id.rs similarity index 97% rename from tracing-core/src/id.rs rename to core/src/skywalking/core/id.rs index b276986..384963a 100644 --- a/tracing-core/src/id.rs +++ b/core/src/skywalking/core/id.rs @@ -85,8 +85,8 @@ impl ToString for ID { #[cfg(test)] mod id_tests { - use crate::ID; - use crate::id::IDGenerator; + use crate::skywalking::core::ID; + use crate::skywalking::core::id::IDGenerator; #[test] fn test_id_generator() { diff --git a/tracing-core/src/log.rs b/core/src/skywalking/core/log.rs similarity index 97% rename from tracing-core/src/log.rs rename to core/src/skywalking/core/log.rs index a8d3c9a..e0b81f1 100644 --- a/tracing-core/src/log.rs +++ b/core/src/skywalking/core/log.rs @@ -47,7 +47,7 @@ impl EventField { #[cfg(test)] mod log_tests { - use crate::log::{EventField, LogEvent}; + use crate::skywalking::core::log::{EventField, LogEvent}; #[test] fn test_log_new() { diff --git a/tracing-core/src/lib.rs b/core/src/skywalking/core/mod.rs similarity index 98% rename from tracing-core/src/lib.rs rename to core/src/skywalking/core/mod.rs index 7d9a2d1..7715556 100644 --- a/tracing-core/src/lib.rs +++ b/core/src/skywalking/core/mod.rs @@ -31,5 +31,4 @@ pub mod id; pub mod context_listener; pub mod log; pub mod context_carrier; -pub mod segment_ref; - +pub mod segment_ref; \ No newline at end of file diff --git a/tracing-core/src/segment_ref.rs b/core/src/skywalking/core/segment_ref.rs similarity index 97% rename from tracing-core/src/segment_ref.rs rename to core/src/skywalking/core/segment_ref.rs index eca2be1..421da20 100644 --- a/tracing-core/src/segment_ref.rs +++ b/core/src/skywalking/core/segment_ref.rs @@ -15,8 +15,8 @@ use std::os::raw::c_long; -use crate::{ID, Span, TracingContext}; -use crate::segment_ref::SegmentRefType::CROSS_PROCESS; +use crate::skywalking::core::{ID, Span, TracingContext}; +use crate::skywalking::core::segment_ref::SegmentRefType::CROSS_PROCESS; #[derive(Clone, Hash)] pub struct SegmentRef { @@ -214,8 +214,8 @@ impl SegmentRef { #[cfg(test)] mod segment_ref_tests { - use crate::ID; - use crate::segment_ref::SegmentRef; + use crate::skywalking::core::ID; + use crate::skywalking::core::segment_ref::SegmentRef; #[test] fn test_deserialize_context_carrier() { diff --git a/tracing-core/src/span.rs b/core/src/skywalking/core/span.rs similarity index 97% rename from tracing-core/src/span.rs rename to core/src/skywalking/core/span.rs index a51c8eb..9842dea 100644 --- a/tracing-core/src/span.rs +++ b/core/src/skywalking/core/span.rs @@ -15,9 +15,9 @@ use std::time::SystemTime; -use crate::log::LogEvent; -use crate::segment_ref::SegmentRef; -use crate::Tag; +use crate::skywalking::core::log::LogEvent; +use crate::skywalking::core::segment_ref::SegmentRef; +use crate::skywalking::core::Tag; /// Span is one of the tracing concept, representing a time duration. ///Span is an important and common concept in distributed tracing system. Learn Span from Google Dapper Paper. @@ -209,9 +209,9 @@ impl Span for TracingSpan { mod span_tests { use std::time::SystemTime; - use crate::log::{EventField, LogEvent}; - use crate::span::*; - use crate::Tag; + use crate::skywalking::core::log::{EventField, LogEvent}; + use crate::skywalking::core::span::*; + use crate::skywalking::core::Tag; #[test] fn test_span_new() { diff --git a/tracing-core/src/tag.rs b/core/src/skywalking/core/tag.rs similarity index 97% rename from tracing-core/src/tag.rs rename to core/src/skywalking/core/tag.rs index aab0e0c..80bbad9 100644 --- a/tracing-core/src/tag.rs +++ b/core/src/skywalking/core/tag.rs @@ -41,7 +41,7 @@ impl Tag { #[cfg(test)] mod tag_tests { - use crate::Tag; + use crate::skywalking::core::Tag; #[test] fn test_tag_new() { diff --git a/core/src/skywalking/mod.rs b/core/src/skywalking/mod.rs new file mode 100644 index 0000000..08730c9 --- /dev/null +++ b/core/src/skywalking/mod.rs @@ -0,0 +1,17 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod core; +pub mod agent; diff --git a/tracing-core/Cargo.toml b/tracing-core/Cargo.toml deleted file mode 100644 index 821e4ef..0000000 --- a/tracing-core/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "skywalking-core" -version = "0.1.0" -authors = ["Apache Software Foundation (ASF)"] -edition = "2018" -description = "SkyWalking tracing core APIs. Provide the way to build SkyWalking native format traces/spans and propagated context." -license = "Apache 2.0" - -[dependencies] -rand = "0.7.3" -base64 = "0.11.0" \ No newline at end of file