Skip to content

Commit

Permalink
Merge pull request #23 from newrelic-experimental/camel-updates
Browse files Browse the repository at this point in the history
Camel updates
  • Loading branch information
dhilpipre committed Jan 29, 2024
2 parents 38c820d + 60fb9af commit 9de8e78
Show file tree
Hide file tree
Showing 162 changed files with 1,374 additions and 4,893 deletions.
3 changes: 1 addition & 2 deletions camel-core-3.18/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jar {
attributes 'Implementation-Vendor': 'New Relic Labs'
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
attributes 'Implementation-Version': 1.0
attributes 'Agent-Class': 'com.newrelic.instrumentation.labs.apache.camel.processors.CamelCorePremain'
}
}

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.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

@WeaveWithAnnotation(type = MatchType.Interface, annotationClasses = {"org.apache.camel.Pattern"})
public abstract class Pattern_instrumentation {
@WeaveWithAnnotation(annotationClasses = {"org.apache.camel.Pattern"})
@WeaveIntoAllMethods
@Trace
private static void instrumentation() {
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
StackTraceElement first = traces[1];
String methodName = first.getMethodName();
String classname = first.getClassName();
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] { "Custom", "Camel", "Handler", classname, methodName });
}

@WeaveWithAnnotation(annotationClasses = {"org.apache.camel.Pattern"})
@WeaveIntoAllMethods
@Trace
private static void instrumentation() {

StackTraceElement[] traces = Thread.currentThread().getStackTrace();
StackTraceElement first = traces[1];
String methodName = first.getMethodName();
String classname = first.getClassName();
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Camel","Handler",classname,methodName);
}

}

This file was deleted.

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();
}
}
Loading

0 comments on commit 9de8e78

Please sign in to comment.