-
Notifications
You must be signed in to change notification settings - Fork 849
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
base: main
Are you sure you want to change the base?
Changes from all commits
7f9ef5f
ef46f8f
9590742
a9fb915
500d261
aa731c7
bed6535
c21608c
ec33889
ab67793
189c416
7991abf
448ece8
5a62252
2fdd372
d452c3e
f04bb8d
5aa430e
db6a054
b1776cf
d9e11e8
8fc9659
cb9283e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,4 @@ java { | |
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,17 +428,38 @@ private void addTimedEvent(EventData timedEvent) { | |
@Override | ||
public ReadWriteSpan setStatus(StatusCode statusCode, @Nullable String description) { | ||
if (statusCode == null) { | ||
return this; | ||
return this; // No action if statusCode is null | ||
} | ||
synchronized (lock) { | ||
if (!isModifiableByCurrentThread()) { | ||
logger.log(Level.FINE, "Calling setStatus() on an ended Span."); | ||
return this; | ||
} else if (this.status.getStatusCode() == StatusCode.OK) { | ||
} | ||
<<<<<<< HEAD | ||
|
||
======= | ||
|
||
>>>>>>> d9e11e8e4aebfe44bc79436b8e7ee42344e4a5aa | ||
StatusCode currentStatusCode = this.status.getStatusCode(); | ||
|
||
// 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."); | ||
return this; | ||
return this; // Do not allow lower priority status to override OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove the logging that was here before? |
||
} if (currentStatusCode == StatusCode.ERROR && statusCode == StatusCode.UNSET) { | ||
logger.log(Level.FINE, "Cannot set status to UNSET when current status is ERROR."); | ||
return this; // Do not allow UNSET to override ERROR | ||
} | ||
|
||
// Set the status, ignoring description if status is not ERROR. | ||
if (statusCode == StatusCode.ERROR) { | ||
this.status = StatusData.create(statusCode, description); | ||
} else { | ||
if (currentStatusCode != statusCode) { | ||
this.status = | ||
StatusData.create(statusCode, null); | ||
} | ||
} | ||
this.status = StatusData.create(statusCode, description); | ||
} | ||
return this; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,11 +119,25 @@ void setUp() { | |
@Test | ||
void nothingChangedAfterEnd() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. take a look at the test called There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
SdkSpan span = createTestSpan(SpanKind.INTERNAL); | ||
|
||
// Set an initial status before ending the span | ||
span.setStatus(StatusCode.OK, "Initial status"); | ||
assertThat(span.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.OK); | ||
|
||
// End the span | ||
span.end(); | ||
// Check that adding trace events or update fields after Span#end() does not throw any thrown | ||
|
||
// Store the current status for verification | ||
StatusData currentStatus = span.toSpanData().getStatus(); | ||
|
||
// Check that adding trace events or update fields after Span#end() does not throw any exception | ||
// and are ignored. | ||
spanDoWork(span, StatusCode.ERROR, "CANCELLED"); | ||
|
||
// Verify that the status has not changed after the span has ended | ||
SpanData spanData = span.toSpanData(); | ||
assertThat(spanData.getStatus()).isEqualTo(currentStatus); | ||
|
||
verifySpanData( | ||
spanData, | ||
Attributes.empty(), | ||
|
@@ -1432,6 +1446,29 @@ private void verifySpanData( | |
spanDataAttributes.forEach((key, value) -> assertThat(attributes.get(key)).isEqualTo(value)); | ||
} | ||
|
||
|
||
@Test | ||
void setStatusCannotOverrideStatusError() { | ||
SdkSpan testSpan = createTestRootSpan(); | ||
|
||
// Set an initial status to ERROR | ||
testSpan.setStatus(StatusCode.ERROR, "Initial error status"); | ||
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.ERROR); | ||
|
||
// Attempt to set status to OK (should not change) | ||
testSpan.setStatus(StatusCode.OK); | ||
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.ERROR); | ||
|
||
// Attempt to set status to UNSET (should not change) | ||
testSpan.setStatus(StatusCode.UNSET); | ||
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.ERROR); | ||
|
||
// Attempt to set status to ERROR again (should remain ERROR) | ||
testSpan.setStatus(StatusCode.ERROR, "Another error status"); | ||
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.ERROR); | ||
} | ||
|
||
|
||
@Test | ||
void testAsSpanData() { | ||
String name = "GreatSpan"; | ||
|
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.
Why remove this?