Skip to content

Commit b837e4c

Browse files
committed
Restore compliance between code and specs
The Composite Samplers based on Consistent Probability Sampling are described at https://github.com/open-telemetry/opentelemetry-specification/blob/v1.57.0/oteps/trace/0250-Composite_Samplers.md
1 parent 79608eb commit b837e4c

18 files changed

Lines changed: 35 additions & 50 deletions

File tree

sdk-extensions/declarative-config/src/main/java/io/opentelemetry/sdk/autoconfigure/declarativeconfig/ComposableRuleBasedSamplerFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static final class DeclarativeConfigSamplingPredicate implements SamplingPredica
135135
@Override
136136
public boolean matches(
137137
Context parentContext,
138-
String traceId,
139138
String name,
140139
SpanKind spanKind,
141140
Attributes attributes,

sdk-extensions/declarative-config/src/test/java/io/opentelemetry/sdk/autoconfigure/declarativeconfig/ComposableRuleBasedSamplerFactoryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ private static Stream<Arguments> createTestCases() {
254254
IdGenerator.random().generateSpanId(),
255255
TraceFlags.getDefault(),
256256
TraceState.getDefault())));
257-
private static final String tid = IdGenerator.random().generateTraceId();
258257
private static final String sn = "name";
259258
private static final io.opentelemetry.api.trace.SpanKind sk = CLIENT;
260259
private static final AttributeKey<String> HTTP_ROUTE = AttributeKey.stringKey("http.route");
@@ -268,7 +267,7 @@ void declarativeConfigSamplingPredicate(
268267
io.opentelemetry.api.trace.SpanKind spanKind,
269268
Attributes attributes,
270269
boolean expectedResult) {
271-
assertThat(predicate.matches(context, tid, sn, spanKind, attributes, emptyList()))
270+
assertThat(predicate.matches(context, sn, spanKind, attributes, emptyList()))
272271
.isEqualTo(expectedResult);
273272
}
274273

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableAlwaysOffSampler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ enum ComposableAlwaysOffSampler implements ComposableSampler {
1919
@Override
2020
public SamplingIntent getSamplingIntent(
2121
Context parentContext,
22-
String traceId,
2322
String name,
2423
SpanKind spanKind,
2524
Attributes attributes,

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableAlwaysOnSampler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ enum ComposableAlwaysOnSampler implements ComposableSampler {
1818
private static final SamplingIntent INTENT =
1919
SamplingIntent.create(
2020
ImmutableSamplingIntent.MIN_THRESHOLD,
21-
/* thresholdReliable= */ true,
21+
/* adjustedCountReliable= */ true,
2222
Attributes.empty(),
2323
Function.identity());
2424

2525
@Override
2626
public SamplingIntent getSamplingIntent(
2727
Context parentContext,
28-
String traceId,
2928
String name,
3029
SpanKind spanKind,
3130
Attributes attributes,

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableAnnotatingSampler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ final class ComposableAnnotatingSampler implements ComposableSampler {
2727
@Override
2828
public SamplingIntent getSamplingIntent(
2929
Context parentContext,
30-
String traceId,
3130
String name,
3231
SpanKind spanKind,
3332
Attributes attributes,
3433
List<LinkData> parentLinks) {
3534
SamplingIntent intent =
36-
delegate.getSamplingIntent(parentContext, traceId, name, spanKind, attributes, parentLinks);
35+
delegate.getSamplingIntent(parentContext, name, spanKind, attributes, parentLinks);
3736
return SamplingIntent.create(
3837
intent.getThreshold(),
39-
intent.isThresholdReliable(),
38+
intent.isAdjustedCountReliable(),
4039
intent.getAttributes().toBuilder().putAll(this.attributes).build(),
4140
intent.getTraceStateUpdater());
4241
}

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableParentThresholdSampler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,28 @@ final class ComposableParentThresholdSampler implements ComposableSampler {
3131
@Override
3232
public SamplingIntent getSamplingIntent(
3333
Context parentContext,
34-
String traceId,
3534
String name,
3635
SpanKind spanKind,
3736
Attributes attributes,
3837
List<LinkData> parentLinks) {
3938
SpanContext parentSpanContext = Span.fromContext(parentContext).getSpanContext();
4039
if (!parentSpanContext.isValid()) {
41-
return rootSampler.getSamplingIntent(
42-
parentContext, traceId, name, spanKind, attributes, parentLinks);
40+
return rootSampler.getSamplingIntent(parentContext, name, spanKind, attributes, parentLinks);
4341
}
4442

4543
OtelTraceState otTraceState = OtelTraceState.parse(parentSpanContext.getTraceState());
4644
if (isValidThreshold(otTraceState.getThreshold())) {
4745
return ImmutableSamplingIntent.create(
4846
otTraceState.getThreshold(),
49-
/* thresholdReliable= */ true,
47+
/* adjustedCountReliable= */ true,
5048
Attributes.empty(),
5149
Function.identity());
5250
}
5351

5452
long threshold =
5553
parentSpanContext.getTraceFlags().isSampled() ? MIN_THRESHOLD : INVALID_THRESHOLD;
5654
return ImmutableSamplingIntent.create(
57-
threshold, /* thresholdReliable= */ false, Attributes.empty(), Function.identity());
55+
threshold, /* adjustedCountReliable= */ false, Attributes.empty(), Function.identity());
5856
}
5957

6058
@Override

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableProbabilitySampler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private static long calculateThreshold(double ratio) {
3333
this.intent =
3434
SamplingIntent.create(
3535
ImmutableSamplingIntent.INVALID_THRESHOLD,
36-
/* thresholdReliable= */ false,
36+
/* adjustedCountReliable= */ false,
3737
Attributes.empty(),
3838
Function.identity());
3939
} else {
@@ -43,7 +43,10 @@ private static long calculateThreshold(double ratio) {
4343

4444
this.intent =
4545
SamplingIntent.create(
46-
threshold, /* thresholdReliable= */ true, Attributes.empty(), Function.identity());
46+
threshold,
47+
/* adjustedCountReliable= */ true,
48+
Attributes.empty(),
49+
Function.identity());
4750
}
4851
this.description =
4952
"ComposableTraceIdRatioBasedSampler{threshold=" + thresholdStr + ", ratio=" + ratio + "}";
@@ -52,7 +55,6 @@ private static long calculateThreshold(double ratio) {
5255
@Override
5356
public SamplingIntent getSamplingIntent(
5457
Context parentContext,
55-
String traceId,
5658
String name,
5759
SpanKind spanKind,
5860
Attributes attributes,

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableRuleBasedSampler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ final class ComposableRuleBasedSampler implements ComposableSampler {
4141
@Override
4242
public SamplingIntent getSamplingIntent(
4343
Context parentContext,
44-
String traceId,
4544
String name,
4645
SpanKind spanKind,
4746
Attributes attributes,
4847
List<LinkData> parentLinks) {
4948
for (SamplingRule rule : rules) {
50-
if (rule.predicate()
51-
.matches(parentContext, traceId, name, spanKind, attributes, parentLinks)) {
49+
if (rule.predicate().matches(parentContext, name, spanKind, attributes, parentLinks)) {
5250
return rule.sampler()
53-
.getSamplingIntent(parentContext, traceId, name, spanKind, attributes, parentLinks);
51+
.getSamplingIntent(parentContext, name, spanKind, attributes, parentLinks);
5452
}
5553
}
5654
return NON_SAMPLING_INTENT;

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/ComposableSampler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static ComposableSampler annotating(ComposableSampler sampler, Attributes attrib
5656
/** Returns the {@link SamplingIntent} to use to make a sampling decision. */
5757
SamplingIntent getSamplingIntent(
5858
Context parentContext,
59-
String traceId,
6059
String name,
6160
SpanKind spanKind,
6261
Attributes attributes,

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/samplers/CompositeSampler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public SamplingResult shouldSample(
5353
OtelTraceState otelTraceState = OtelTraceState.parse(traceState);
5454

5555
SamplingIntent intent =
56-
delegate.getSamplingIntent(parentContext, traceId, name, spanKind, attributes, parentLinks);
56+
delegate.getSamplingIntent(parentContext, name, spanKind, attributes, parentLinks);
5757

58-
boolean thresholdReliable = false;
58+
boolean adjustedCountReliable = false;
5959
boolean sampled = false;
6060
if (isValidThreshold(intent.getThreshold())) {
61-
thresholdReliable = intent.isThresholdReliable();
61+
adjustedCountReliable = intent.isAdjustedCountReliable();
6262
long randomValue;
63-
if (thresholdReliable) {
63+
if (adjustedCountReliable) {
6464
if (isValidRandomValue(otelTraceState.getRandomValue())) {
6565
randomValue = otelTraceState.getRandomValue();
6666
} else {
@@ -75,7 +75,7 @@ public SamplingResult shouldSample(
7575

7676
SamplingDecision decision =
7777
sampled ? SamplingDecision.RECORD_AND_SAMPLE : SamplingDecision.DROP;
78-
if (sampled && thresholdReliable) {
78+
if (sampled && adjustedCountReliable) {
7979
otelTraceState =
8080
new OtelTraceState(
8181
otelTraceState.getRandomValue(), intent.getThreshold(), otelTraceState.getRest());

0 commit comments

Comments
 (0)