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

Commit

Permalink
Added tests and header propagation to start transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
user1 committed Nov 2, 2020
1 parent d6778fb commit 936e185
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mule4-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic.apm</groupId>
<artifactId>mule4-agent</artifactId>
<version>0.2.0</version>
<version>0.3.0</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
Expand Up @@ -11,6 +11,7 @@
import co.elastic.apm.api.ElasticApm;
import co.elastic.apm.api.Span;
import co.elastic.apm.api.Transaction;
import co.elastic.apm.mule4.agent.tracing.HttpTracingUtils;
import co.elastic.apm.mule4.agent.transaction.TransactionStore;

/*
Expand Down Expand Up @@ -38,13 +39,23 @@ public static void startSpan(TransactionStore transactionStore, MessageProcessor

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

checkAndPropagateParentTraceId(span, notification);

setSpanDetails(span, notification);

String spanId = getSpanId(notification);

transactionStore.addSpan(transactionId, spanId, span);
}

private static void checkAndPropagateParentTraceId(Span span, MessageProcessorNotification notification) {

// Propagate trace.id through HTTP
if (HttpTracingUtils.isHttpRequester(notification))
HttpTracingUtils.propagateTraceIdHeader(span, notification);

}

public static String getSpanId(MessageProcessorNotification notification) {
return notification.getInfo().getComponent().getLocation().getLocation();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package co.elastic.apm.mule4.agent.tracing;

import org.mule.extension.http.api.HttpRequestAttributes;
import org.mule.runtime.api.component.ComponentIdentifier;
import org.mule.runtime.api.metadata.TypedValue;
import org.mule.runtime.api.notification.MessageProcessorNotification;
import org.mule.runtime.api.notification.PipelineMessageNotification;
import org.mule.runtime.api.util.MultiMap;

import co.elastic.apm.api.Span;

public class HttpTracingUtils {

private static final String HTTP_REQUEST_NAMESPACE = "http://www.mulesoft.org/schema/mule/http";
private static final String HTTP_REQUEST_NAME = "request";
public static final String ELASTIC_APM_TRACEPARENT = "elastic-apm-traceparent";

public static boolean isHttpEvent(PipelineMessageNotification notification) {
Expand Down Expand Up @@ -36,4 +42,18 @@ private static TypedValue<Object> extractAttributes(PipelineMessageNotification
return notification.getEvent().getMessage().getAttributes();
}

public static boolean isHttpRequester(MessageProcessorNotification notification) {

ComponentIdentifier identifier = notification.getInfo().getComponent().getIdentifier();
String name = identifier.getName();
String namespace = identifier.getNamespaceUri();

return HTTP_REQUEST_NAME.equals(name) && HTTP_REQUEST_NAMESPACE.equals(namespace);
}

public static void propagateTraceIdHeader(Span span, MessageProcessorNotification notification) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public void testNoTraceIdPropagation() throws Exception {

}

@Test
public void testTraceIdPropagationThroughHttp() throws Exception {

HttpGet getRequest = new HttpGet("http://localhost:8998");
getRequest.addHeader(HttpTracingUtils.ELASTIC_APM_TRACEPARENT, TRACE_PARENT1);

HttpClient httpClient = HttpClientBuilder.create().build();

HttpResponse response = httpClient.execute(getRequest);


}

@Override
protected String getConfigFile() {
return "DistributedTracingTest.xml";
Expand Down

0 comments on commit 936e185

Please sign in to comment.