Skip to content

Commit 6e2eef7

Browse files
committed
Remove child-sampler warnings from ParentBasedSampler
1 parent 4af9078 commit 6e2eef7

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/samplers/ParentBasedSampler.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
import io.opentelemetry.context.Context;
1313
import io.opentelemetry.sdk.trace.data.LinkData;
1414
import java.util.List;
15-
import java.util.logging.Logger;
1615
import javax.annotation.Nullable;
1716
import javax.annotation.concurrent.Immutable;
1817

1918
/**
20-
* A Sampler that uses the sampled flag of the parent Span, if present. If the
21-
* span has no parent,
22-
* this Sampler will use the "root" sampler that it is built with. See
23-
* documentation on the {@link
24-
* ParentBasedSamplerBuilder} methods for the details on the various
25-
* configurable options.
19+
* A Sampler that uses the sampled flag of the parent Span, if present. If the span has no parent,
20+
* this Sampler will use the "root" sampler that it is built with. See documentation on the {@link
21+
* ParentBasedSamplerBuilder} methods for the details on the various configurable options.
2622
*/
2723
@Immutable
2824
final class ParentBasedSampler implements Sampler {
@@ -32,7 +28,6 @@ final class ParentBasedSampler implements Sampler {
3228
private final Sampler remoteParentNotSampled;
3329
private final Sampler localParentSampled;
3430
private final Sampler localParentNotSampled;
35-
private static final Logger logger = Logger.getLogger(ParentBasedSampler.class.getName());
3631

3732
ParentBasedSampler(
3833
Sampler root,
@@ -41,28 +36,17 @@ final class ParentBasedSampler implements Sampler {
4136
@Nullable Sampler localParentSampled,
4237
@Nullable Sampler localParentNotSampled) {
4338
this.root = root;
44-
this.remoteParentSampled = remoteParentSampled == null ? Sampler.alwaysOn() : remoteParentSampled;
45-
this.remoteParentNotSampled = remoteParentNotSampled == null ? Sampler.alwaysOff() : remoteParentNotSampled;
39+
this.remoteParentSampled =
40+
remoteParentSampled == null ? Sampler.alwaysOn() : remoteParentSampled;
41+
this.remoteParentNotSampled =
42+
remoteParentNotSampled == null ? Sampler.alwaysOff() : remoteParentNotSampled;
4643
this.localParentSampled = localParentSampled == null ? Sampler.alwaysOn() : localParentSampled;
47-
this.localParentNotSampled = localParentNotSampled == null ? Sampler.alwaysOff() : localParentNotSampled;
48-
warnIfTraceIdRatioBased(this.remoteParentSampled, "remoteParentSampled");
49-
warnIfTraceIdRatioBased(this.remoteParentNotSampled, "remoteParentNotSampled");
50-
warnIfTraceIdRatioBased(this.localParentSampled, "localParentSampled");
51-
warnIfTraceIdRatioBased(this.localParentNotSampled, "localParentNotSampled");
52-
}
53-
54-
private static void warnIfTraceIdRatioBased(Sampler sampler, String role) {
55-
if (sampler instanceof TraceIdRatioBasedSampler) {
56-
logger.warning(
57-
"TraceIdRatioBasedSampler is being used as a child sampler (" + role + "). "
58-
+ "This configuration is discouraged per the OpenTelemetry specification "
59-
+ "and may lead to unexpected sampling behavior.");
60-
}
44+
this.localParentNotSampled =
45+
localParentNotSampled == null ? Sampler.alwaysOff() : localParentNotSampled;
6146
}
6247

6348
// If a parent is set, always follows the same sampling decision as the parent.
64-
// Otherwise, uses the delegateSampler provided at initialization to make a
65-
// decision.
49+
// Otherwise, uses the delegateSampler provided at initialization to make a decision.
6650
@Override
6751
public SamplingResult shouldSample(
6852
Context parentContext,

0 commit comments

Comments
 (0)