Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ by the agent may be different. This was done in order to improve the integration
* Added support to capture `context.message.routing-key` in rabbitmq, spring amqp instrumentations - {pull}1767[#1767]
* Breakdown metrics are now tracked per service (when using APM Server 8.0) - {pull}2208[#2208]
* Add support for Spring AMQP batch API - {pull}1716[#1716]
* Add the (current) transaction name to the error (when using APM Server 8.0) - {pull}2235[#2235]

[float]
===== Performance improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, @
error.setException(e);
Transaction currentTransaction = currentTransaction();
if (currentTransaction != null) {
if (currentTransaction.getNameForSerialization().length() > 0) {
error.setTransactionName(currentTransaction.getNameForSerialization());
}
error.setTransactionType(currentTransaction.getType());
error.setTransactionSampled(currentTransaction.isSampled());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ public static class TransactionInfo implements Recyclable {
* A hint for UI to be able to show whether a recorded trace for the corresponding transaction is expected
*/
private boolean isSampled;
/**
* The related TransactionInfo name
*/
private StringBuilder name = new StringBuilder();
/**
* The related TransactionInfo type
*/
Expand All @@ -247,13 +251,18 @@ public static class TransactionInfo implements Recyclable {
@Override
public void resetState() {
isSampled = false;
name.setLength(0);
type = null;
}

public boolean isSampled() {
return isSampled;
}

public StringBuilder getName() {
return name;
}

@Nullable
public String getType() {
return type;
Expand All @@ -268,6 +277,11 @@ public void setTransactionSampled(boolean transactionSampled) {
transactionInfo.isSampled = transactionSampled;
}

public void setTransactionName(@Nullable StringBuilder name) {
transactionInfo.name.setLength(0);
transactionInfo.name.append(name);
}

public void setTransactionType(@Nullable String type) {
transactionInfo.type = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ private void serializeError(ErrorCapture errorCapture) {
private void serializeErrorTransactionInfo(ErrorCapture.TransactionInfo errorTransactionInfo) {
writeFieldName("transaction");
jw.writeByte(JsonWriter.OBJECT_START);
if (errorTransactionInfo.getName() != null) {
writeField("name", errorTransactionInfo.getName());
}
if (errorTransactionInfo.getType() != null) {
writeField("type", errorTransactionInfo.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ private ErrorCapture validateError(ErrorCapture error, AbstractSpan<?> span, boo
.describedAs("error trace context [%s] should be a child of span trace context [%s]", error.getTraceContext(), span.getTraceContext())
.isTrue();
assertThat(error.getTransactionInfo().isSampled()).isEqualTo(sampled);
if (!transaction.getNameAsString().isEmpty()) {
assertThat(error.getTransactionInfo().getName()).isEqualTo(transaction.getNameAsString());
}
assertThat(error.getTransactionInfo().getType()).isEqualTo(transaction.getType());
return error;
}
Expand Down Expand Up @@ -484,4 +487,17 @@ void testCaptureExceptionAndGetErrorId() {
assertThat(error.getTraceContext().getId().toString()).isEqualTo(errorId);
}

@Test
void testCaptureExceptionWithTransactionName() {
Transaction transaction = startTestRootTransaction().withName("My Transaction");
try (Scope scope = transaction.activateInScope()) {
transaction.captureException(new Exception("test"));
transaction.end();
}

assertThat(reporter.getErrors()).hasSize(1);
ErrorCapture error = reporter.getFirstError();
assertThat(error.getTransactionInfo().getName().toString()).isEqualTo("My Transaction");
}

}