Skip to content

Commit

Permalink
migrated changes from 3.18 to 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilpipre committed Jan 29, 2024
1 parent 50e8d7e commit ecd8916
Show file tree
Hide file tree
Showing 110 changed files with 584 additions and 4,063 deletions.
2 changes: 1 addition & 1 deletion camel-core-3.18/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jar {
}

verifyInstrumentation {
passes 'org.apache.camel:camel-core:[3.18.0,4.0.0)'
passes 'org.apache.camel:camel-core:[3.18.0,4.0.0]'
excludeRegex '.*M[1-9]'
excludeRegex '.*RC[1-9]'
}

This file was deleted.

2 changes: 1 addition & 1 deletion camel-core-4.0.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jar {
}

verifyInstrumentation {
passes 'org.apache.camel:camel-core:[4.0.0,4.1.0)'
passes 'org.apache.camel:camel-core:[4.0.0,)'
excludeRegex '.*M[1-9]'
excludeRegex '.*RC[1-9]'
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.TransportType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName="org.apache.camel.processor.aggregate.AggregateProcessor")
public abstract class AggregateProcessor_instrumentation {

@Trace(dispatcher = true)
@Trace
protected boolean doProcess(Exchange exchange, AsyncCallback callback) {
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
Expand All @@ -26,19 +25,17 @@ protected boolean doProcess(Exchange exchange, AsyncCallback callback) {
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","AggregateProcessor","doProcess",routeID});
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "CamelProcessor", new String[] {"AggregateProcessor",routeID});
}
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));
return Weaver.callOriginal();
}

@Trace(dispatcher=true)
@Trace
protected boolean doProcess(Exchange exchange, String key, AsyncCallback callback, boolean sync) {
String routeID = exchange != null ? exchange.getFromRouteId() : null;
if(routeID != null && !routeID.isEmpty()) {
NewRelic.addCustomParameter("From Route ID", routeID);
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","AggregateProcessor","doProcess",routeID});
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "CamelProcessor", new String[] {"AggregateProcessor",routeID});
}
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));

return Weaver.callOriginal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public String getHeader(String name) {
@Override
public Collection<String> getHeaderNames() {
Map<String, Object> props = exchange.getProperties();
Message msg = exchange.getMessage();
if(msg != null) {
Map<String, Object> msgHeaders = msg.getHeaders();
props.putAll(msgHeaders);
}

return props != null ? props.keySet() : Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.nr.instrumentation.apache.camel;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.AsyncCallback;
import org.apache.camel.Exchange;
import org.apache.camel.Message;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.TransportType;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
Expand All @@ -20,19 +18,16 @@ public abstract class CamelInternalProcessor_instrumentation {

@Trace(dispatcher = true)
public boolean process(Exchange exchange, AsyncCallback callback) {
Map<String, Object> attributes = new HashMap<String, Object>();
HashMap<String, Object> attributes = new HashMap<>();
Util.recordExchange(attributes, exchange);
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
if(exchange != null && exchange.getFromRouteId() != null) {
traced.setMetricName("Custom","CamelInternalProcessor","process",exchange.getFromRouteId());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
String routeId = exchange != null ? exchange.getFromRouteId() : null;
if(exchange != null) {
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));
}
if(!attributes.isEmpty()) {
traced.addCustomAttributes(attributes);
if(routeId != null && !routeId.isEmpty()) {
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "CamelInternalProcessor", "Camel",getClass().getSimpleName(),routeId);
}
Message message = exchange.getMessage();


NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelMessageHeaders(message));
return Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
package com.nr.instrumentation.apache.camel;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.AsyncCallback;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.TransportType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName="org.apache.camel.processor.ChoiceProcessor")
public abstract class ChoiceProcessor_instrumentation {

@Trace(dispatcher=true)
public abstract String getId();

public boolean process(Exchange exchange, AsyncCallback callback) {
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
String classname = getClass().getSimpleName();
CamelHeaders headers = new CamelHeaders(exchange);
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, headers);
Endpoint endpoint = exchange.getFromEndpoint();
if(endpoint != null) {
String endpointURI = endpoint.getEndpointBaseUri();
if(endpointURI != null && !endpointURI.isEmpty()) {
Util.recordValue(attributes, "EndpointURI", endpointURI);
}
}
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
NewRelic.getAgent().getTracedMethod().addCustomAttribute("ChoiceProcessor-ID", getId());
String routeID = exchange != null ? exchange.getFromRouteId() : null;
if(routeID != null && !routeID.isEmpty()) {
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom",classname,"process",routeID});
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "ChoiceProcessor", new String[] {"ChoiceProcessor",routeID});
}
return Weaver.callOriginal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,27 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.camel.AsyncCallback;
import org.apache.camel.Exchange;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransportType;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type=MatchType.BaseClass,originalName="org.apache.camel.processor.MulticastProcessor")
public abstract class MultiCastProcessor_instrumentation {

@Trace(dispatcher=true)
public boolean process(Exchange exchange, AsyncCallback callback) {
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));

return Weaver.callOriginal();
}

@Weave(originalName="org.apache.camel.processor.MulticastProcessor$MulticastTask", type = MatchType.BaseClass)
protected static abstract class MulticastTask {


@Trace(dispatcher=true)
@Trace
protected void doDone(Exchange exchange, boolean forceExhaust) {
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Camel","MulticastTask",getClass().getSimpleName(),"doDone");
Weaver.callOriginal();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.nr.instrumentation.apache.camel;

import java.util.concurrent.CompletableFuture;

import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;

import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.Weaver;

public class NRAsyncProcessorStart implements AsyncProcessor {

private static boolean isTransformed = false;

private AsyncProcessor delegate = null;
private String consumer = null;

public NRAsyncProcessorStart(AsyncProcessor processor) {
delegate = processor;
if(!isTransformed) {
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass());
isTransformed = true;
}
}

@Override
@Trace(dispatcher = true)
public void process(Exchange exchange) throws Exception {
if(consumer != null) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Camel","AsyncConsumerStart",consumer,"process-sync");
}
Weaver.callOriginal();
}

@Override
@Trace(dispatcher = true)
public boolean process(Exchange exchange, AsyncCallback callback) {
if(consumer != null) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Camel","AsyncConsumerStart",consumer,"process-async");
}
return delegate.process(exchange, callback);
}

@Override
@Trace(dispatcher = true)
public CompletableFuture<Exchange> processAsync(Exchange exchange) {
if(consumer != null) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Camel","AsyncConsumerStart",consumer,"processAsync");
}
return delegate.processAsync(exchange);
}

public void setConsumer(String s) {
consumer = s;
}
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,58 @@
package com.nr.instrumentation.apache.camel;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
import org.apache.camel.Route;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.TransportType;

public class NRAsyncProcessorWrapper extends NRProcessorWrapper implements AsyncProcessor {
public class NRAsyncProcessorWrapper implements AsyncProcessor {

public NRAsyncProcessorWrapper(AsyncProcessor p,Route r) {
super(p,r);
private AsyncProcessor delegate = null;
protected Token token = null;
protected static boolean isTransformed = false;


public NRAsyncProcessorWrapper(AsyncProcessor d, Token t) {
if(!isTransformed) {
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass());
isTransformed = true;
}
token = t;
delegate = d;
}

@Override
@Trace(dispatcher=true)
@Trace(async = true)
public boolean process(Exchange exchange, AsyncCallback callback) {
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));
String[] names;
if(route != null) {
String routeId = route.getId();
if(routeId != null && !routeId.isEmpty()) {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process",routeId};
NewRelic.getAgent().getTracedMethod().addCustomAttribute("RouteId", routeId);
NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, false, "Processor", "Process",routeId);
} else {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process"};
}
} else {
Object timerTaskValue = exchange.getProperty(Exchange.TIMER_NAME);
if(timerTaskValue != null) {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process","TimerTask",timerTaskValue.toString()};
}
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process"};

if(token != null) {
token.linkAndExpire();
token = null;
}
NewRelic.getAgent().getTracedMethod().setMetricName(names);
return ((AsyncProcessor)delegate).process(exchange, callback);
return delegate.process(exchange,callback);
}

@Override
@Trace(dispatcher = true)
@Trace(async = true)
public CompletableFuture<Exchange> processAsync(Exchange exchange) {
Map<String, Object> attributes = new HashMap<String, Object>();
Util.recordExchange(attributes, exchange);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Other, new CamelHeaders(exchange));
String[] names;
if(route != null) {
String routeId = route.getId();
if(routeId != null && !routeId.isEmpty()) {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process",routeId};
NewRelic.getAgent().getTracedMethod().addCustomAttribute("RouteId", routeId);
} else {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"process"};
}
} else {
names = new String[] {"Custom","AsyncProcessor",delegate.getClass().getSimpleName(),"processAsync"};

if(token != null) {
token.linkAndExpire();
token = null;
}
return delegate.processAsync(exchange);
}

@Trace(async = true)
public void process(Exchange exchange) throws Exception {
if(token != null) {
token.linkAndExpire();
token = null;
}
NewRelic.getAgent().getTracedMethod().setMetricName(names);
return ((AsyncProcessor)delegate).processAsync(exchange);
delegate.process(exchange);
}

}
Loading

0 comments on commit ecd8916

Please sign in to comment.