Skip to content

Commit 329d787

Browse files
authored
toString calls through getDescription (#1813)
1 parent 572d6ab commit 329d787

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/Samplers.java

+20-16
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ public SamplingResult shouldSample(
181181
public String getDescription() {
182182
return "AlwaysOnSampler";
183183
}
184+
185+
@Override
186+
public String toString() {
187+
return getDescription();
188+
}
184189
}
185190

186191
@Immutable
@@ -203,6 +208,11 @@ public SamplingResult shouldSample(
203208
public String getDescription() {
204209
return "AlwaysOffSampler";
205210
}
211+
212+
@Override
213+
public String toString() {
214+
return getDescription();
215+
}
206216
}
207217

208218
@Immutable
@@ -269,6 +279,11 @@ public String getDescription() {
269279
this.localParentNotSampled.getDescription());
270280
}
271281

282+
@Override
283+
public String toString() {
284+
return getDescription();
285+
}
286+
272287
static class Builder {
273288
private final Sampler root;
274289
private Sampler remoteParentSampled;
@@ -375,22 +390,6 @@ public int hashCode() {
375390
result = 31 * result + (localParentNotSampled != null ? localParentNotSampled.hashCode() : 0);
376391
return result;
377392
}
378-
379-
@Override
380-
public String toString() {
381-
return "ParentBased{"
382-
+ "root="
383-
+ root
384-
+ ", remoteParentSampled="
385-
+ remoteParentSampled
386-
+ ", remoteParentNotSampled="
387-
+ remoteParentNotSampled
388-
+ ", localParentSampled="
389-
+ localParentSampled
390-
+ ", localParentNotSampled="
391-
+ localParentNotSampled
392-
+ '}';
393-
}
394393
}
395394

396395
/**
@@ -461,6 +460,11 @@ public final SamplingResult shouldSample(
461460
public final String getDescription() {
462461
return String.format("TraceIdRatioBased{%.6f}", getRatio());
463462
}
463+
464+
@Override
465+
public final String toString() {
466+
return getDescription();
467+
}
464468
}
465469

466470
@Immutable

sdk_extensions/jaeger_remote_sampler/src/main/java/io/opentelemetry/sdk/extensions/trace/jaeger/sampler/JaegerRemoteSampler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ private static Sampler updateSampler(SamplingStrategyResponse response) {
103103

104104
@Override
105105
public String getDescription() {
106-
return this.toString();
106+
return String.format("JaegerRemoteSampler{%s}", this.sampler);
107107
}
108108

109109
@Override
110110
public String toString() {
111-
return String.format("JaegerRemoteSampler{%s}", this.sampler);
111+
return getDescription();
112112
}
113113

114114
@VisibleForTesting

sdk_extensions/jaeger_remote_sampler/src/main/java/io/opentelemetry/sdk/extensions/trace/jaeger/sampler/PerOperationSampler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public SamplingResult shouldSample(
5151

5252
@Override
5353
public String getDescription() {
54-
return toString();
54+
return String.format(
55+
"PerOperationSampler{default=%s, perOperation=%s}",
56+
this.defaultSampler, this.perOperationSampler);
5557
}
5658

5759
@Override
5860
public String toString() {
59-
return String.format(
60-
"PerOperationSampler{default=%s, perOperation=%s}",
61-
this.defaultSampler, this.perOperationSampler);
61+
return getDescription();
6262
}
6363
}

sdk_extensions/jaeger_remote_sampler/src/main/java/io/opentelemetry/sdk/extensions/trace/jaeger/sampler/RateLimitingSampler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public SamplingResult shouldSample(
7272

7373
@Override
7474
public String getDescription() {
75-
return this.toString();
75+
return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond);
7676
}
7777

7878
@Override
7979
public String toString() {
80-
return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond);
80+
return getDescription();
8181
}
8282

8383
@VisibleForTesting

sdk_extensions/jaeger_remote_sampler/src/test/java/io/opentelemetry/sdk/extensions/trace/jaeger/sampler/JaegerRemoteSamplerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void description() {
113113
.setServiceName(SERVICE_NAME)
114114
.build();
115115
assertThat(sampler.getDescription())
116-
.matches("JaegerRemoteSampler\\{TraceIdRatioBased\\{ratio=0.001, idUpperBound=.*\\}\\}");
116+
.isEqualTo("JaegerRemoteSampler{TraceIdRatioBased{0.001000}}");
117117

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

0 commit comments

Comments
 (0)