-
Notifications
You must be signed in to change notification settings - Fork 208
W3C : Tracecontext classes #775
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
Conversation
...ava/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java
Outdated
Show resolved
Hide resolved
...java/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Tracestate.java
Outdated
Show resolved
Hide resolved
| * | ||
| * Implementations can add vendor specific details here. | ||
| * | ||
| * @author Reiley Yang |
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.
Curious, why do we put author name here?
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.
Last time I've seen this was when I work on the C++ compiler, at that time there was no "git blame".
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.
Most Java libraries do this :) Its a common pattern in Java projects.
...ava/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java
Outdated
Show resolved
Hide resolved
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.
Looks good for now.
|
Please merge this to a working branch (e.g. w3c) instead of master. |
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.
We should not merge into master until feature complete.
Please create a feature branch and merge to it.
| /** | ||
| * 16 byte trace-id that is used to uniquely identify a distributed trace | ||
| */ | ||
| @VisibleForTesting final String traceId; |
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.
Since you have public accessors, you shouldn't need @VisibleForTesting. Same for spanId and traceFlags
| * @return boolean | ||
| */ | ||
| private static boolean isHex(String s, int n) { | ||
| if (s == null || s.length() == 0) { |
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.
One option is to Long.parseLong(s, 16) and if it throws NumberFormatException, return false.
Sometimes try/catch can be more performant, but if that's not a consideration at this point, I wouldn't worry about it. Also, I'd write a test to confirm prove it's more performant if you do choose that method.
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.
Yes, I and Reiley discussed this one. @reyang we should have this in final version. By the way, the catch here is also that only lower case should be there. I am not sure what parseLong will do for upper case.
| if (arr.length != 4) { | ||
| return null; | ||
| } | ||
| if (!isHex(arr[0], 2)) { |
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.
Depending on the usage here, you should consider replacing the isHex checks and instead assign the Character.digit calls to local variables, then check for -1 since the .digit method is doing these checks already.
| * | ||
| * Implementations can add vendor specific details here. | ||
| */ | ||
| @Experimental |
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.
Is something looking for these annotations?
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.
No I have marked this just because, ultimately this classes would be part of tracecontext libraray under different package name. Therefore, I just want to ensure no one depends on it.
| /** | ||
| * An 8-bit field that controls tracing flags such as sampling, trace level etc. | ||
| */ | ||
| @VisibleForTesting |
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.
Perhaps @VisibleForTesting isn't necessary since there are public accessors.
...ava/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java
Show resolved
Hide resolved
...ava/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java
Show resolved
Hide resolved
...ava/com/microsoft/applicationinsights/web/internal/correlation/tracecontext/Traceparent.java
Show resolved
Hide resolved
|
@littleaj as this is classes are not perhaps the final version, and there will be some refinements, merging this branch into feature branch and we shall iterate on it. |
|
@dhaval24 sounds good |
| * The constructor that tries to create Traceparent Object from given version, traceId, spanID | ||
| * and traceFlags. | ||
| */ | ||
| public Traceparent(int version, String traceId, String spanId, int traceFlags) { |
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.
int traceFlags why int? it's byte
| return null; | ||
| } | ||
|
|
||
| return new Traceparent( |
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.
so in some cases, when traceparent is not valid we return null and in some cases we throw. this is inconsistent. I'd prefer we never throw.
The problem is that if you've got bad traceparent - it's not even your fault and you cannot do anything about it.
Of course you can ask everyone who creates traceparent to catch exceptions and check for nulls, but it's easier to do this once in traceparent
And if it's not valid return a new one - with brand new values - that's what spec also states
| /** | ||
| * Field to capture tracestate header | ||
| */ | ||
| public final String reserved; |
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.
shouldn't it be private?
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.
I think so, this should be private. @reyang ?
|
This will be removed and replace by the actual implementation :) |
* W3C : Tracecontext classes (#775) * W3C Tracecontext * adding comments * addressing PR comments * Implement W3C tracestate * address review feedbacks * address review comments * W3C Integration (#782) * Initial integration of W3C protocol for incoming request * refactoring header name * updating the verbosity level when correlation fails * Fix bugs in correlation found via tests, implement more unit tests and address partial PR comments * improve createOutboundTracestate() * create tracestate when header not available * fix test * enable outbout w3c * Refactering code to use Helper methods with TraceContext classes * fix tracestate integration, fix outbound tracestate injection, fix tests, propogate traceflags * add property to turn on W3C in springboot starter, remove debug logs * adopt internal storage of id's to legacy AI format for backport, update tests * address PR comments * Fix an incorrect assert * refactor resolveCorrelation() method to be more readable and debuggable * rename method names, create outbound traceparent for http if there is no incoming request too * fixing a bug in w3c config for agent * fix the dependency type name, fix target to be host+port | target * update changelog and readme * Minor changes, add log trace to check W3C enabled on agent * adding support for backport with AI-Legacy-Correlation-Headers * adding tests for backward compatibility * address PR comments * add few tests, comments * add backport switch turn off test * reset after tests, to fix the build * adding tracing to understand when W3C is turned on for debugging * fix format string * fix a bug in creating correct target for dependencies
This PR brings in the required classes for integrating W3C correlation protocol.
Related #716
@reyang @lmolkova take a look.
For significant contributions please make sure you have completed the following items: