Support ContextManager APIs and context stack-style auto propagation. (#3)
* m1 only.
* Finish m2.
* Could keep parent in the shadow, and build the span relationship based on stack automatically.
* Support context manager APIs.
* Add some comments to codes.
diff --git a/Cargo.lock b/Cargo.lock
index dee751b..e99ac24 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -33,6 +33,12 @@
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -90,6 +96,7 @@
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 @@
## 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/tracing-core/src/lib.rs b/core/src/lib.rs
similarity index 65%
copy from tracing-core/src/lib.rs
copy to core/src/lib.rs
index 7d9a2d1..f94e272 100644
--- a/tracing-core/src/lib.rs
+++ b/core/src/lib.rs
@@ -13,23 +13,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub use context::Context;
-pub use context::TracingContext;
-pub use context_carrier::Extractable;
-pub use context_carrier::Injectable;
-pub use context_listener::ContextListener;
-pub use id::ID;
-pub use log::EventField;
-pub use log::LogEvent;
-pub use span::Span;
-pub use tag::Tag;
-
-pub mod span;
-pub mod context;
-pub mod tag;
-pub mod id;
-pub mod context_listener;
-pub mod log;
-pub mod context_carrier;
-pub mod segment_ref;
+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<CurrentTracingContext> = 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<F>(operation_name: &str, extractor: Option<&dyn Extractable>, f: F)
+ where F: FnOnce(&mut Box<dyn Span>) {
+ CTX.with(|context| {
+ let span;
+ {
+ // Borrow mut ref has to end in this specific scope, as the context is nested used in f<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<F>(operation_name: &str, peer: &str, injector: Option<&dyn Injectable>, f: F)
+ where F: FnOnce(&mut Box<dyn Span>) {
+ CTX.with(|context| {
+ let span;
+ {
+ // Borrow mut ref has to end in this specific scope, as the context is nested used in f<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<F>(operation_name: &str, f: F)
+ where F: FnOnce(&mut Box<dyn Span>) {
+ CTX.with(|context| {
+ let span;
+ {
+ // Borrow mut ref has to end in this specific scope, as the context is nested used in f<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<Box<WorkingContext>>,
+}
+
+struct WorkingContext {
+ context: Box<TracingContext>,
+ span_stack: Vec<i32>,
+}
+
+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<i32>, extractor: Option<&dyn Extractable>) -> Option<Box<dyn Span>> {
+ 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<i32>, peer: &str, injector: Option<&dyn Injectable>) -> Option<Box<dyn Span>> {
+ 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<i32>) -> Option<Box<dyn Span>> {
+ 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<dyn Span>) {
+ 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<i32> {
+ 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<i32> {
+ Some(1)
+ }
+
+ fn report_trace(&self, finished_context: Box<TracingContext>) {}
+ }
+}
diff --git a/tracing-core/src/lib.rs b/core/src/skywalking/agent/mod.rs
similarity index 64%
copy from tracing-core/src/lib.rs
copy to core/src/skywalking/agent/mod.rs
index 7d9a2d1..7cf36a6 100644
--- a/tracing-core/src/lib.rs
+++ b/core/src/skywalking/agent/mod.rs
@@ -13,23 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub use context::Context;
-pub use context::TracingContext;
-pub use context_carrier::Extractable;
-pub use context_carrier::Injectable;
-pub use context_listener::ContextListener;
-pub use id::ID;
-pub use log::EventField;
-pub use log::LogEvent;
-pub use span::Span;
-pub use tag::Tag;
+pub use context_manager::ContextManager;
-pub mod span;
-pub mod context;
-pub mod tag;
-pub mod id;
-pub mod context_listener;
-pub mod log;
-pub mod context_carrier;
-pub mod segment_ref;
+pub mod context_manager;
+pub mod reporter;
diff --git a/tracing-core/src/lib.rs b/core/src/skywalking/agent/reporter.rs
similarity index 64%
copy from tracing-core/src/lib.rs
copy to core/src/skywalking/agent/reporter.rs
index 7d9a2d1..cf26f3f 100644
--- a/tracing-core/src/lib.rs
+++ b/core/src/skywalking/agent/reporter.rs
@@ -13,23 +13,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub use context::Context;
-pub use context::TracingContext;
-pub use context_carrier::Extractable;
-pub use context_carrier::Injectable;
-pub use context_listener::ContextListener;
-pub use id::ID;
-pub use log::EventField;
-pub use log::LogEvent;
-pub use span::Span;
-pub use tag::Tag;
+use crate::skywalking::core::{ContextListener, TracingContext};
-pub mod span;
-pub mod context;
-pub mod tag;
-pub mod id;
-pub mod context_listener;
-pub mod log;
-pub mod context_carrier;
-pub mod segment_ref;
+pub struct Reporter {}
+impl ContextListener for Reporter {
+ fn service_instance_id(&self) -> Option<i32> {
+ Some(1)
+ }
+
+ fn report_trace(&self, finished_context: Box<TracingContext>) {
+ 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<dyn Span>>, extractor: Option<&dyn Extractable>) -> Box<dyn Span>;
+ fn create_entry_span(&mut self, operation_name: &str, parent_span_id: Option<i32>, extractor: Option<&dyn Extractable>) -> Box<dyn Span>;
/// Create an exit span belonging this context
- fn create_exit_span(&mut self, operation_name: &str, parent: Option<&Box<dyn Span>>, peer: &str, injector: Option<&dyn Injectable>) -> Box<dyn Span>;
+ fn create_exit_span(&mut self, operation_name: &str, parent_span_id: Option<i32>, peer: &str, injector: Option<&dyn Injectable>) -> Box<dyn Span>;
/// Create an local span belonging this context
- fn create_local_span(&mut self, operation_name: &str, parent: Option<&Box<dyn Span>>) -> Box<dyn Span>;
+ fn create_local_span(&mut self, operation_name: &str, parent_span_id: Option<i32>) -> Box<dyn Span>;
/// 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<dyn Span>);
@@ -51,9 +52,8 @@
impl TracingContext {
/// Create a new instance
- pub fn new(reporter: &dyn ContextListener) -> Option<TracingContext> {
- let instance_id = reporter.service_instance_id();
- match instance_id {
+ pub fn new(service_instance_id: Option<i32>) -> Option<TracingContext> {
+ match service_instance_id {
None => { None }
Some(id) => {
Some(TracingContext {
@@ -100,10 +100,10 @@
/// Default implementation of Context
impl Context for TracingContext {
- fn create_entry_span(&mut self, operation_name: &str, parent: Option<&Box<dyn Span>>, extractor: Option<&dyn Extractable>) -> Box<dyn Span> {
- 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<i32>, extractor: Option<&dyn Extractable>) -> Box<dyn Span> {
+ 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 @@
Box::new(entry_span)
}
- fn create_exit_span(&mut self, operation_name: &str, parent: Option<&Box<dyn Span>>, peer: &str, injector: Option<&dyn Injectable>) -> Box<dyn Span> {
- 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<i32>, peer: &str, injector: Option<&dyn Injectable>) -> Box<dyn Span> {
+ 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 @@
Box::new(exit_span)
}
- fn create_local_span(&mut self, operation_name: &str, parent: Option<&Box<dyn Span>>) -> Box<dyn Span> {
- 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<i32>) -> Box<dyn Span> {
+ 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 @@
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 @@
}
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 @@
#[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<Sender<TracingContext>>,
- recv: Box<Receiver<TracingContext>>,
+ sender: Box<Sender<Box<TracingContext>>>,
+ recv: Box<Receiver<Box<TracingContext>>>,
}
impl MockReporter {
@@ -214,7 +214,7 @@
Some(1)
}
- fn report_trace(&self, finished_context: TracingContext) {
+ fn report_trace(&self, finished_context: Box<TracingContext>) {
self.sender.send(finished_context);
}
}
@@ -235,16 +235,4 @@
assert_eq!(value.len() > 0, true);
}
}
-
- struct MockRegisterPending {}
-
- impl ContextListener for MockRegisterPending {
- fn service_instance_id(&self) -> Option<i32> {
- 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 @@
/// 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<TracingContext>);
}
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 @@
#[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 96%
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 @@
#[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 99%
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 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 @@
#[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 96%
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 @@
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 @@
#[cfg(test)]
mod tag_tests {
- use crate::Tag;
+ use crate::skywalking::core::Tag;
#[test]
fn test_tag_new() {
diff --git a/tracing-core/src/lib.rs b/core/src/skywalking/mod.rs
similarity index 64%
copy from tracing-core/src/lib.rs
copy to core/src/skywalking/mod.rs
index 7d9a2d1..08730c9 100644
--- a/tracing-core/src/lib.rs
+++ b/core/src/skywalking/mod.rs
@@ -13,23 +13,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub use context::Context;
-pub use context::TracingContext;
-pub use context_carrier::Extractable;
-pub use context_carrier::Injectable;
-pub use context_listener::ContextListener;
-pub use id::ID;
-pub use log::EventField;
-pub use log::LogEvent;
-pub use span::Span;
-pub use tag::Tag;
-
-pub mod span;
-pub mod context;
-pub mod tag;
-pub mod id;
-pub mod context_listener;
-pub mod log;
-pub mod context_carrier;
-pub mod segment_ref;
-
+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