Skip to content

Commit

Permalink
#6207 Ensure Span Status Cannot Be Updated After StatusCode.OK Is Set (
Browse files Browse the repository at this point in the history
  • Loading branch information
apederson94 committed Feb 8, 2024
1 parent c12779d commit c0b73f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ public ReadWriteSpan setStatus(StatusCode statusCode, @Nullable String descripti
if (hasEnded) {
logger.log(Level.FINE, "Calling setStatus() on an ended Span.");
return this;
} else if (this.status.getStatusCode() == StatusCode.OK) {
logger.log(Level.FINE, "Calling setStatus() on a Span that is already set to OK.");
return this;
}
this.status = StatusData.create(statusCode, description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,17 @@ void onStartOnEndNotRequired() {
verify(spanProcessor, never()).onEnd(any());
}

@Test
void setStatusCannotOverrideStatusOK() {
SdkSpan testSpan = createTestRootSpan();
testSpan.setStatus(StatusCode.OK);
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.OK);
testSpan.setStatus(StatusCode.ERROR);
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.OK);
testSpan.setStatus(StatusCode.UNSET);
assertThat(testSpan.toSpanData().getStatus().getStatusCode()).isEqualTo(StatusCode.OK);
}

private SdkSpan createTestSpanWithAttributes(Map<AttributeKey, Object> attributes) {
SpanLimits spanLimits = SpanLimits.getDefault();
AttributesMap attributesMap =
Expand Down

0 comments on commit c0b73f5

Please sign in to comment.