Skip to content

Commit 06f974d

Browse files
committed
More cleanup
1 parent 84d78c7 commit 06f974d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

sdk/common/src/main/java/io/opentelemetry/sdk/internal/DefaultExceptionAttributeResolver.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ public static ExceptionAttributeResolver getInstance() {
2727
@Override
2828
public void setExceptionAttributes(
2929
AttributeSetter attributeSetter, Throwable throwable, int maxAttributeLength) {
30-
attributeSetter.setAttribute(
31-
ExceptionAttributeResolver.EXCEPTION_TYPE, throwable.getClass().getCanonicalName());
32-
String message = throwable.getMessage();
33-
if (message != null) {
34-
attributeSetter.setAttribute(ExceptionAttributeResolver.EXCEPTION_MESSAGE, message);
30+
String exceptionType = throwable.getClass().getCanonicalName();
31+
if (exceptionType != null) {
32+
attributeSetter.setAttribute(ExceptionAttributeResolver.EXCEPTION_TYPE, exceptionType);
3533
}
34+
35+
String exceptionMessage = throwable.getMessage();
36+
if (exceptionMessage != null) {
37+
attributeSetter.setAttribute(ExceptionAttributeResolver.EXCEPTION_MESSAGE, exceptionMessage);
38+
}
39+
3640
StringWriter stringWriter = new StringWriter();
3741
try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
3842
throwable.printStackTrace(printWriter);
3943
}
40-
attributeSetter.setAttribute(
41-
ExceptionAttributeResolver.EXCEPTION_STACKTRACE, stringWriter.toString());
44+
String exceptionStacktrace = stringWriter.toString();
45+
if (exceptionStacktrace != null) {
46+
attributeSetter.setAttribute(
47+
ExceptionAttributeResolver.EXCEPTION_STACKTRACE, exceptionStacktrace);
48+
}
4249
}
4350
}

sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public <T> ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey<T> ke
105105
ExtendedAttributesMap.create(
106106
logLimits.getMaxNumberOfAttributes(), logLimits.getMaxAttributeValueLength());
107107
}
108-
extendedAttributes.putIfCapacity(key, value);
108+
extendedAttributes.put(key, value);
109109
}
110110
return this;
111111
}

sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public <T> SpanBuilder setAttribute(AttributeKey<T> key, T value) {
150150
if (key == null || key.getKey().isEmpty() || value == null) {
151151
return this;
152152
}
153-
attributes().putIfCapacity(key, value);
153+
attributes().put(key, value);
154154
return this;
155155
}
156156

@@ -209,8 +209,7 @@ public Span startSpan() {
209209
}
210210
Attributes samplingAttributes = samplingResult.getAttributes();
211211
if (!samplingAttributes.isEmpty()) {
212-
samplingAttributes.forEach(
213-
(key, value) -> attributes().putIfCapacity((AttributeKey) key, value));
212+
samplingAttributes.forEach((key, value) -> attributes().put((AttributeKey) key, value));
214213
}
215214

216215
// Avoid any possibility to modify the attributes by adding attributes to the Builder after the

sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SdkSpanTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import java.util.stream.IntStream;
7171
import java.util.stream.Stream;
7272
import javax.annotation.Nullable;
73-
import org.assertj.core.api.Assertions;
7473
import org.junit.jupiter.api.BeforeEach;
7574
import org.junit.jupiter.api.Test;
7675
import org.junit.jupiter.api.extension.ExtendWith;

0 commit comments

Comments
 (0)