Skip to content

Commit 0b1441e

Browse files
authored
Fix error transaction name serialization check and add tests (elastic#2246)
1 parent 69b64f6 commit 0b1441e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ private void serializeError(ErrorCapture errorCapture) {
339339
private void serializeErrorTransactionInfo(ErrorCapture.TransactionInfo errorTransactionInfo) {
340340
writeFieldName("transaction");
341341
jw.writeByte(JsonWriter.OBJECT_START);
342-
if (errorTransactionInfo.getName() != null) {
343-
writeField("name", errorTransactionInfo.getName());
344-
}
342+
writeField("name", errorTransactionInfo.getName());
345343
if (errorTransactionInfo.getType() != null) {
346344
writeField("type", errorTransactionInfo.getType());
347345
}

apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/DslJsonSerializerTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void testErrorSerialization() {
157157
ErrorCapture error = new ErrorCapture(tracer).asChildOf(transaction).withTimestamp(5000);
158158
error.setTransactionSampled(true);
159159
error.setTransactionType("test-type");
160+
error.setTransactionName(new StringBuilder("Test Transaction"));
160161
error.setException(new Exception("test"));
161162
error.getContext().addLabel("foo", "bar");
162163

@@ -176,8 +177,10 @@ void testErrorSerialization() {
176177
JsonNode stacktrace = exception.get("stacktrace");
177178
assertThat(stacktrace).hasSize(15);
178179

179-
assertThat(errorTree.get("transaction").get("sampled").booleanValue()).isTrue();
180-
assertThat(errorTree.get("transaction").get("type").textValue()).isEqualTo("test-type");
180+
JsonNode transactionTree = errorTree.get("transaction");
181+
assertThat(transactionTree.get("sampled").booleanValue()).isTrue();
182+
assertThat(transactionTree.get("type").textValue()).isEqualTo("test-type");
183+
assertThat(transactionTree.get("name").asText()).isEqualTo("Test Transaction");
181184
}
182185

183186
@Test
@@ -212,6 +215,11 @@ void testErrorSerializationWithEmptyTraceId() {
212215
assertThat(errorTree.get("trace_id")).isNull();
213216
assertThat(errorTree.get("parent_id")).isNull();
214217
assertThat(errorTree.get("transaction_id")).isNull();
218+
219+
JsonNode transactionTree = errorTree.get("transaction");
220+
assertThat(transactionTree.get("sampled").booleanValue()).isFalse();
221+
assertThat(transactionTree.get("type")).isNull();
222+
assertThat(transactionTree.get("name")).isNull();
215223
}
216224

217225
@Test

0 commit comments

Comments
 (0)