Skip to content

Implement W3C tracestate#779

Merged
reyang merged 3 commits into
W3CImplementationfrom
reiley/w3c
Dec 4, 2018
Merged

Implement W3C tracestate#779
reyang merged 3 commits into
W3CImplementationfrom
reiley/w3c

Conversation

@reyang

@reyang reyang commented Dec 4, 2018

Copy link
Copy Markdown
Member

* Field to capture tracestate header
* Internal representation of the tracestate
*/
private LinkedHashMap<String, String> internalList = new LinkedHashMap<String, String>(32);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A good practice to follow is use Interface.
Map<String, String> internalList = new LinkedHashMap<>(32). You also need not specify the types in diamond operator twice. By the way, LinkedHashMap is used to maintain insertion order. Do you need to maintain that order here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is 32 the max limit according to spec?

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.

for (String item : values) {
Matcher m = MEMBER_FORMAT_RE.matcher(item);
if (!m.find()) {
throw new IllegalArgumentException(String.format("invalid string %s in tracestate", item));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, within Application Insights the practice that was followed was to not throw only, but do try - catch and Log. So that we don't break users application. Do we want to throw here (for generic library purpose and use try catch in implementation)?

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.

From class implementation perspective, it makes sense to throw if invalid argument is passed in.
For integration, we need to swallow the exception and ignore the broken header according to the W3C spec.

/**
* Ctor that creates a tracestate object from a parent one
*/
public Tracestate(Tracestate parent, String key, String value) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For application insights case we need another helper method also - which can basically swap the value of the azure key. Should this helper reside here? If not we would need to have almost similar method in the AI implementation.

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.

Can we use new Tracestate(tracestate, "key", "new value")?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should work

@dhaval24 dhaval24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general this looks fine, though I am bit worried how will regex evaluation impact performance. In general if the tracestate is long enough than every eval operation would be O(N) where N is the size of tracestate. All this happens in request hot path. Though it should be fine for now.

@dhaval24 dhaval24 requested review from littleaj and lmolkova December 4, 2018 19:18
@reyang reyang merged commit edcb47a into W3CImplementation Dec 4, 2018
@trask trask deleted the reiley/w3c branch September 21, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants