Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from CrombieLockwood/NewTransactionIdIfNull
Browse files Browse the repository at this point in the history
SpanUtils.startSpan uses currentTransaction when not found
  • Loading branch information
michaelhyatt authored Sep 1, 2020
2 parents a821855 + d5d36b2 commit 02d414d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion mule4-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/target/
$*
.mule/
.settings
.settings
.idea
*.iml
2 changes: 1 addition & 1 deletion mule4-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic.apm</groupId>
<artifactId>mule4-agent</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<name>Elastic Mule 4 APM agent</name>
<description>Elastic Mule 4 APM agent</description>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package co.elastic.apm.mule4.agent.span;

import java.util.Map;

import co.elastic.apm.api.ElasticApm;
import co.elastic.apm.api.Span;
import co.elastic.apm.api.Transaction;
import co.elastic.apm.mule4.agent.transaction.TransactionStore;
import org.mule.runtime.api.component.location.ComponentLocation;
import org.mule.runtime.api.interception.InterceptionEvent;
import org.mule.runtime.api.interception.ProcessorParameterValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import co.elastic.apm.api.Span;
import co.elastic.apm.api.Transaction;
import co.elastic.apm.mule4.agent.transaction.TransactionStore;
import java.util.Map;

/*
* Creation and ending of APM Spans.
Expand All @@ -18,6 +20,8 @@ public class SpanUtils {
private static final String DOC_NAME = "doc:name";
private static final String UNNAMED = "...";

private static final Logger logger = LoggerFactory.getLogger(SpanUtils.class);

/*
* Start a span
*/
Expand All @@ -28,7 +32,7 @@ public static Span startSpan(TransactionStore transactionStore, ComponentLocatio
// Span can only be started if there is an existing transaction created by flow
// listener.
Transaction transaction = transactionStore.getTransaction(transactionId)
.orElseThrow(() -> new RuntimeException("Could not find transaction " + transactionId));
.orElse(getCurrentTransactionAndLog(transactionId));

Span span = transaction.startSpan(getSpanType(location), getSubType(location), getAction(location));

Expand All @@ -37,6 +41,11 @@ public static Span startSpan(TransactionStore transactionStore, ComponentLocatio
return span;
}

private static Transaction getCurrentTransactionAndLog(String transactionId) {
logger.debug("Could not find transaction " + transactionId + ". Using currentTransaction.");
return ElasticApm.currentTransaction();
}

/*
* Populate Span details at creation time
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ private static Transaction populateTransactionDetails(Transaction transaction,

transaction2.setType(Transaction.TYPE_REQUEST);

getTransactionId(notification)
.ifPresent(s -> transaction2.addLabel("correlationId", s));

// TODO: investigate population of transaction start from the external
// parameters.
// transaction.setStartTimestamp(epochMicros);
Expand Down

0 comments on commit 02d414d

Please sign in to comment.