Skip to content

Auto finalize context and span when dropped.#28

Merged
wu-sheng merged 13 commits into
apache:masterfrom
jmjoy:drop
Jul 16, 2022
Merged

Auto finalize context and span when dropped.#28
wu-sheng merged 13 commits into
apache:masterfrom
jmjoy:drop

Conversation

@jmjoy

@jmjoy jmjoy commented Jul 15, 2022

Copy link
Copy Markdown
Member

Major changes have been made to automatically finalize context and span (more Rust-style).

  1. In order to automatically finalize when Drop is 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 implement Send (such as tokio::spawn), it needs to use the type Arc<Mutex<T>>. The Mutex here only uses try_lock, so it will not cause blocking.
  2. Removed TimeFetcher because it is only used for integration testing, and conditional compilation is a better choice for mocking.
  3. Added global tracer and related methods.

Comment thread Cargo.toml
async-stream = "0.3.3"
base64 = "0.13.0"
bytes = "1.1.0"
cfg-if = "1.0.0"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency cfg-ifalready exists, here re-import it.

Comment thread src/context/span.rs
/// }
/// ```
#[derive(Clone)]
pub struct Span {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move Span to a single mod.

.unwrap()
.as_millis() as i64
cfg_if! {
if #[cfg(feature = "mock")] {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use conditional compilation to mock fetching time.

Comment thread src/context/trace_context.rs Outdated
/// 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.");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/context/tracer.rs

/// Skywalking tracer.
pub struct Tracer<R: Reporter + Send + Sync + 'static> {
static GLOBAL_TRACER: OnceCell<Tracer> = OnceCell::const_new();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added global tracer and related methods.

@jmjoy jmjoy marked this pull request as ready for review July 15, 2022 15:35
@wu-sheng wu-sheng added this to the 0.3.0 milestone Jul 16, 2022
@wu-sheng wu-sheng added the enhancement New feature or request label Jul 16, 2022
Comment thread README.md
Comment thread README.md Outdated
Comment thread src/context/propagation/encoder.rs Outdated
Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
@codecov-commenter

codecov-commenter commented Jul 16, 2022

Copy link
Copy Markdown

Codecov Report

Merging #28 (e36a948) into master (0c43b32) will decrease coverage by 33.65%.
The diff coverage is 25.65%.

@@             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     
Impacted Files Coverage Δ
src/context/span.rs 0.00% <0.00%> (ø)
src/context/system_time.rs 0.00% <0.00%> (ø)
src/reporter/grpc.rs 0.00% <0.00%> (ø)
src/reporter/log.rs 0.00% <0.00%> (ø)
tests/trace_context.rs 0.00% <ø> (-100.00%) ⬇️
src/context/trace_context.rs 23.57% <24.77%> (-51.21%) ⬇️
src/context/tracer.rs 41.17% <36.66%> (+41.17%) ⬆️
src/context/propagation/encoder.rs 100.00% <100.00%> (ø)
tests/propagation.rs 100.00% <100.00%> (+3.22%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c43b32...e36a948. Read the comment docs.

@wu-sheng wu-sheng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once e2e passed.

@wu-sheng wu-sheng merged commit c544be8 into apache:master Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants