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

Commit

Permalink
Updated to Java APM agent 1.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
The User of this Mac authored and user1 committed Jul 13, 2020
2 parents 07385ef + 0c202e6 commit e02738a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
4 changes: 2 additions & 2 deletions apm-mule3-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-mule3-agent</artifactId>
<version>1.16.0</version>
<version>1.17.0</version>
<packaging>${packaging}</packaging>
<name>Mule apm-mule3-agent Application</name>

Expand Down Expand Up @@ -34,7 +34,7 @@
<mule.version>3.9.0</mule.version>
<mule.tools.version>1.2</mule.tools.version>

<elastic-apm.version>1.16.0</elastic-apm.version>
<elastic-apm.version>1.17.0</elastic-apm.version>
<version.byte-buddy>1.10.8</version.byte-buddy>

<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@ public void onNotification(PipelineMessageNotification notification) {
transactionUtils.startTransactionIfNone(notification);
break;

case PipelineMessageNotification.PROCESS_COMPLETE:
case PipelineMessageNotification.PROCESS_END:
transactionUtils.endTransactionIfNeeded(notification);
break;

case PipelineMessageNotification.PROCESS_COMPLETE:
// Ignored, as it is skipped when flow exception is thrown
break;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.elastic.apm.mule.utils;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.log4j.MDC;
import org.mule.api.MessagingException;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;
Expand All @@ -21,6 +22,9 @@
*
*/
public class TransactionUtils {

private static final String MDC_TRANSACTION_ID = "transaction.id";
private static final String MDC_TRACE_ID = "trace.id";

@Autowired
private SpanStore txMap;
Expand Down Expand Up @@ -56,6 +60,8 @@ public void startTransactionIfNone(PipelineMessageNotification notification) {

txMap.storeTransactionOrSpan(messageId, notification, transaction);

if (isLogCorrelationEnabled())
addMdcHeaders(transaction);
}

/**
Expand All @@ -82,9 +88,27 @@ public void endTransactionIfNeeded(PipelineMessageNotification notification) {
transaction.captureException(exceptionThrown);

transaction.end(notification.getTimestamp() * 1_000);

if (isLogCorrelationEnabled())
removeMdcHeaders();
}
}

private boolean isLogCorrelationEnabled() {
return "true".equals(System.getProperty("elastic.apm.enable_log_correlation"))
|| "true".equals(System.getenv("ELASTIC_APM_ENABLE_LOG_CORRELATION"));
}

private void addMdcHeaders(Transaction transaction) {
MDC.put(MDC_TRACE_ID, transaction.getTraceId());
MDC.put(MDC_TRANSACTION_ID, transaction.getId());
}

private void removeMdcHeaders() {
MDC.remove(MDC_TRACE_ID);
MDC.remove(MDC_TRANSACTION_ID);
}

private MuleMessage getMuleMessage(PipelineMessageNotification notification) {
return ((MuleEvent) notification.getSource()).getMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.mule.tck.junit4.FunctionalTestCase;

import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.ElasticApmTracerBuilder;
import co.elastic.apm.agent.impl.error.ErrorCapture;
import co.elastic.apm.agent.impl.transaction.Span;
Expand Down Expand Up @@ -65,11 +66,12 @@ public ErrorCapture answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(reporter).report(Mockito.any(ErrorCapture.class));

Mockito.doNothing().when(reporter).scheduleMetricReporting(Mockito.any(), Mockito.anyLong(), Mockito.any());

ElasticApmAgent.initInstrumentation(new ElasticApmTracerBuilder().reporter(reporter).build(),
ByteBuddyAgent.install());
ElasticApmTracer tracer = new ElasticApmTracerBuilder().reporter(reporter).build();
tracer.start();
ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install());

// Skip real initialisation so it is not triggered in the flows for tests
ApmClient.setInitialised();
Expand Down
4 changes: 2 additions & 2 deletions apm-mule3.8-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic.apm</groupId>
<artifactId>apm-mule3.8-agent</artifactId>
<version>1.16.0</version>
<version>1.17.0</version>
<packaging>${packaging}</packaging>
<name>Mule apm-mule3-agent Application built for Mule 3.8</name>

Expand Down Expand Up @@ -34,7 +34,7 @@
<mule.version>3.8.1</mule.version>
<mule.tools.version>1.2</mule.tools.version>

<elastic-apm.version>1.16.0</elastic-apm.version>
<elastic-apm.version>1.17.0</elastic-apm.version>
<version.byte-buddy>1.10.8</version.byte-buddy>

<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@ public void onNotification(PipelineMessageNotification notification) {
transactionUtils.startTransactionIfNone(notification);
break;

case PipelineMessageNotification.PROCESS_COMPLETE:
case PipelineMessageNotification.PROCESS_END:
transactionUtils.endTransactionIfNeeded(notification);
break;

case PipelineMessageNotification.PROCESS_COMPLETE:
// Ignored, as it is skipped when flow exception is thrown
break;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.elastic.apm.mule.utils;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.log4j.MDC;
import org.mule.api.MessagingException;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;
Expand All @@ -22,6 +23,9 @@
*/
public class TransactionUtils {

private static final String MDC_TRANSACTION_ID = "transaction.id";
private static final String MDC_TRACE_ID = "trace.id";

@Autowired
private SpanStore txMap;

Expand Down Expand Up @@ -56,6 +60,9 @@ public void startTransactionIfNone(PipelineMessageNotification notification) {

txMap.storeTransactionOrSpan(messageId, notification, transaction);

if (isLogCorrelationEnabled())
addMdcHeaders(transaction);

}

/**
Expand All @@ -82,9 +89,27 @@ public void endTransactionIfNeeded(PipelineMessageNotification notification) {
transaction.captureException(exceptionThrown);

transaction.end(notification.getTimestamp() * 1_000);

if (isLogCorrelationEnabled())
removeMdcHeaders();
}
}

private boolean isLogCorrelationEnabled() {
return "true".equals(System.getProperty("elastic.apm.enable_log_correlation"))
|| "true".equals(System.getenv("ELASTIC_APM_ENABLE_LOG_CORRELATION"));
}

private void addMdcHeaders(Transaction transaction) {
MDC.put(MDC_TRACE_ID, transaction.getTraceId());
MDC.put(MDC_TRANSACTION_ID, transaction.getId());
}

private void removeMdcHeaders() {
MDC.remove(MDC_TRACE_ID);
MDC.remove(MDC_TRANSACTION_ID);
}

private MuleMessage getMuleMessage(PipelineMessageNotification notification) {
return ((MuleEvent) notification.getSource()).getMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.mule.tck.junit4.FunctionalTestCase;

import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.ElasticApmTracerBuilder;
import co.elastic.apm.agent.impl.error.ErrorCapture;
import co.elastic.apm.agent.impl.transaction.Span;
Expand Down Expand Up @@ -65,11 +66,12 @@ public ErrorCapture answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(reporter).report(Mockito.any(ErrorCapture.class));

Mockito.doNothing().when(reporter).scheduleMetricReporting(Mockito.any(), Mockito.anyLong(), Mockito.any());

ElasticApmAgent.initInstrumentation(new ElasticApmTracerBuilder().reporter(reporter).build(),
ByteBuddyAgent.install());
ElasticApmTracer tracer = new ElasticApmTracerBuilder().reporter(reporter).build();
tracer.start();
ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install());

// Skip real initialisation so it is not triggered in the flows for tests
ApmClient.setInitialised();
Expand Down

0 comments on commit e02738a

Please sign in to comment.