Skip to content

Conversation

@yixunx
Copy link
Contributor

@yixunx yixunx commented Jun 3, 2019

Before this PR

Tracer.initTrace takes a slightly awkward approach to use an optional boolean to represent a tri-state (relevant discussion at #163 (comment))

After this PR

Added a new version of Tracer.initTrace that takes an enum instead of an optional boolean for the observability parameter. The old method that takes an optional is deprecated.

@yixunx
Copy link
Contributor Author

yixunx commented Jun 3, 2019

This is using the names @iamdanfox initially wrote in #163 (comment). I think these look clear enough, but let me know if you come up with better names for this.

@yixunx yixunx force-pushed the yx/refactor-optional-boolean branch from d319c94 to 434627e Compare June 3, 2019 18:50
return Observability.SAMPLER_DECIDES;
} else {
return Optional.of(header.equals("1"));
return header.equals("1") ? Observability.SAMPLE : Observability.DO_NOT_SAMPLE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Happy this no longer allocates 😄

return Observability.SAMPLER_DECIDES;
} else {
// No need to box the resulting boolean and allocate
// a new Optional wrapper for each invocation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably remove this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@yixunx yixunx changed the title [break] Refactor Tracer.initTrace to take enum instead of optional boolean [improvement] Refactor Tracer.initTrace to take enum instead of optional boolean Jun 4, 2019
@yixunx yixunx force-pushed the yx/refactor-optional-boolean branch from 67b283d to 9f3b64b Compare June 4, 2019 10:59
public enum Observability {
SAMPLE,
DO_NOT_SAMPLE,
SAMPLER_DECIDES

Choose a reason for hiding this comment

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

maybe consider UNDECIDED

@yixunx
Copy link
Contributor Author

yixunx commented Jun 4, 2019

Think I've addressed all existing comments, and this is good for another review

SAMPLE,
DO_NOT_SAMPLE,
UNDECIDED
}
Copy link
Contributor

@carterkozak carterkozak Jun 4, 2019

Choose a reason for hiding this comment

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

Mind adding docs to this class?

Big fan of this :-)

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

Generally lgtm, thanks for the deprecated backcompat methods.

private static Optional<Boolean> hasSampledHeader(ContainerRequestContext context) {
private static Observability getObservabilityFromHeader(ContainerRequestContext context) {
String header = context.getHeaderString(TraceHttpHeaders.IS_SAMPLED);
if (header == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a slight behavior change, but we may want Strings.isNullOrEmpty(header) here

Copy link
Contributor

Choose a reason for hiding this comment

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

In favor of this, would lead to less potential confusion down the line.

return Observability.UNDECIDED;
} else {
return Optional.of(header.equals("1"));
return header.equals("1") ? Observability.SAMPLE : Observability.DO_NOT_SAMPLE;
Copy link
Contributor

Choose a reason for hiding this comment

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

pedantic nit: would prefer "1".equals(header), though it won't make a difference in practice here since we've already validated non-null

@bulldozer-bot bulldozer-bot bot merged commit 28056fb into palantir:develop Jun 4, 2019
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