Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tracing/src/main/java/com/palantir/tracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ private Tracer() {}
*/
private static Trace createTrace(Optional<Boolean> isObservable, String traceId) {
Preconditions.checkArgument(traceId != null && !traceId.isEmpty(), "traceId must be non-empty: %s", traceId);
boolean observable = isObservable.orElseGet(sampler::sample);
boolean observable = shouldObserve(isObservable);
return new Trace(observable, traceId);
}

// Avoid lambda allocation on hot paths
@SuppressWarnings("OptionalIsPresent")
private static boolean shouldObserve(Optional<Boolean> isObservable) {
if (isObservable.isPresent()) {
return Boolean.TRUE.equals(isObservable.get());
}
return sampler.sample();
}

/**
* Initializes the current thread's trace, erasing any previously accrued open spans. The new trace is {@link
* Trace#isObservable observable} iff the given flag is true, or, iff {@code isObservable} is absent, if the {@link
Expand Down