Skip to content

Commit

Permalink
Invert isSpanUnmodifiableByCurrentThread
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Sep 2, 2024
1 parent fc67a4d commit 80aa059
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public <T> ReadWriteSpan setAttribute(AttributeKey<T> key, T value) {
return this;
}
synchronized (lock) {
if (isSpanUnmodifiableByCurrentThread()) {
if (!isModifiableByCurrentThread()) {
logger.log(Level.FINE, "Calling setAttribute() on an ended Span.");
return this;
}
Expand All @@ -335,9 +335,9 @@ public <T> ReadWriteSpan setAttribute(AttributeKey<T> key, T value) {
}

@GuardedBy("lock")
private boolean isSpanUnmodifiableByCurrentThread() {
return hasEnded == EndState.ENDED
|| (hasEnded == EndState.ENDING && Thread.currentThread() != spanEndingThread);
private boolean isModifiableByCurrentThread() {
return hasEnded == EndState.NOT_ENDED
|| (hasEnded == EndState.ENDING && Thread.currentThread() == spanEndingThread);
}

@Override
Expand Down Expand Up @@ -402,7 +402,7 @@ public ReadWriteSpan addEvent(String name, Attributes attributes, long timestamp

private void addTimedEvent(EventData timedEvent) {
synchronized (lock) {
if (isSpanUnmodifiableByCurrentThread()) {
if (!isModifiableByCurrentThread()) {
logger.log(Level.FINE, "Calling addEvent() on an ended Span.");
return;
}
Expand All @@ -422,7 +422,7 @@ public ReadWriteSpan setStatus(StatusCode statusCode, @Nullable String descripti
return this;
}
synchronized (lock) {
if (isSpanUnmodifiableByCurrentThread()) {
if (!isModifiableByCurrentThread()) {
logger.log(Level.FINE, "Calling setStatus() on an ended Span.");
return this;
} else if (this.status.getStatusCode() == StatusCode.OK) {
Expand Down Expand Up @@ -460,7 +460,7 @@ public ReadWriteSpan updateName(String name) {
return this;
}
synchronized (lock) {
if (isSpanUnmodifiableByCurrentThread()) {
if (!isModifiableByCurrentThread()) {
logger.log(Level.FINE, "Calling updateName() on an ended Span.");
return this;
}
Expand All @@ -485,7 +485,7 @@ public Span addLink(SpanContext spanContext, Attributes attributes) {
spanLimits.getMaxNumberOfAttributesPerLink(),
spanLimits.getMaxAttributeValueLength()));
synchronized (lock) {
if (isSpanUnmodifiableByCurrentThread()) {
if (!isModifiableByCurrentThread()) {
logger.log(Level.FINE, "Calling addLink() on an ended Span.");
return this;
}
Expand Down

0 comments on commit 80aa059

Please sign in to comment.