Skip to content

Conversation

@dhaval24
Copy link
Contributor

@dhaval24 dhaval24 commented Nov 28, 2018

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:

  • Design discussion issue #
  • Changes in public surface reviewed
  • CHANGELOG.md updated

@dhaval24 dhaval24 self-assigned this Nov 28, 2018
@dhaval24 dhaval24 requested a review from littleaj November 28, 2018 19:25
*
* Implementations can add vendor specific details here.
*
* @author Reiley Yang
Copy link
Member

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?

Copy link
Member

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".

Copy link
Contributor Author

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.

Copy link
Member

@reyang reyang left a 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.

@reyang
Copy link
Member

reyang commented Nov 28, 2018

Please merge this to a working branch (e.g. w3c) instead of master.

Copy link
Member

@reyang reyang left a 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;
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@dhaval24 dhaval24 Nov 28, 2018

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)) {
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

@dhaval24 dhaval24 changed the base branch from master to W3CImplementation November 28, 2018 21:23
@dhaval24
Copy link
Contributor Author

@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 dhaval24 merged commit 76b2d92 into W3CImplementation Nov 28, 2018
@littleaj
Copy link
Contributor

@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) {

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(
Copy link

@lmolkova lmolkova Nov 29, 2018

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;

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?

Copy link
Contributor Author

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 ?

@reyang
Copy link
Member

reyang commented Nov 29, 2018

This will be removed and replace by the actual implementation :)

This was referenced Dec 7, 2018
dhaval24 added a commit that referenced this pull request Dec 15, 2018
* 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
@trask trask deleted the W3C/Implementation-Part-1 branch September 21, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants