Skip to content

Commit

Permalink
corrected problems that were causing two extensions to load when only…
Browse files Browse the repository at this point in the history
… one should
  • Loading branch information
dhilpipre committed Jan 4, 2024
1 parent 35c52bc commit e51965e
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 314 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.spi.Synchronization;

import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;

public class Util {

public static final String NRTOKENPROPERTY = "newrelic.asynctoken";
private static final List<String> ignores;

static {
Expand Down Expand Up @@ -58,26 +56,6 @@ public static String getMethodName(Method m) {
return classname + "." + methodName;
}

public static void addCompletionIfNeeded(ExtendedExchange exchange) {
if(exchange == null) return;

List<Synchronization> completions = exchange.handoverCompletions();
if(completions == null || completions.isEmpty()) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
} else {
boolean hasNR = false;
for(int i=0; i<completions.size() && !hasNR; i++) {
Synchronization sync = completions.get(i);
hasNR = sync instanceof NRSynchronization;
}
if(!hasNR) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
}
}
}

public static void recordExchange(Map<String, Object> attributes, Exchange exchange) {
if(exchange != null) {
recordValue(attributes, "ExchangeId", exchange.getExchangeId());
Expand Down
23 changes: 0 additions & 23 deletions camel-core-3.18/src/main/java/org/apache/camel/BatchConsumer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.nr.instrumentation.apache.camel.CamelHeaders;
import com.nr.instrumentation.apache.camel.Util;

@Weave(type=MatchType.Interface)
public abstract class Endpoint {
@Weave(type=MatchType.Interface, originalName = "org.apache.camel.Endpoint")
public abstract class Endpoint_instrumentation {


public abstract String getEndpointUri();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.camel.component.file;

import java.util.HashMap;
import java.util.Queue;

import org.apache.camel.Processor;
import org.apache.camel.support.ScheduledBatchPollingConsumer;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.apache.camel.Util;

@Weave(type = MatchType.BaseClass)
public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsumer {

protected GenericFileEndpoint<T> endpoint = Weaver.callOriginal();


public GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations, GenericFileProcessStrategy<T> processStrategy) {
super( endpoint, processor);
}

@Trace(dispatcher = true)
public int processBatch(Queue<Object> exchanges) {
HashMap<String, Object> attributes = new HashMap<>();
int numToProcess = exchanges.size();
if(numToProcess == 0) {
NewRelic.getAgent().getTransaction().ignore();
} else {
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Camel",getClass().getName(),"processBatch"});
Util.recordValue(attributes, "RouteId", getRouteId());
Util.recordValue(attributes, "InputQueueSize", numToProcess);
String routeId = getRouteId();

NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true,"CamelFileConsumer", new String[] {"CamelFileConsumer", routeId != null ? getRouteId() : endpoint.toString()});
}


int result=Weaver.callOriginal();
Util.recordValue(attributes, "NumbertOfBatchProcessed", result);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

return result;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.spi.Synchronization;

import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;

public class Util {

public static final String NRTOKENPROPERTY = "newrelic.asynctoken";
private static final List<String> ignores;

static {
Expand Down Expand Up @@ -57,27 +55,7 @@ public static String getMethodName(Method m) {

return classname + "." + methodName;
}

public static void addCompletionIfNeeded(ExtendedExchange exchange) {
if(exchange == null) return;

List<Synchronization> completions = exchange.handoverCompletions();
if(completions == null || completions.isEmpty()) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
} else {
boolean hasNR = false;
for(int i=0; i<completions.size() && !hasNR; i++) {
Synchronization sync = completions.get(i);
hasNR = sync instanceof NRSynchronization;
}
if(!hasNR) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
}
}
}


public static void recordExchange(Map<String, Object> attributes, Exchange exchange) {
if(exchange != null) {
recordValue(attributes, "ExchangeId", exchange.getExchangeId());
Expand Down
23 changes: 0 additions & 23 deletions camel-core-3.9/src/main/java/org/apache/camel/BatchConsumer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.nr.instrumentation.apache.camel.CamelHeaders;
import com.nr.instrumentation.apache.camel.Util;

@Weave(type=MatchType.Interface)
public abstract class Endpoint {
@Weave(type=MatchType.Interface, originalName = "org.apache.camel.Endpoint")
public abstract class Endpoint_instrumentation {


public abstract String getEndpointUri();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.camel.component.file;

import java.util.HashMap;
import java.util.Queue;

import org.apache.camel.Processor;
import org.apache.camel.support.ScheduledBatchPollingConsumer;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TransactionNamePriority;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.apache.camel.Util;

@Weave(type = MatchType.BaseClass)
public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsumer {

protected GenericFileEndpoint<T> endpoint = Weaver.callOriginal();


public GenericFileConsumer(GenericFileEndpoint<T> endpoint, Processor processor, GenericFileOperations<T> operations, GenericFileProcessStrategy<T> processStrategy) {
super( endpoint, processor);
}

@Trace(dispatcher = true)
public int processBatch(Queue<Object> exchanges) {
HashMap<String, Object> attributes = new HashMap<>();
int numToProcess = exchanges.size();
if(numToProcess == 0) {
NewRelic.getAgent().getTransaction().ignore();
} else {
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] {"Custom","Camel",getClass().getName(),"processBatch"});
Util.recordValue(attributes, "RouteId", getRouteId());
Util.recordValue(attributes, "InputQueueSize", numToProcess);
String routeId = getRouteId();

NewRelic.getAgent().getTransaction().setTransactionName(TransactionNamePriority.FRAMEWORK_LOW, true,"CamelFileConsumer", new String[] {"CamelFileConsumer", routeId != null ? getRouteId() : endpoint.toString()});
}


int result=Weaver.callOriginal();
Util.recordValue(attributes, "NumbertOfBatchProcessed", result);
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);

return result;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public void run() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangeExtension;
import org.apache.camel.spi.Synchronization;

import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;

public class Util {

public static final String NRTOKENPROPERTY = "newrelic.asynctoken";
private static final List<String> ignores;

static {
Expand Down Expand Up @@ -58,26 +56,6 @@ public static String getMethodName(Method m) {
return classname + "." + methodName;
}

public static void addCompletionIfNeeded(ExchangeExtension exchange) {
if(exchange == null) return;

List<Synchronization> completions = exchange.handoverCompletions();
if(completions == null || completions.isEmpty()) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
} else {
boolean hasNR = false;
for(int i=0; i<completions.size() && !hasNR; i++) {
Synchronization sync = completions.get(i);
hasNR = sync instanceof NRSynchronization;
}
if(!hasNR) {
NRSynchronization nrSync = new NRSynchronization();
exchange.addOnCompletion(nrSync);
}
}
}

public static void recordExchange(Map<String, Object> attributes, Exchange exchange) {
if(exchange != null) {
recordValue(attributes, "ExchangeId", exchange.getExchangeId());
Expand Down
Loading

0 comments on commit e51965e

Please sign in to comment.