Skip to content

Commit c863fe6

Browse files
committed
feat(Cel-Based Sampler): Minor changes from PR review
- Added @trask, @jack-berg and @breedx-splk as additional code owners - Added the project to the topmost README.md list of Provided Libraries - Made the list of expressions passed to the sampler immutable - Calculate the string representation of an expression on demand and not set it as a class private property
1 parent 55c88a8 commit c863fe6

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

.github/component_owners.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ components:
2727
- zeitlinger
2828
cel-sampler:
2929
- dol
30+
- trask
31+
- jack-berg
32+
- breedx-splk
3033
cloudfoundry-resources:
3134
- KarstenSchnitter
3235
compressors:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ feature or via instrumentation, this project is hopefully for you.
2121
| alpha | [AWS X-Ray Propagator](./aws-xray-propagator/README.md) |
2222
| alpha | [Baggage Processors](./baggage-processor/README.md) |
2323
| alpha | [zstd Compressor](./compressors/compressor-zstd/README.md) |
24+
| alpha | [CEL-Based Sampler](./cel-sampler/README.md) |
2425
| alpha | [Consistent Sampling](./consistent-sampling/README.md) |
2526
| alpha | [Disk Buffering](./disk-buffering/README.md) |
2627
| alpha | [GCP Authentication Extension](./gcp-auth-extension/README.md) |

cel-sampler/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ tracer_provider:
7575
## Component owners
7676

7777
* [Dominic Lüchinger](https://github.com/dol), SIX Group
78-
* TBD
78+
* [Jack Berg](https://github.com/jack-berg), New Relic
79+
* [Jason Plumb](https://github.com/breedx-splk), Splunk
80+
* [Trask Stalnaker](https://github.com/trask), Microsoft
7981

8082
Learn more about component owners in [component_owners.yml](../.github/component_owners.yml).

cel-sampler/src/main/java/io/opentelemetry/contrib/sampler/cel/CelBasedSampler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import io.opentelemetry.sdk.trace.data.LinkData;
2222
import io.opentelemetry.sdk.trace.samplers.Sampler;
2323
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
24+
import java.util.ArrayList;
25+
import java.util.Collections;
2426
import java.util.HashMap;
2527
import java.util.List;
2628
import java.util.Map;
@@ -67,7 +69,9 @@ public final class CelBasedSampler implements Sampler {
6769
* @param fallback The fallback sampler to use when no expressions match
6870
*/
6971
public CelBasedSampler(List<CelBasedSamplingExpression> expressions, Sampler fallback) {
70-
this.expressions = requireNonNull(expressions, "expressions must not be null");
72+
this.expressions =
73+
Collections.unmodifiableList(
74+
new ArrayList<>(requireNonNull(expressions, "expressions must not be null")));
7175
this.expressions.forEach(
7276
expr -> {
7377
if (!expr.getAbstractSyntaxTree().isChecked()) {
@@ -111,7 +115,7 @@ public SamplingResult shouldSample(
111115
CelRuntime.Program program = celRuntime.createProgram(expression.getAbstractSyntaxTree());
112116
Object result = program.eval(evaluationContext);
113117
// Happy path: Perform sampling based on the boolean result
114-
if (result instanceof Boolean && ((Boolean) result)) {
118+
if (Boolean.TRUE.equals(result)) {
115119
return expression
116120
.getDelegate()
117121
.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);

cel-sampler/src/main/java/io/opentelemetry/contrib/sampler/cel/CelBasedSamplingExpression.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
public final class CelBasedSamplingExpression {
2323
private final CelAbstractSyntaxTree abstractSyntaxTree;
24-
private final String expression;
2524
private final Sampler delegate;
2625

2726
/**
@@ -33,7 +32,6 @@ public final class CelBasedSamplingExpression {
3332
CelBasedSamplingExpression(CelAbstractSyntaxTree abstractSyntaxTree, Sampler delegate) {
3433
this.abstractSyntaxTree =
3534
requireNonNull(abstractSyntaxTree, "abstractSyntaxTree must not be null");
36-
this.expression = abstractSyntaxTree.getSource().getContent().toString();
3735
this.delegate = requireNonNull(delegate, "delegate must not be null");
3836
}
3937

@@ -52,7 +50,7 @@ CelAbstractSyntaxTree getAbstractSyntaxTree() {
5250
* @return The expression string
5351
*/
5452
String getExpression() {
55-
return expression;
53+
return abstractSyntaxTree.getSource().getContent().toString();
5654
}
5755

5856
/**
@@ -68,7 +66,7 @@ Sampler getDelegate() {
6866
public String toString() {
6967
return "CelBasedSamplingExpression{"
7068
+ "expression='"
71-
+ expression
69+
+ getExpression()
7270
+ "', delegate="
7371
+ delegate
7472
+ "}";
@@ -84,12 +82,12 @@ public boolean equals(@Nullable Object o) {
8482
}
8583
CelBasedSamplingExpression that = (CelBasedSamplingExpression) o;
8684
return Objects.equals(abstractSyntaxTree, that.abstractSyntaxTree)
87-
&& Objects.equals(expression, that.expression)
85+
&& Objects.equals(getExpression(), that.getExpression())
8886
&& Objects.equals(delegate, that.delegate);
8987
}
9088

9189
@Override
9290
public int hashCode() {
93-
return Objects.hash(abstractSyntaxTree, expression, delegate);
91+
return Objects.hash(abstractSyntaxTree, getExpression(), delegate);
9492
}
9593
}

0 commit comments

Comments
 (0)