-
Notifications
You must be signed in to change notification settings - Fork 19
[improvement] Refactor Tracer.initTrace to take enum instead of optional boolean #166
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
[improvement] Refactor Tracer.initTrace to take enum instead of optional boolean #166
Conversation
|
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. |
d319c94 to
434627e
Compare
| return Observability.SAMPLER_DECIDES; | ||
| } else { | ||
| return Optional.of(header.equals("1")); | ||
| return header.equals("1") ? Observability.SAMPLE : Observability.DO_NOT_SAMPLE; |
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.
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. |
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.
Can probably remove this comment
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.
done
67b283d to
9f3b64b
Compare
| public enum Observability { | ||
| SAMPLE, | ||
| DO_NOT_SAMPLE, | ||
| SAMPLER_DECIDES |
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.
maybe consider UNDECIDED
|
Think I've addressed all existing comments, and this is good for another review |
| SAMPLE, | ||
| DO_NOT_SAMPLE, | ||
| UNDECIDED | ||
| } |
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.
Mind adding docs to this class?
Big fan of this :-)
carterkozak
left a comment
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.
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) { |
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.
It's a slight behavior change, but we may want Strings.isNullOrEmpty(header) 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.
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; |
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.
pedantic nit: would prefer "1".equals(header), though it won't make a difference in practice here since we've already validated non-null
Before this PR
Tracer.initTracetakes 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.initTracethat takes an enum instead of an optional boolean for the observability parameter. The old method that takes an optional is deprecated.