Skip to content

Commit 4c90b3e

Browse files
committed
[#noissue] Extract ExceptionInfo
1 parent 735bb5d commit 4c90b3e

File tree

16 files changed

+116
-116
lines changed

16 files changed

+116
-116
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.navercorp.pinpoint.common.server.bo;
2+
3+
public record ExceptionInfo(int id, String message) {
4+
5+
}

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanBo.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ public class SpanBo implements Event, BasicSpan {
7272

7373
private long collectorAcceptTime;
7474

75-
private boolean hasException = false;
76-
private int exceptionId;
77-
private String exceptionMessage;
75+
private ExceptionInfo exceptionInfo;
76+
7877
private String exceptionClass;
7978

8079
private int applicationServiceType;
@@ -325,25 +324,18 @@ public boolean isRoot() {
325324
return -1L == parentSpanId;
326325
}
327326

328-
public boolean hasException() {
329-
return hasException;
327+
public ExceptionInfo getExceptionInfo() {
328+
return exceptionInfo;
330329
}
331330

332-
public int getExceptionId() {
333-
return exceptionId;
334-
}
335-
336-
public String getExceptionMessage() {
337-
return exceptionMessage;
331+
public boolean hasException() {
332+
return exceptionInfo != null;
338333
}
339334

340-
public void setExceptionInfo(int exceptionId, String exceptionMessage) {
341-
this.hasException = true;
342-
this.exceptionId = exceptionId;
343-
this.exceptionMessage = exceptionMessage;
335+
public void setExceptionInfo(ExceptionInfo exceptionInfo) {
336+
this.exceptionInfo = exceptionInfo;
344337
}
345338

346-
347339
public String getExceptionClass() {
348340
return exceptionClass;
349341
}
@@ -425,9 +417,7 @@ public String toString() {
425417
", spanEventBoList=" + spanEventBoList +
426418
", spanChunkBoList=" + spanChunkBoList +
427419
", collectorAcceptTime=" + collectorAcceptTime +
428-
", hasException=" + hasException +
429-
", exceptionId=" + exceptionId +
430-
", exceptionMessage='" + exceptionMessage + '\'' +
420+
", exceptionInfo=" + exceptionInfo +
431421
", exceptionClass='" + exceptionClass + '\'' +
432422
", applicationServiceType=" + applicationServiceType +
433423
", acceptorHost='" + acceptorHost + '\'' +
@@ -475,8 +465,7 @@ public static class Builder {
475465

476466
private long collectorAcceptTime;
477467

478-
private int exceptionId;
479-
private String exceptionMessage;
468+
private ExceptionInfo exceptionInfo;
480469
private String exceptionClass;
481470

482471
private int applicationServiceType;
@@ -486,6 +475,7 @@ public static class Builder {
486475

487476
private byte loggingTransactionInfo; //optional
488477

478+
489479
Builder(long spanId) {
490480
this.spanId = spanId;
491481
}
@@ -588,13 +578,8 @@ public Builder setCollectorAcceptTime(long collectorAcceptTime) {
588578
return this;
589579
}
590580

591-
public Builder setExceptionId(int exceptionId) {
592-
this.exceptionId = exceptionId;
593-
return this;
594-
}
595-
596-
public Builder setExceptionMessage(String exceptionMessage) {
597-
this.exceptionMessage = exceptionMessage;
581+
public Builder setExceptionInfo(ExceptionInfo exceptionInfo) {
582+
this.exceptionInfo = exceptionInfo;
598583
return this;
599584
}
600585

@@ -655,8 +640,8 @@ public SpanBo build() {
655640
result.setErrCode(this.errCode);
656641
result.setCollectorAcceptTime(this.collectorAcceptTime);
657642
result.setExceptionClass(this.exceptionClass);
658-
if (this.exceptionMessage != null) {
659-
result.setExceptionInfo(this.exceptionId, this.exceptionMessage);
643+
if (this.exceptionInfo != null) {
644+
result.setExceptionInfo(exceptionInfo);
660645
}
661646
result.setApplicationServiceType(this.applicationServiceType);
662647
result.setAcceptorHost(this.acceptorHost);

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanEventBo.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public class SpanEventBo implements Event {
4646
private int depth = -1;
4747
private long nextSpanId = -1;
4848

49-
private boolean hasException;
50-
private int exceptionId;
51-
private String exceptionMessage;
49+
private ExceptionInfo exceptionInfo;
5250

5351
// should get exceptionClass from dao
5452
private String exceptionClass;
@@ -154,28 +152,21 @@ public void setAnnotationBoList(List<AnnotationBo> annotationList) {
154152
}
155153

156154
public boolean hasException() {
157-
return hasException;
155+
return exceptionInfo != null;
158156
}
159157

160-
public int getExceptionId() {
161-
return exceptionId;
158+
public ExceptionInfo getExceptionInfo() {
159+
return exceptionInfo;
162160
}
163161

164-
public String getExceptionMessage() {
165-
return exceptionMessage;
162+
public void setExceptionInfo(ExceptionInfo exceptionInfo) {
163+
this.exceptionInfo = exceptionInfo;
166164
}
167165

168166
public String getExceptionClass() {
169167
return exceptionClass;
170168
}
171169

172-
public void setExceptionInfo(int exceptionId, String exceptionMessage) {
173-
this.hasException = true;
174-
this.exceptionId = exceptionId;
175-
this.exceptionMessage = exceptionMessage;
176-
}
177-
178-
179170
public void setExceptionClass(String exceptionClass) {
180171
this.exceptionClass = exceptionClass;
181172
}
@@ -203,9 +194,7 @@ public String toString() {
203194
", annotationBoList=" + annotationBoList +
204195
", depth=" + depth +
205196
", nextSpanId=" + nextSpanId +
206-
", hasException=" + hasException +
207-
", exceptionId=" + exceptionId +
208-
", exceptionMessage='" + exceptionMessage + '\'' +
197+
", exceptionInfo=" + exceptionInfo +
209198
", exceptionClass='" + exceptionClass + '\'' +
210199
", nextAsyncId=" + nextAsyncId +
211200
'}';
@@ -230,7 +219,7 @@ public static class Builder {
230219
private String endPoint;
231220
private int apiId;
232221

233-
private List<AnnotationBo> annotationBoList = new ArrayList<>();
222+
private final List<AnnotationBo> annotationBoList = new ArrayList<>();
234223

235224
private int depth = -1;
236225
private long nextSpanId = -1;

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.navercorp.pinpoint.common.server.bo.AnnotationBo;
2222
import com.navercorp.pinpoint.common.server.bo.AnnotationComparator;
2323
import com.navercorp.pinpoint.common.server.bo.AnnotationFactory;
24+
import com.navercorp.pinpoint.common.server.bo.ExceptionInfo;
2425
import com.navercorp.pinpoint.common.server.bo.LocalAsyncIdBo;
2526
import com.navercorp.pinpoint.common.server.bo.SpanBo;
2627
import com.navercorp.pinpoint.common.server.bo.SpanChunkBo;
@@ -150,8 +151,9 @@ SpanBo newSpanBo(PSpan pSpan, BindAttribute attribute) {
150151
// FIXME span.errCode contains error of span and spanEvent
151152
// because exceptionInfo is the error information of span itself, exceptionInfo can be null even if errCode is not 0
152153
if (pSpan.hasExceptionInfo()) {
153-
final PIntStringValue exceptionInfo = pSpan.getExceptionInfo();
154-
spanBo.setExceptionInfo(exceptionInfo.getIntValue(), getExceptionMessage(exceptionInfo));
154+
final PIntStringValue pException = pSpan.getExceptionInfo();
155+
ExceptionInfo exceptionInfo = new ExceptionInfo(pException.getIntValue(), getExceptionMessage(pException));
156+
spanBo.setExceptionInfo(exceptionInfo);
155157
}
156158

157159
List<AnnotationBo> annotationBoList = buildAnnotationList(pSpan.getAnnotationList());
@@ -213,8 +215,9 @@ private void bind(SpanEventBo spanEvent, PSpanEvent pSpanEvent, SpanEventBo prev
213215
spanEvent.setAnnotationBoList(annotationList);
214216

215217
if (pSpanEvent.hasExceptionInfo()) {
216-
final PIntStringValue exceptionInfo = pSpanEvent.getExceptionInfo();
217-
spanEvent.setExceptionInfo(exceptionInfo.getIntValue(), getExceptionMessage(exceptionInfo));
218+
final PIntStringValue pException = pSpanEvent.getExceptionInfo();
219+
ExceptionInfo exceptionInfo = new ExceptionInfo(pSpanEvent.getExceptionInfo().getIntValue(), getExceptionMessage(pException));
220+
spanEvent.setExceptionInfo(exceptionInfo);
218221
}
219222
}
220223

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.navercorp.pinpoint.common.server.bo.AnnotationBo;
2222
import com.navercorp.pinpoint.common.server.bo.AnnotationTranscoder;
2323
import com.navercorp.pinpoint.common.server.bo.BasicSpan;
24+
import com.navercorp.pinpoint.common.server.bo.ExceptionInfo;
2425
import com.navercorp.pinpoint.common.server.bo.LocalAsyncIdBo;
2526
import com.navercorp.pinpoint.common.server.bo.SpanBo;
2627
import com.navercorp.pinpoint.common.server.bo.SpanChunkBo;
@@ -149,7 +150,8 @@ public void readSpanValue(Buffer buffer, SpanBo span, SpanDecodingContext decodi
149150
if (bitField.isSetHasException()) {
150151
int exceptionId = buffer.readSVInt();
151152
String exceptionMessage = buffer.readPrefixedString();
152-
span.setExceptionInfo(exceptionId, exceptionMessage);
153+
ExceptionInfo exceptionInfo = new ExceptionInfo(exceptionId, exceptionMessage);
154+
span.setExceptionInfo(exceptionInfo);
153155
}
154156

155157
if (bitField.isSetFlag()) {
@@ -268,7 +270,8 @@ private SpanEventBo readNextSpanEvent(final Buffer buffer, final SpanEventBo pre
268270
if (bitField.isSetHasException()) {
269271
int exceptionId = buffer.readSVInt();
270272
String exceptionMessage = buffer.readPrefixedString();
271-
spanEventBo.setExceptionInfo(exceptionId, exceptionMessage);
273+
ExceptionInfo exceptionInfo = new ExceptionInfo(exceptionId, exceptionMessage);
274+
spanEventBo.setExceptionInfo(exceptionInfo);
272275
}
273276

274277
if (bitField.isSetAnnotation()) {
@@ -310,7 +313,8 @@ private SpanEventBo readFirstSpanEvent(Buffer buffer, SpanDecodingContext decodi
310313
if (bitField.isSetHasException()) {
311314
int exceptionId = buffer.readSVInt();
312315
String exceptionMessage = buffer.readPrefixedString();
313-
firstSpanEvent.setExceptionInfo(exceptionId, exceptionMessage);
316+
ExceptionInfo exceptionInfo = new ExceptionInfo(exceptionId, exceptionMessage);
317+
firstSpanEvent.setExceptionInfo(exceptionInfo);
314318
}
315319

316320
if (bitField.isSetAnnotation()) {

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.navercorp.pinpoint.common.server.bo.AnnotationBo;
66
import com.navercorp.pinpoint.common.server.bo.AnnotationTranscoder;
77
import com.navercorp.pinpoint.common.server.bo.BasicSpan;
8+
import com.navercorp.pinpoint.common.server.bo.ExceptionInfo;
89
import com.navercorp.pinpoint.common.server.bo.LocalAsyncIdBo;
910
import com.navercorp.pinpoint.common.server.bo.SpanBo;
1011
import com.navercorp.pinpoint.common.server.bo.SpanChunkBo;
@@ -181,8 +182,11 @@ public ByteBuffer encodeSpanColumnValue(SpanEncodingContext<SpanBo> encodingCont
181182
}
182183

183184
if (bitField.isSetHasException()) {
184-
buffer.putSVInt(span.getExceptionId());
185-
buffer.putPrefixedString(span.getExceptionMessage());
185+
if (span.hasException()) {
186+
ExceptionInfo exceptionInfo = span.getExceptionInfo();
187+
buffer.putSVInt(exceptionInfo.id());
188+
buffer.putPrefixedString(exceptionInfo.message());
189+
}
186190
}
187191

188192
if (bitField.isSetFlag()) {
@@ -235,8 +239,11 @@ public void writeFirstSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEnco
235239
}
236240

237241
if (bitField.isSetHasException()) {
238-
buffer.putSVInt(spanEventBo.getExceptionId());
239-
buffer.putPrefixedString(spanEventBo.getExceptionMessage());
242+
ExceptionInfo exceptionInfo = spanEventBo.getExceptionInfo();
243+
if (exceptionInfo!= null) {
244+
buffer.putSVInt(exceptionInfo.id());
245+
buffer.putPrefixedString(exceptionInfo.message());
246+
}
240247
}
241248

242249
if (bitField.isSetAnnotation()) {
@@ -322,8 +329,11 @@ public void writeNextSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEvent
322329
}
323330

324331
if (bitField.isSetHasException()) {
325-
buffer.putSVInt(spanEventBo.getExceptionId());
326-
buffer.putPrefixedString(spanEventBo.getExceptionMessage());
332+
ExceptionInfo exceptionInfo = spanEventBo.getExceptionInfo();
333+
if (exceptionInfo != null) {
334+
buffer.putSVInt(exceptionInfo.id());
335+
buffer.putPrefixedString(exceptionInfo.message());
336+
}
327337
}
328338

329339
if (bitField.isSetAnnotation()) {

commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ public void assertSpan(PSpan pSpan, SpanBo spanBo) {
7777
Assertions.assertEquals(hasException, spanBo.hasException());
7878
if (hasException) {
7979
PIntStringValue exceptionInfo = pSpan.getExceptionInfo();
80-
Assertions.assertEquals(exceptionInfo.getIntValue(), spanBo.getExceptionId());
81-
Assertions.assertEquals(exceptionInfo.getStringValue().getValue(), spanBo.getExceptionMessage());
80+
ExceptionInfo exceptionInfoBo = spanBo.getExceptionInfo();
81+
Assertions.assertEquals(exceptionInfo.getIntValue(), exceptionInfoBo.id());
82+
Assertions.assertEquals(exceptionInfo.getStringValue().getValue(), exceptionInfoBo.message());
8283
}
8384

8485
Assertions.assertEquals(pSpan.getLoggingTransactionInfo(), spanBo.getLoggingTransactionInfo());
@@ -133,8 +134,9 @@ public void assertSpanEvent(PSpanEvent pSpanEvent, int delta, SpanEventBo spanEv
133134
Assertions.assertEquals(hasException, spanEventBo.hasException());
134135
if (hasException) {
135136
PIntStringValue exceptionInfo = pSpanEvent.getExceptionInfo();
136-
Assertions.assertEquals(exceptionInfo.getIntValue(), spanEventBo.getExceptionId());
137-
Assertions.assertEquals(exceptionInfo.getStringValue().getValue(), spanEventBo.getExceptionMessage());
137+
ExceptionInfo exceptionInfoBo = spanEventBo.getExceptionInfo();
138+
Assertions.assertEquals(exceptionInfo.getIntValue(), exceptionInfoBo.id());
139+
Assertions.assertEquals(exceptionInfo.getStringValue().getValue(), exceptionInfoBo.message());
138140
}
139141

140142
Assertions.assertEquals(pSpanEvent.getAsyncEvent(), spanEventBo.getNextAsyncId());

commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/bitfield/SpanBitFieldTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield;
22

3+
import com.navercorp.pinpoint.common.server.bo.ExceptionInfo;
34
import com.navercorp.pinpoint.common.server.bo.SpanBo;
45
import com.navercorp.pinpoint.common.trace.LoggingInfo;
56
import org.apache.logging.log4j.LogManager;
@@ -14,7 +15,7 @@ public class SpanBitFieldTest {
1415
private final Logger logger = LogManager.getLogger(this.getClass());
1516

1617
@Test
17-
public void testRoot_1() throws Exception {
18+
public void testRoot_1() {
1819
SpanBo spanBo = new SpanBo();
1920
spanBo.setParentSpanId(-1);
2021

@@ -23,11 +24,10 @@ public void testRoot_1() throws Exception {
2324

2425
spanBitField.setRoot(false);
2526
Assertions.assertFalse(spanBitField.isRoot());
26-
2727
}
2828

2929
@Test
30-
public void testRoot_2() throws Exception {
30+
public void testRoot_2() {
3131
SpanBo spanBo = new SpanBo();
3232
spanBo.setParentSpanId(0);
3333

@@ -72,7 +72,7 @@ public void testApplicationServiceTypeEncodingStrategy_PREV_TYPE_EQUALS() {
7272

7373
SpanBitField spanBitField = SpanBitField.build(spanBo);
7474

75-
Assertions.assertEquals(spanBitField.getApplicationServiceTypeEncodingStrategy(), ServiceTypeEncodingStrategy.PREV_EQUALS);
75+
Assertions.assertEquals(ServiceTypeEncodingStrategy.PREV_EQUALS, spanBitField.getApplicationServiceTypeEncodingStrategy());
7676
}
7777

7878
@Test
@@ -83,19 +83,19 @@ public void testApplicationServiceTypeEncodingStrategy_RAW() {
8383

8484
SpanBitField spanBitField = SpanBitField.build(spanBo);
8585

86-
Assertions.assertEquals(spanBitField.getApplicationServiceTypeEncodingStrategy(), ServiceTypeEncodingStrategy.RAW);
86+
Assertions.assertEquals(ServiceTypeEncodingStrategy.RAW, spanBitField.getApplicationServiceTypeEncodingStrategy());
8787

8888
spanBitField.maskAll();
89-
Assertions.assertEquals(spanBitField.getApplicationServiceTypeEncodingStrategy(), ServiceTypeEncodingStrategy.RAW);
89+
Assertions.assertEquals(ServiceTypeEncodingStrategy.RAW, spanBitField.getApplicationServiceTypeEncodingStrategy());
9090
spanBitField.setApplicationServiceTypeEncodingStrategy(ServiceTypeEncodingStrategy.PREV_EQUALS);
91-
Assertions.assertEquals(spanBitField.getApplicationServiceTypeEncodingStrategy(), ServiceTypeEncodingStrategy.PREV_EQUALS);
91+
Assertions.assertEquals(ServiceTypeEncodingStrategy.PREV_EQUALS, spanBitField.getApplicationServiceTypeEncodingStrategy());
9292
}
9393

9494

9595
@Test
9696
public void testHasException_1() {
9797
SpanBo spanBo = new SpanBo();
98-
spanBo.setExceptionInfo(1, "error");
98+
spanBo.setExceptionInfo(new ExceptionInfo(1, "error"));
9999

100100
SpanBitField spanBitField = SpanBitField.build(spanBo);
101101

0 commit comments

Comments
 (0)