Skip to content
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

setStatus method conforms to the specified behavior regarding status … #6808

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Victorsesan
Copy link

…code priorities and description handling

Relate to #6797

@Victorsesan Victorsesan requested a review from a team as a code owner October 21, 2024 01:16
this.status = StatusData.create(statusCode, description);
}
return this;
synchronized (lock) {
Copy link
Member

Choose a reason for hiding this comment

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

We use spotless to ensure consist code formatting. Please run ./gradlew spotlessApply.

@@ -418,22 +418,37 @@ private void addTimedEvent(EventData timedEvent) {

@Override
public ReadWriteSpan setStatus(StatusCode statusCode, @Nullable String description) {
if (statusCode == null) {
return this;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this?


// Prevent setting a lower priority status
if (currentStatusCode == StatusCode.OK) {
logger.log(Level.FINE, "Calling setStatus() on a Span that is already set to OK.");
Copy link
Member

Choose a reason for hiding this comment

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

Only log a warning the target status code is != StatusCode.OK.

if (statusCode == StatusCode.ERROR) {
this.status = StatusData.create(statusCode, description); // Allow description for ERROR
} else {
this.status = StatusData.create(statusCode, null); // Ignore description for non-ERROR statuses
Copy link
Member

Choose a reason for hiding this comment

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

#nit: Let's skip the extra allocation if the status code doesn't stand to change.

Suggested change
this.status = StatusData.create(statusCode, null); // Ignore description for non-ERROR statuses
if (currentStatusCode != statusCode) {
this.status = StatusData.create(statusCode, null); // Ignore description for non-ERROR statuses
}

@Victorsesan
Copy link
Author

@jack-berg I have fix and added the suggestions as required, sorry for the delay and all the hassle i had so many mistake trying to fix and find a way to run ./gradlew spotlessApply which made me rewrite most of the time from scratch. I have spend hours with every trick there is trying to setup gradle and jdk on my console to run spotless but it keeps showing unable to detect jdk 17 and gradle. Please do let me know if there are still any corrections to be made from the new PR and if by chance there is another method i can go about to ensure the consist code formatting on my PR. thanks

@jack-berg
Copy link
Member

I have spend hours with every trick there is trying to setup gradle and jdk on my console to run spotless but it keeps showing unable to detect jdk 17 and gradle.

Yes the build requires jdk 17, and gradle detects jdk versions in a very specific way as documented here: https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection

My personal preference for installing / managing JDKs is to use sdkman!, which makes it super easy to install multiple versions and toggle between them as needed. Gradle will automatically look for jdks that match the project requirements where sdkman installs them.

@Victorsesan
Copy link
Author

Victorsesan commented Oct 24, 2024

Screenshot 2024-10-24 162139
@jack-berg I finally got jdk 17 running with sdkman! I'm very excited! though the setup couldn't have been completed without the help of wsl but still i got it up and ruuning.
Edit: I think it worked this time! please check my recent commits and see the changes i made, if there is any redo or correction that is needed i will be happy to. Thanks for your time

*Gradle build in build.gradle.kts had failed during spotless check because the plugin org.graalvm.buildtools.native was not found
-Solution: I have applied a plugin and made it work

*spotlessJavaCheck task failed because certain files did not conform to the formatting rules defined in the Spotless configuration
-Solution: Initiated an auto fix using ./gradlew :sdk:trace:spotlessApply

*Lastly as requested i initiated
./gradlew spotlessApply to ensure a consist code formating and the build was successful with no errors!

Relate to open-telemetry#6797
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.

Project coverage is 90.47%. Comparing base (5ec1e86) to head (7991abf).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
.../main/java/io/opentelemetry/sdk/trace/SdkSpan.java 71.42% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6808      +/-   ##
============================================
+ Coverage     90.38%   90.47%   +0.09%     
- Complexity     6584     6602      +18     
============================================
  Files           731      731              
  Lines         19722    19742      +20     
  Branches       1931     1938       +7     
============================================
+ Hits          17825    17862      +37     
+ Misses         1300     1288      -12     
+ Partials        597      592       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkwatson
Copy link
Contributor

This PR seems to have a bunch of unrelated changes in it. And, it definitely needs unit tests for the new behavior.

@Victorsesan
Copy link
Author

Victorsesan commented Oct 25, 2024

This PR seems to have a bunch of unrelated changes in it. And, it definitely needs unit tests for the new behavior.

@jkwatson Is there anything i can do to fix this? I will be very much happy to help. Sorry for all the inconveniences, if there is a way i can run the required unit test so we can have everything back to normal again i will be happy to.

@jkwatson
Copy link
Contributor

This PR seems to have a bunch of unrelated changes in it. And, it definitely needs unit tests for the new behavior.

@jkwatson Is there anything i can do to fix this? I will be very much happy to help. Sorry for all the inconveniences, if there is a way i can run the required unit test so we can have everything back to normal again i will be happy to.

You need to write unit tests for the new behavior. Note that the build checks aren't passing because of code coverage.

And, please get the diff into a clean state. Look at the 'Files changed' in the PR and get it into a state where only the changes needed for this PR are there.

.gitignore Outdated
Comment on lines 37 to 38

.fake
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert this change

Comment on lines 25 to 38
kotlinGradle {
ktlint().editorConfigOverride(mapOf(
"indent_size" to "2",
"continuation_indent_size" to "2",
"max_line_length" to "160",
"insert_final_newline" to "true",
"ktlint_standard_no-wildcard-imports" to "disabled",
"ktlint_standard_max-line-length" to "disabled",
"ktlint_standard_trailing-comma-on-call-site" to "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled",
"ktlint_standard_wrapping" to "disabled"
))
target("**/*.gradle.kts")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

the comments that were here before were important. Please restore this file to what it was before.


vm_info: OpenJDK 64-Bit Server VM (17.0.13+11-LTS) for windows-amd64 JRE (17.0.13+11-LTS), built on Oct 9 2024 05:44:29 by "" with MS VC++ 16.10 / 16.11 (VS2019)

END.
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this file

@Victorsesan
Copy link
Author

@jkwatson Seems like we still had a test failure in L437 and 438 in sdk and build should i try to remove them instead?

}
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need changes to this file for some reason? If not, please revert.

@jkwatson
Copy link
Contributor

@jkwatson Seems like we still had a test failure in L437 and 438 in sdk and build should i try to remove them instead?

??? The failure is that there is no test coverage. Please add a case to the unit tests for this.

@Victorsesan
Copy link
Author

Victorsesan commented Oct 26, 2024

@jkwatson So i have been trying to add a case to the unit test , i also tried adding something like this too in the SdkSpanTest but it didn't even make it pass the build test. Just wanted to show some of the tries i did with a comment before tagging you for some pointers. check it out
`@ Test
void testSetStatusToUnsetWhenCurrentStatusIsError() {
// Create a new SdkSpan instance
SdkSpan testSpan = createTestRootSpan();

// Set the initial status to ERROR
testSpan.setStatus(StatusCode.ERROR, "An error occurred");

// Capture the logger output
Logger logger = Logger.getLogger(SdkSpan.class.getName());
Level originalLevel = logger.getLevel();
logger.setLevel(Level.ALL); // Set to ALL to capture all log messages

// Create a custom log handler to capture log messages
TestLogHandler testLogHandler = new TestLogHandler();
logger.addHandler(testLogHandler);

// Attempt to set the status to UNSET
testSpan.setStatus(StatusCode.UNSET, null);

// Verify that the warning was logged
String lastMessage = testLogHandler.getLastMessage();
assertEquals("Cannot set status to UNSET when current status is ERROR.", lastMessage);

// Clean up
logger.removeHandler(testLogHandler);
logger.setLevel(originalLevel);

}`

implementation("net.ltgt.gradle:gradle-nullaway-plugin:2.0.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
implementation("org.owasp:dependency-check-gradle:10.0.4")
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.1")
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert all changes to this file.

@jkwatson
Copy link
Contributor

@jkwatson So i have been trying to add a case to the unit test , i also tried adding something like this too in the SdkSpanTest but it didn't even make it pass the build test. Just wanted to show some of the tries i did with a comment before tagging you for some pointers. check it out `@ Test void testSetStatusToUnsetWhenCurrentStatusIsError() { // Create a new SdkSpan instance SdkSpan testSpan = createTestRootSpan();

// Set the initial status to ERROR
testSpan.setStatus(StatusCode.ERROR, "An error occurred");

// Capture the logger output
Logger logger = Logger.getLogger(SdkSpan.class.getName());
Level originalLevel = logger.getLevel();
logger.setLevel(Level.ALL); // Set to ALL to capture all log messages

// Create a custom log handler to capture log messages
TestLogHandler testLogHandler = new TestLogHandler();
logger.addHandler(testLogHandler);

// Attempt to set the status to UNSET
testSpan.setStatus(StatusCode.UNSET, null);

// Verify that the warning was logged
String lastMessage = testLogHandler.getLastMessage();
assertEquals("Cannot set status to UNSET when current status is ERROR.", lastMessage);

// Clean up
logger.removeHandler(testLogHandler);
logger.setLevel(originalLevel);

}`

I don't care all that much about asserting the fact that things were logged. Much more important is making sure that the span status hasn't changed. Take a look at some of the other tests in the SdkSpanTest. I bet you'll find one that is testing the various status state changes that you could either add to, or base a new test case on.

if (currentStatusCode == StatusCode.OK) {
return this; // Do not allow lower priority status to override OK
} else if (currentStatusCode == StatusCode.ERROR && statusCode == StatusCode.UNSET) {
logger.log(Level.WARNING, "Cannot set status to UNSET when current status is ERROR.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be a WARNING. Probably just FINE like we have for the other status changes.


// Prevent setting a lower priority status.
if (currentStatusCode == StatusCode.OK) {
return this; // Do not allow lower priority status to override OK
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove the logging that was here before?

@@ -119,11 +119,25 @@ void setUp() {
@Test
void nothingChangedAfterEnd() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The change you made doesn't only apply after the span has ended, does it? This test is testing the case of things not changing after span ending.

Copy link
Contributor

Choose a reason for hiding this comment

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

take a look at the test called setStatusCannotOverrideStatusOK. Write a new test that looks much like that one that tests the case(s) that you've introduced.

Copy link
Author

Choose a reason for hiding this comment

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

Just added a new test for that ,though not sure if that is the required approach, still open for corrections. Also pardon some of my mistakes or modification , I'm still learning and improving on myself, and i always try to use different approach whenever needed , which if i knew how to perfectly run a test on my changes to know if they are okay it would have been much easier, so i have to check and get corrections here. Thanks for your time , let me know if the test i wrote is that which you need to be added.

// Prevent setting a lower priority status.
if (currentStatusCode == StatusCode.OK) {
return this; // Do not allow lower priority status to override OK
} else if (currentStatusCode == StatusCode.ERROR && statusCode == StatusCode.UNSET) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this else is redundant, since the if above it returns already.

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