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
This commit is contained in:
Dominic Lüchinger 2025-10-16 22:12:44 +02:00
parent 55c88a8bf6
commit c863fe6fc2
No known key found for this signature in database
5 changed files with 17 additions and 9 deletions

View File

@ -27,6 +27,9 @@ components:
- zeitlinger
cel-sampler:
- dol
- trask
- jack-berg
- breedx-splk
cloudfoundry-resources:
- KarstenSchnitter
compressors:

View File

@ -21,6 +21,7 @@ feature or via instrumentation, this project is hopefully for you.
| alpha | [AWS X-Ray Propagator](./aws-xray-propagator/README.md) |
| alpha | [Baggage Processors](./baggage-processor/README.md) |
| alpha | [zstd Compressor](./compressors/compressor-zstd/README.md) |
| alpha | [CEL-Based Sampler](./cel-sampler/README.md) |
| alpha | [Consistent Sampling](./consistent-sampling/README.md) |
| alpha | [Disk Buffering](./disk-buffering/README.md) |
| alpha | [GCP Authentication Extension](./gcp-auth-extension/README.md) |

View File

@ -75,6 +75,8 @@ tracer_provider:
## Component owners
* [Dominic Lüchinger](https://github.com/dol), SIX Group
* TBD
* [Jack Berg](https://github.com/jack-berg), New Relic
* [Jason Plumb](https://github.com/breedx-splk), Splunk
* [Trask Stalnaker](https://github.com/trask), Microsoft
Learn more about component owners in [component_owners.yml](../.github/component_owners.yml).

View File

@ -21,6 +21,8 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -67,7 +69,9 @@ public final class CelBasedSampler implements Sampler {
* @param fallback The fallback sampler to use when no expressions match
*/
public CelBasedSampler(List<CelBasedSamplingExpression> expressions, Sampler fallback) {
this.expressions = requireNonNull(expressions, "expressions must not be null");
this.expressions =
Collections.unmodifiableList(
new ArrayList<>(requireNonNull(expressions, "expressions must not be null")));
this.expressions.forEach(
expr -> {
if (!expr.getAbstractSyntaxTree().isChecked()) {
@ -111,7 +115,7 @@ public final class CelBasedSampler implements Sampler {
CelRuntime.Program program = celRuntime.createProgram(expression.getAbstractSyntaxTree());
Object result = program.eval(evaluationContext);
// Happy path: Perform sampling based on the boolean result
if (result instanceof Boolean && ((Boolean) result)) {
if (Boolean.TRUE.equals(result)) {
return expression
.getDelegate()
.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);

View File

@ -21,7 +21,6 @@ import javax.annotation.Nullable;
*/
public final class CelBasedSamplingExpression {
private final CelAbstractSyntaxTree abstractSyntaxTree;
private final String expression;
private final Sampler delegate;
/**
@ -33,7 +32,6 @@ public final class CelBasedSamplingExpression {
CelBasedSamplingExpression(CelAbstractSyntaxTree abstractSyntaxTree, Sampler delegate) {
this.abstractSyntaxTree =
requireNonNull(abstractSyntaxTree, "abstractSyntaxTree must not be null");
this.expression = abstractSyntaxTree.getSource().getContent().toString();
this.delegate = requireNonNull(delegate, "delegate must not be null");
}
@ -52,7 +50,7 @@ public final class CelBasedSamplingExpression {
* @return The expression string
*/
String getExpression() {
return expression;
return abstractSyntaxTree.getSource().getContent().toString();
}
/**
@ -68,7 +66,7 @@ public final class CelBasedSamplingExpression {
public String toString() {
return "CelBasedSamplingExpression{"
+ "expression='"
+ expression
+ getExpression()
+ "', delegate="
+ delegate
+ "}";
@ -84,12 +82,12 @@ public final class CelBasedSamplingExpression {
}
CelBasedSamplingExpression that = (CelBasedSamplingExpression) o;
return Objects.equals(abstractSyntaxTree, that.abstractSyntaxTree)
&& Objects.equals(expression, that.expression)
&& Objects.equals(getExpression(), that.getExpression())
&& Objects.equals(delegate, that.delegate);
}
@Override
public int hashCode() {
return Objects.hash(abstractSyntaxTree, expression, delegate);
return Objects.hash(abstractSyntaxTree, getExpression(), delegate);
}
}