Skip to content

Commit

Permalink
toString calls through getDescription (open-telemetry#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
XiXiaPdx authored Oct 15, 2020
1 parent 572d6ab commit 329d787
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
36 changes: 20 additions & 16 deletions sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/Samplers.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public SamplingResult shouldSample(
public String getDescription() {
return "AlwaysOnSampler";
}

@Override
public String toString() {
return getDescription();
}
}

@Immutable
Expand All @@ -203,6 +208,11 @@ public SamplingResult shouldSample(
public String getDescription() {
return "AlwaysOffSampler";
}

@Override
public String toString() {
return getDescription();
}
}

@Immutable
Expand Down Expand Up @@ -269,6 +279,11 @@ public String getDescription() {
this.localParentNotSampled.getDescription());
}

@Override
public String toString() {
return getDescription();
}

static class Builder {
private final Sampler root;
private Sampler remoteParentSampled;
Expand Down Expand Up @@ -375,22 +390,6 @@ public int hashCode() {
result = 31 * result + (localParentNotSampled != null ? localParentNotSampled.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "ParentBased{"
+ "root="
+ root
+ ", remoteParentSampled="
+ remoteParentSampled
+ ", remoteParentNotSampled="
+ remoteParentNotSampled
+ ", localParentSampled="
+ localParentSampled
+ ", localParentNotSampled="
+ localParentNotSampled
+ '}';
}
}

/**
Expand Down Expand Up @@ -461,6 +460,11 @@ public final SamplingResult shouldSample(
public final String getDescription() {
return String.format("TraceIdRatioBased{%.6f}", getRatio());
}

@Override
public final String toString() {
return getDescription();
}
}

@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ private static Sampler updateSampler(SamplingStrategyResponse response) {

@Override
public String getDescription() {
return this.toString();
return String.format("JaegerRemoteSampler{%s}", this.sampler);
}

@Override
public String toString() {
return String.format("JaegerRemoteSampler{%s}", this.sampler);
return getDescription();
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public SamplingResult shouldSample(

@Override
public String getDescription() {
return toString();
return String.format(
"PerOperationSampler{default=%s, perOperation=%s}",
this.defaultSampler, this.perOperationSampler);
}

@Override
public String toString() {
return String.format(
"PerOperationSampler{default=%s, perOperation=%s}",
this.defaultSampler, this.perOperationSampler);
return getDescription();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public SamplingResult shouldSample(

@Override
public String getDescription() {
return this.toString();
return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond);
}

@Override
public String toString() {
return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond);
return getDescription();
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void description() {
.setServiceName(SERVICE_NAME)
.build();
assertThat(sampler.getDescription())
.matches("JaegerRemoteSampler\\{TraceIdRatioBased\\{ratio=0.001, idUpperBound=.*\\}\\}");
.isEqualTo("JaegerRemoteSampler{TraceIdRatioBased{0.001000}}");

// wait until the sampling strategy is retrieved before exiting test method
await().atMost(10, TimeUnit.SECONDS).until(samplerIsType(sampler, RateLimitingSampler.class));
Expand Down

0 comments on commit 329d787

Please sign in to comment.