Skip to content

Conversation

@jmjoy
Copy link
Member

@jmjoy jmjoy commented Jun 5, 2022

  1. Get current time as milliseconds rather than seconds.
  2. Fix parent span id.
  3. Add method to modify internal span object.


let mut span = Box::new(Span::new(
self.next_span_id,
-1,
Copy link
Member

Choose a reason for hiding this comment

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

Why hard code the span parent Span ID? Parent span ID should be the previous unfinished span in this tracing context.

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the mean of unfinished span? I think the left is correct, and right is incorrect.

Left Right
image image

Copy link
Member

Choose a reason for hiding this comment

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

If /status/500 fails, and retry /status/400 again, then yes, the right is correct.
But this example seems not relative to why hardcode parent span ID? The right logic is, parent span ID should be the latest unfinished span ID in this context/thread.
I don't mean the original codes are correct, I don't check so carefully. But the new one seems not correct at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I understand what you mean. In this case, the parent span ID should be set to the Span ID of the previous span that has not set end time. The code will change a lot.

Copy link
Member

Choose a reason for hiding this comment

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

I think you just need to add a current span ref in TracingContext, and always use it as parent span ID, unless a parent Span ref is given as new span's parameter.
The current span in TracingContext should be set to its parent when it is closed.

In the Java agent, we use a stack(implement through a LinkedList) to push/pop the active span.
You could take this as a good reference,

https://github.com/apache/skywalking-java/blob/372d75403053c1eb81d3cc4ec696a675fab1da71/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java#L80

Copy link
Member

Choose a reason for hiding this comment

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

I can see you did a lot of work on making rust-sdk in PHP ecosystem, and also helped our php-agent in skyapm org.
If you are willing to take more responsibility to this repo, this would be a very good start.

@Shikugawa implemented this for the first time, we have a lot to do to polish.


let span = Box::new(Span::new(
self.next_span_id,
0,
Copy link
Member

Choose a reason for hiding this comment

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

Why initial as 0?

@wu-sheng
Copy link
Member

wu-sheng commented Jun 8, 2022

Any update?

@jmjoy
Copy link
Member Author

jmjoy commented Jun 9, 2022

Any update?

No.

@wu-sheng wu-sheng added the stale No update for days label Jun 9, 2022
@jmjoy
Copy link
Member Author

jmjoy commented Jun 10, 2022

Is this solution OK? If possible, I will fix CI.

@wu-sheng
Copy link
Member

Is this solution OK? If possible, I will fix CI.

What solution? I left comments days ago. Wait for your reply.

@jmjoy
Copy link
Member Author

jmjoy commented Jun 10, 2022

Is this solution OK? If possible, I will fix CI.

What solution? I left comments days ago. Wait for your reply.

Sorry, I found that my comment is pending and I have to submit it. 😅

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2022

Codecov Report

Merging #20 (0fa7b1b) into master (d7baf4c) will increase coverage by 1.92%.
The diff coverage is 97.56%.

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
+ Coverage   84.94%   86.86%   +1.92%     
==========================================
  Files           9        9              
  Lines         279      297      +18     
==========================================
+ Hits          237      258      +21     
+ Misses         42       39       -3     
Impacted Files Coverage Δ
src/context/propagation/context.rs 100.00% <ø> (ø)
src/context/system_time.rs 0.00% <ø> (ø)
src/context/trace_context.rs 74.33% <90.00%> (+4.52%) ⬆️
tests/trace_context.rs 100.00% <100.00%> (ø)

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 d7baf4c...0fa7b1b. Read the comment docs.

@jmjoy
Copy link
Member Author

jmjoy commented Jun 11, 2022

I rewrite the logic of get the parent span id, please review.

Comment on lines 19 to 23
// pub mod skywalking_proto {
// pub mod v3 {
// tonic::include_proto!("skywalking.v3");
// }
// }
Copy link
Member

Choose a reason for hiding this comment

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

Why do you comment these lines?

@wu-sheng
Copy link
Member

The new one looks better, one questions
Do we expect trace context to only exist in one running thread? Just check, because officially, there are two concepts, (1) snapshot concept for across threads context propagation, and (2) async span mode for a span begins and finishes in two threads in other agent implementations.

Please fix e2e test.

@jmjoy
Copy link
Member Author

jmjoy commented Jun 13, 2022

The new one looks better, one questions Do we expect trace context to only exist in one running thread? Just check, because officially, there are two concepts, (1) snapshot concept for across threads context propagation, and (2) async span mode for a span begins and finishes in two threads in other agent implementations.

Please fix e2e test.

Fixed.

  1. Due to the concurrency mechanism of trust, TracingContext and Span should be modified to support multi threading. I think they should be modified in the next issue.
  2. There is no mechanism to ensure that the user calls finalize_span, I think it is better to implement Drop trait automatic call instead, and it can also be modified in the next issue.

@wu-sheng
Copy link
Member

Both are making sense. About (1), let's talk in a discussion/issue in the main repo about the details, to make you easier.

@wu-sheng wu-sheng added this to the 0.2.0 milestone Jun 13, 2022
@wu-sheng wu-sheng removed the stale No update for days label Jun 13, 2022
@wu-sheng wu-sheng added the enhancement New feature or request label Jun 13, 2022
@wu-sheng wu-sheng changed the title Fix time and parent span id. Enhance Trace Context machenism. Jun 13, 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