Auto finalize context and span when dropped.#28
Conversation
| async-stream = "0.3.3" | ||
| base64 = "0.13.0" | ||
| bytes = "1.1.0" | ||
| cfg-if = "1.0.0" |
There was a problem hiding this comment.
Dependency cfg-ifalready exists, here re-import it.
| /// } | ||
| /// ``` | ||
| #[derive(Clone)] | ||
| pub struct Span { |
There was a problem hiding this comment.
Move Span to a single mod.
| .unwrap() | ||
| .as_millis() as i64 | ||
| cfg_if! { | ||
| if #[cfg(feature = "mock")] { |
There was a problem hiding this comment.
Use conditional compilation to mock fetching time.
| /// Panic if entry span have already exist. | ||
| pub fn create_entry_span(&mut self, operation_name: &str) -> Span { | ||
| if self.next_span_id() >= 1 { | ||
| panic!("entry span have already exist."); |
There was a problem hiding this comment.
Use panic instead of returning error, because it is caused by the programmer's incorrect usage, not external input. If there is a need to return an error in the future, can add a try_ prefix method.
|
|
||
| /// Skywalking tracer. | ||
| pub struct Tracer<R: Reporter + Send + Sync + 'static> { | ||
| static GLOBAL_TRACER: OnceCell<Tracer> = OnceCell::const_new(); |
There was a problem hiding this comment.
Added global tracer and related methods.
Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
Codecov Report
@@ Coverage Diff @@
## master #28 +/- ##
===========================================
- Coverage 75.29% 41.63% -33.66%
===========================================
Files 10 12 +2
Lines 344 281 -63
===========================================
- Hits 259 117 -142
- Misses 85 164 +79
Continue to review full report at Codecov.
|
Major changes have been made to automatically finalize context and span (more Rust-style).
Dropis implemented, the creator needs to be referenced on the struct, such as context reference tracer, span reference context, and reference counting needs to be used. Since async task usually needs to implementSend(such astokio::spawn), it needs to use the typeArc<Mutex<T>>. TheMutexhere only usestry_lock, so it will not cause blocking.TimeFetcherbecause it is only used for integration testing, and conditional compilation is a better choice for mocking.