Skip to content

Conversation

jaydeluca
Copy link
Member

@jaydeluca jaydeluca commented Aug 14, 2025

Related to #14128, part of #13468

Created a separate test suite for experimental attributes and enabled telemetry collection.

the checkstyle task was failing with:

[ant:checkstyle] [WARN] /home/runner/work/opentelemetry-java-instrumentation/opentelemetry-java-instrumentation/instrumentation/camel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ExperimentalTest.java:13: Please statically import methods from OpenTelemetryAssertions [RegexpSinglelineJava]

The regex is too strict and catching inner classes, which in this case can't be statically imported. I updated the pattern to exclude both regular and static imports from the package, and to allow uppercase class names while still catching lowercase method calls that should be statically imported.

@jaydeluca jaydeluca requested a review from a team as a code owner August 14, 2025 19:28
<module name="RegexpSinglelineJava">
<property name="format"
value="(?&lt;!import static io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\."/>
value="(?&lt;!import (?:static )?io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\.(?![A-Z]\w*[;\s]*)"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex is too strict and catching inner classes, which in this case can't be statically imported. I updated the pattern to exclude both regular and static imports from the package, and to allow uppercase class names while still catching lowercase method calls that should be statically imported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is quite hard to understand - can we make it 2 assertions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i simplified it a bit

<module name="RegexpSinglelineJava">
<property name="format"
value="(?&lt;!import static io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\."/>
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a negative lookahead here? would it work without?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the negative lookback it catches lines like import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

[ant:checkstyle] [WARN] /Users/jaydeluca/code/projects/opentelemetry-java-instrumentation/instrumentation/ca
mel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ExperimentalTest.jav
a:8: Please statically import methods from OpenTelemetryAssertions [RegexpSinglelineJava]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it now - maybe it's worth to add a comment explaining that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a comment here, do you have a suggestion on how it could be more clear? I tried to explain it with the

but allow inner classes (uppercase) and imports

<module name="RegexpSinglelineJava">
<property name="format"
value="(?&lt;!import static io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\."/>
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
<!-- negative lookahead for "import", because imports are handled by the rule below -->
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rule below is only for assertThat methods, but I pushed an update that calls out the lookahead being to exclude imports

@trask trask merged commit 5b1ad52 into open-telemetry:main Aug 15, 2025
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants