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 #41 from michaelhyatt/update_1.19.0
Browse files Browse the repository at this point in the history
* Update the agent to Java APM agent 1.19.0
* Fix for crash on DevKit steps not implementing AnnotatedObject #39 
* Turning the lambda into explicit anonymous class and surrounding with try/catch - opportunistic fix for #40
  • Loading branch information
michaelhyatt authored Nov 21, 2020
2 parents b277277 + dafab6e commit 9215eea
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 34 deletions.
22 changes: 20 additions & 2 deletions apm-mule3-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>co.elastic.apm</groupId>
<artifactId>apm-mule3-agent</artifactId>

<version>1.17.0</version>
<version>1.19.0</version>
<packaging>${packaging}</packaging>
<name>Mule apm-mule3-agent Application</name>

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

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

<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -224,6 +224,24 @@
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-apikit</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-devkit-support</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-objectstore</artifactId>
<version>1.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.mule.api.AnnotatedObject;
import org.mule.api.MuleEvent;
import org.mule.api.context.notification.ServerNotification;
import org.mule.api.processor.MessageProcessor;
import org.mule.context.notification.MessageProcessorNotification;

/**
Expand All @@ -18,7 +19,15 @@ public class AnnotatedObjectUtils {
private static final String HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION = "http://www.mulesoft.org/schema/mule/documentation";

public static String getProcessorName(MessageProcessorNotification notification) {
AnnotatedObject annotObj = (AnnotatedObject) notification.getProcessor();
AnnotatedObject annotObj;
MessageProcessor obj = notification.getProcessor();

try {
annotObj = (AnnotatedObject) obj;
} catch (ClassCastException e) {
return obj.getClass().getSimpleName();
}

QName qName = new QName(HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION, NAME);
String step = (String) annotObj.getAnnotation(qName);
return step;
Expand All @@ -30,7 +39,15 @@ public static String getFlowName(ServerNotification notification) {
}

public static String getProcessorType(MessageProcessorNotification notification) {
AnnotatedObject annotObj = (AnnotatedObject) notification.getProcessor();
AnnotatedObject annotObj;
Object obj = notification.getProcessor();

try {
annotObj = (AnnotatedObject) obj;
} catch (ClassCastException e) {
return obj.getClass().getSimpleName().toLowerCase();
}

QName qName = new QName(HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION, SOURCE_ELEMENT);
String step = (String) annotObj.getAnnotation(qName);
String value = step.split("[ <]")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.DataType;
import org.mule.api.transport.PropertyScope;
import org.mule.context.notification.MessageProcessorNotification;
import org.springframework.beans.factory.annotation.Autowired;

import co.elastic.apm.api.HeaderInjector;
import co.elastic.apm.api.Span;

/**
Expand Down Expand Up @@ -36,8 +38,18 @@ public void startSpan(MessageProcessorNotification notification) {

// Update MuleMessage with distributed tracing properties set into
// outboundProperty
span.injectTraceHeaders(
(headerName, headerValue) -> message.setProperty(headerName, headerValue, PropertyScope.OUTBOUND));
span.injectTraceHeaders(new HeaderInjector() {

@Override
public void addHeader(String headerName, String headerValue) {
try {
message.setProperty(headerName, headerValue, PropertyScope.OUTBOUND, DataType.STRING_DATA_TYPE);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

createFlowvarSpanTags(notification, span, processorName);

Expand All @@ -60,7 +72,7 @@ private void createFlowvarSpanTags(MessageProcessorNotification notification, Sp
}

private void updateSpanTags(Span span, ImmutablePair<String, Object> pair) {
span.addLabel("flowVar:" + pair.getLeft(), pair.getRight().toString());
span.setLabel("flowVar:" + pair.getLeft(), pair.getRight().toString());
}

private String getMessageId(MuleMessage message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void startTransactionIfNone(PipelineMessageNotification notification) {
if (PropertyUtils.isInputPropertyCaptureEnabled())
PropertyUtils.getInputProperties(muleMessage).forEach(pair -> updateProperties(pair, transaction, "in"));

transaction.addLabel("messageId", messageId);
transaction.setLabel("messageId", messageId);

txMap.storeTransactionOrSpan(messageId, notification, transaction);

Expand Down Expand Up @@ -122,17 +122,17 @@ private void updateProperties(ImmutablePair<String, Object> pair, Transaction tr

if (value instanceof String) {
stringValue = (String) value;
transaction.addLabel(prefix + ":" + key, stringValue);
transaction.setLabel(prefix + ":" + key, stringValue);

} else if (value instanceof ParameterMap) {
ParameterMap map = (ParameterMap) value;

map.keySet().stream()
.forEach((key2) -> transaction.addLabel(prefix + ":" + key + ":" + key2, map.get(key2)));
.forEach((key2) -> transaction.setLabel(prefix + ":" + key + ":" + key2, map.get(key2)));

} else {
stringValue = "???";
transaction.addLabel(prefix + ":" + key, stringValue);
transaction.setLabel(prefix + ":" + key, stringValue);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public ErrorCapture answer(InvocationOnMock invocation) throws Throwable {
}
}).when(reporter).report(Mockito.any(ErrorCapture.class));

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

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

// Skip real initialisation so it is not triggered in the flows for tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,28 @@ public void testFlowWith4steps() throws Exception {
assertEquals("201", tx.getContext().getLabel("out:http.response"));
}

@Test
public void testFlowWithObjstore() throws Exception {

runFlow("objstore-testFlow");

Mockito.verify(reporter, Mockito.times(3)).report(Mockito.any(Span.class));
Mockito.verify(reporter, Mockito.times(1)).report(Mockito.any(Transaction.class));
Mockito.verify(reporter, Mockito.times(0)).report(Mockito.any(ErrorCapture.class));

assertEquals("objstore-testFlow", tx.getNameAsString());

assertEquals("StoreMessageProcessor", spans.get(0).getNameAsString());
assertEquals("storemessageprocessor", spans.get(0).getType().toString());
assertEquals("ContainsMessageProcessor", spans.get(1).getNameAsString());
assertEquals("containsmessageprocessor", spans.get(1).getType().toString());
assertEquals("RemoveMessageProcessor", spans.get(2).getNameAsString());
assertEquals("removemessageprocessor", spans.get(2).getType().toString());
}

@Override
protected String getConfigResources() {
return "test_tracer.xml, test1.xml, test2.xml, parallel_flow.xml";
return "test_tracer.xml, test1.xml, test2.xml, parallel_flow.xml, objstore-test.xml";
}

}
15 changes: 15 additions & 0 deletions apm-mule3-agent/src/test/resources/objstore-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd">
<objectstore:config name="ObjectStore__Connector" doc:name="ObjectStore: Connector"/>
<flow name="objstore-testFlow">
<objectstore:store config-ref="ObjectStore__Connector" key="abc" value-ref="#[123]" overwrite="true" doc:name="ObjectStore"/>
<objectstore:contains config-ref="ObjectStore__Connector" key="abc" doc:name="ObjectStore"/>
<objectstore:remove config-ref="ObjectStore__Connector" key="abc" ignoreNotExists="true" doc:name="ObjectStore"/>
</flow>
</mule>
21 changes: 16 additions & 5 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.17.0</version>
<version>1.19.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.17.0</elastic-apm.version>
<elastic-apm.version>1.19.0</elastic-apm.version>
<version.byte-buddy>1.10.8</version.byte-buddy>

<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -217,7 +217,18 @@
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-devkit-support</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-objectstore</artifactId>
<version>1.3.3</version>
<scope>provided</scope>
</dependency>

<!-- 3.8.1 is missing this, but 3.8.5 has it -->
<dependency>
Expand All @@ -239,7 +250,7 @@
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>http://repository.mulesoft.org/releases/</url>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
Expand All @@ -248,7 +259,7 @@
<id>mulesoft-release</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>http://repository.mulesoft.org/releases/</url>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.mule.api.AnnotatedObject;
import org.mule.api.MuleEvent;
import org.mule.api.context.notification.ServerNotification;
import org.mule.api.processor.MessageProcessor;
import org.mule.context.notification.MessageProcessorNotification;

/**
Expand All @@ -18,7 +19,15 @@ public class AnnotatedObjectUtils {
private static final String HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION = "http://www.mulesoft.org/schema/mule/documentation";

public static String getProcessorName(MessageProcessorNotification notification) {
AnnotatedObject annotObj = (AnnotatedObject) notification.getProcessor();
AnnotatedObject annotObj;
MessageProcessor obj = notification.getProcessor();

try {
annotObj = (AnnotatedObject) obj;
} catch (ClassCastException e) {
return obj.getClass().getSimpleName();
}

QName qName = new QName(HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION, NAME);
String step = (String) annotObj.getAnnotation(qName);
return step;
Expand All @@ -30,7 +39,15 @@ public static String getFlowName(ServerNotification notification) {
}

public static String getProcessorType(MessageProcessorNotification notification) {
AnnotatedObject annotObj = (AnnotatedObject) notification.getProcessor();
AnnotatedObject annotObj;
Object obj = notification.getProcessor();

try {
annotObj = (AnnotatedObject) obj;
} catch (ClassCastException e) {
return obj.getClass().getSimpleName().toLowerCase();
}

QName qName = new QName(HTTP_WWW_MULESOFT_ORG_SCHEMA_MULE_DOCUMENTATION, SOURCE_ELEMENT);
String step = (String) annotObj.getAnnotation(qName);
String value = step.split("[ <]")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.DataType;
import org.mule.api.transport.PropertyScope;
import org.mule.context.notification.MessageProcessorNotification;
import org.springframework.beans.factory.annotation.Autowired;

import co.elastic.apm.api.HeaderInjector;
import co.elastic.apm.api.Span;

/**
Expand Down Expand Up @@ -36,8 +38,18 @@ public void startSpan(MessageProcessorNotification notification) {

// Update MuleMessage with distributed tracing properties set into
// outboundProperty
span.injectTraceHeaders(
(headerName, headerValue) -> message.setProperty(headerName, headerValue, PropertyScope.OUTBOUND));
span.injectTraceHeaders(new HeaderInjector() {

@Override
public void addHeader(String headerName, String headerValue) {
try {
message.setProperty(headerName, headerValue, PropertyScope.OUTBOUND, DataType.STRING_DATA_TYPE);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

createFlowvarSpanTags(notification, span, processorName);

Expand All @@ -60,7 +72,7 @@ private void createFlowvarSpanTags(MessageProcessorNotification notification, Sp
}

private void updateSpanTags(Span span, ImmutablePair<String, Object> pair) {
span.addLabel("flowVar:" + pair.getLeft(), pair.getRight().toString());
span.setLabel("flowVar:" + pair.getLeft(), pair.getRight().toString());
}

private String getMessageId(MuleMessage message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void startTransactionIfNone(PipelineMessageNotification notification) {
if (PropertyUtils.isInputPropertyCaptureEnabled())
PropertyUtils.getInputProperties(muleMessage).forEach(pair -> updateProperties(pair, transaction, "in"));

transaction.addLabel("messageId", messageId);
transaction.setLabel("messageId", messageId);

txMap.storeTransactionOrSpan(messageId, notification, transaction);

Expand Down Expand Up @@ -123,17 +123,17 @@ private void updateProperties(ImmutablePair<String, Object> pair, Transaction tr

if (value instanceof String) {
stringValue = (String) value;
transaction.addLabel(prefix + ":" + key, stringValue);
transaction.setLabel(prefix + ":" + key, stringValue);

} else if (value instanceof ParameterMap) {
ParameterMap map = (ParameterMap) value;

map.keySet().stream()
.forEach((key2) -> transaction.addLabel(prefix + ":" + key + ":" + key2, map.get(key2)));
.forEach((key2) -> transaction.setLabel(prefix + ":" + key + ":" + key2, map.get(key2)));

} else {
stringValue = "???";
transaction.addLabel(prefix + ":" + key, stringValue);
transaction.setLabel(prefix + ":" + key, stringValue);
}

}
Expand Down
Loading

0 comments on commit 9215eea

Please sign in to comment.