-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring TraceHeader Calls #361
Conversation
Codecov Report
@@ Coverage Diff @@
## master #361 +/- ##
============================================
+ Coverage 58.35% 58.38% +0.03%
- Complexity 1226 1228 +2
============================================
Files 133 133
Lines 5016 5015 -1
Branches 595 590 -5
============================================
+ Hits 2927 2928 +1
- Misses 1815 1816 +1
+ Partials 274 271 -3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
isSampled ? currentSubsegment.getId() : null, | ||
isSampled ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED); | ||
request.addHeader(TraceHeader.HEADER_KEY, header.toString()); | ||
request.addHeader(TraceHeader.HEADER_KEY, TraceHeader.fromEntity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code doesn't look equivalent to the one it's replacing.
In the left side code, the parent id as the TraceHeader argument is either currentSubsegment
's id or null
. Only the isSampled
is fetched from either previousSubsegment or the recorder.getCurrentSegment()
.
In the right side code, the whole TraceHeader will be created either from previousSubsegment
or currentSubsegment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, good catch! This was a bug.
I looked at the original code and I don't think we even need to use the previous subsegment here.
this.samplingStrategyOverride = samplingStrategyOverride; | ||
|
||
id = creator.getIdGenerator().newEntityId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this NoOpSubsegment
is never emitted and never propagated, can we set a static id here? We should avoid unnecessary computation if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
I added it when I noticed parentId was missing in NoOpSubsegments in trace headers. Then I saw we don't actually add it to the header when it is not sampled. Forgot to remove it after that.
@@ -43,6 +43,8 @@ static Segment noOp(TraceID traceId, AWSXRayRecorder recorder) { | |||
/** | |||
* @return the sampled | |||
*/ | |||
@JsonIgnore | |||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to necessarily override the isSampled()
method from Entity
?
Is it possible for Entity
types and subtypes to directly use this method from Entity
without an override?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, removed.
Issue #, if available:
Description of changes:
Problem 1
We have redundant code for creating a trace header.
Solution
Create a centralized function for creating trace headers from entities. This required NoOpSubsegment to have its traceId.
Problem 2
Why does NoOpSubsegment need a namespace and name? We have a bug where we are not correctly ending subsegments if they are NoOp. The subsegment gets created, but never ended by afterResponse because it is seen as a duplicate because its namespace and name is always empty.
Solution
Pass down the name and namespace in NoOpSubsegments.
https://github.com/aws/aws-xray-sdk-java/blob/master/aws-xray-recorder-sdk-aws-sdk/src/main/java/com/amazonaws/xray/handlers/TracingHandler.java
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.