-
Notifications
You must be signed in to change notification settings - Fork 168
Common Expression Language (CEL) sampler #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@dol this looks nice! @johnbley what do you think of CEL vs JEXL in the context of open-telemetry/opentelemetry-java-instrumentation#13590? |
Just a note to myself. I need to expand the test cases with the following addition.
|
Very interesting! I'll take a look at it! |
As I refined the tests I found some edge cases in the setup and mapping of the CEL engine. I'll mark the PR as work in progress. Sorry for that. |
no worries! you can click "Convert to draft" (hidden under the list of reviewers), and then when you're ready you can click "Ready for review" |
@trask @jack-berg : I wanted you to give an update on the PR. As I was adding more tests cases to PR I encountered a problem with single/double quote parsing on the declarative config. First I though it's an issue with a complex expression input. But after digging deep into the source code of this project and I created the following bug report: open-telemetry/opentelemetry-java#7429 As the chances are very high that a complex expression will need to mix single and double quotes, this bug should be addressed first. |
open-telemetry/opentelemetry-java#7433 should fix this regression. |
The latest version added more unit tests and better coverage. I think the new CEL sampler is ready for an review. |
Build is pretty broken. Can you look at this @dol thanks! |
@breedx-splk I'm waiting for the |
@jack-berg @trask The PR is ready for review after the fix was merged and release ( open-telemetry/opentelemetry-java#7433 ) and the BOM version was bumped ( 850933f#diff-df7d51fc1db73056c56958a9784e26310dae8ec239fb940820f5ddea4b655693L5 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this is an awesome addition that users will start trying immediately. I left a few comments/questions that I'd like to see addressed...but this is looking solid.
samplers/src/main/java/io/opentelemetry/contrib/sampler/CelBasedSamplingExpression.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/opentelemetry/contrib/sampler/internal/CelBasedSamplerComponentProvider.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/internal/CelBasedSamplerComponentProviderTest.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/internal/CelBasedSamplerComponentProviderTest.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/internal/CelBasedSamplerComponentProviderTest.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/io/opentelemetry/contrib/sampler/CelBasedSamplerTest.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/io/opentelemetry/contrib/sampler/CelBasedSamplerTest.java
Outdated
Show resolved
Hide resolved
samplers/src/test/java/io/opentelemetry/contrib/sampler/CelBasedSamplerTest.java
Outdated
Show resolved
Hide resolved
029ff17
to
3328c31
Compare
@breedx-splk Thank you for the valuable review. I addressed all the remarks. |
50b7e21
to
e197503
Compare
@dol looks like there are some merge conflicts now... |
e197503
to
f80ebb1
Compare
@breedx-splk Thx for the hint. The merge conflict is resolved. |
I've added this PR as a topic for tomorrow's Java SIG meeting to get a few more eyes on it, in particular since this module is automatically pulled in and available in the OpenTelemetry Java agent (@dol you're of course welcome to join if you'd like!) |
+ "localParentNotSampled:AlwaysOffSampler" | ||
+ "}"); | ||
|
||
// SERVER span to other path should be recorded and sampled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one matches the first expression?
// SERVER span to other path should be recorded and sampled | |
// SERVER span with host header and 200 response is dropped due to matching with first expression. |
I'm not against putting this into For clarity, I'm raising a possible future idea, not trying to derail the current work here which looks good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dol thank you for your patience and understanding with this PR.
We definitely think there is room for this sampler to exist, and many of us really appreciate the flexibility that the CEL brings here. We also think that @johnbley 's idea about OTTL is also interesting, but no implementation of OTTL yet exists in java...but maybe one day! 🤞🏻
So as @trask suggested above, we did indeed talk about this in the SIG meeting this week. The conclusion was that we think it would be best to introduce this as a new contrib module instead of adding it to the existing samplers module. Doing that allows the existing stable java instrumentation agent to continue depending on the existing samplers module, without introducing new dependencies or opening up any potential expression exploit/vulnerability that might be dreamed up.
Based on this, I'm going to request changes on this PR in hopes that you can either adjust this one or make a new one that creates a new gradle module. I hope you understand and can work with us to get this great work merged.
Thanks again for the contribution and looking forward to seeing it land as a new module here.
@breedx-splk Thanks for the clarification on how to go forward. I'll go ahead and perform the requested changes to outsource the CEL sampler to it's own gradle module. I was not aware that the OTEL collector already has a similar approeach in complex filtering with it's own DSL, the |
Adds new CelBasedSampler to the OpenTelemetry Java SDK, enabling advanced sampling rules using the Common Expression Language (CEL).
c930856
to
55c88a8
Compare
@breedx-splk It's now it's own dedicated gradle module. I messed up the rebase and it included more commits then expected. As a consequence the github-action bot included a lot more reviewers. 🙇 Sorry for spamming additional code owners. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nearly there! I had a few small comments, and I do think it's helpful to expand the component owners list. Please also add this project to the topmost README.md
in the repo.
Thanks again!
cel-sampler/src/main/java/io/opentelemetry/contrib/sampler/cel/CelBasedSamplingExpression.java
Show resolved
Hide resolved
cel-sampler/src/main/java/io/opentelemetry/contrib/sampler/cel/CelBasedSampler.java
Outdated
Show resolved
Hide resolved
cel-sampler/src/main/java/io/opentelemetry/contrib/sampler/cel/CelBasedSampler.java
Outdated
Show resolved
Hide resolved
Already doing follow-up reviews. Getting close to approval!
- 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
a5748f3
to
c863fe6
Compare
This pull request introduces a new
CelBasedSampler
to the OpenTelemetry Java SDK, enabling advanced sampling rules using the Common Expression Language (CEL). It also includes updates to the existingRuleBasedRoutingSampler
for consistency and clarity. Below is a summary of the most important changes grouped by theme:New
CelBasedSampler
Implementation:CelBasedSampler
class, which evaluates CEL expressions to make sampling decisions based on span attributes. It includes a fallback sampler and supports multiple expressions. (samplers/src/main/java/io/opentelemetry/contrib/sampler/CelBasedSampler.java
)CelBasedSamplerBuilder
to constructCelBasedSampler
instances with methods for adding expressions and specifying actions (e.g.,DROP
orRECORD_AND_SAMPLE
). (samplers/src/main/java/io/opentelemetry/contrib/sampler/CelBasedSamplerBuilder.java
)CelBasedSamplingExpression
class to encapsulate individual CEL expressions and their associated samplers. (samplers/src/main/java/io/opentelemetry/contrib/sampler/CelBasedSamplingExpression.java
)CelBasedSampler
, enabling configuration through YAML files. (samplers/src/main/java/io/opentelemetry/contrib/sampler/internal/CelBasedSamplerComponentProvider.java
)Documentation Updates:
samplers/README.md
to document the newCelBasedSampler
, including its usage, schema, and example configurations. (samplers/README.md
) [1] [2]Dependency Additions:
dev.cel:cel:0.9.0
library to enable CEL expression evaluation. (samplers/build.gradle.kts
)Updates to
RuleBasedRoutingSampler
:SamplingRule
toRuleBasedRoutingSamplingRule
for clarity and updated all related references in theRuleBasedRoutingSampler
and its builder. (samplers/src/main/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSampler.java
,samplers/src/main/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSamplerBuilder.java
,samplers/src/main/java/io/opentelemetry/contrib/sampler/RuleBasedRoutingSamplingRule.java
) [1] [2] [3] [4] [5] [6] [7]These changes collectively enhance the SDK's sampling capabilities, allowing users to define sophisticated sampling rules using CEL while maintaining compatibility with existing samplers.