generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed problems with camel kafka instrumentation
- Loading branch information
Showing
10 changed files
with
295 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...src/main/java/org/apache/camel/component/kafka/consumer/support/KafkaRecordProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.apache.camel.component.kafka.consumer.support; | ||
|
||
import org.apache.camel.Exchange; | ||
import org.apache.camel.spi.ExceptionHandler; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import org.apache.kafka.common.TopicPartition; | ||
|
||
import com.newrelic.api.agent.DestinationType; | ||
import com.newrelic.api.agent.MessageConsumeParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.TransportType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.newrelic.instrumentation.camel.kafka.ConsumerRecordHeaders; | ||
|
||
@Weave | ||
public abstract class KafkaRecordProcessor { | ||
|
||
@Trace(dispatcher = true) | ||
public ProcessingResult processExchange(Exchange exchange, TopicPartition partition, boolean partitionHasNext, | ||
boolean recordHasNext, ConsumerRecord<Object, Object> record, ProcessingResult lastResult, ExceptionHandler exceptionHandler) { | ||
ConsumerRecordHeaders headers = new ConsumerRecordHeaders(record); | ||
NewRelic.getAgent().getTransaction().acceptDistributedTraceHeaders(TransportType.Kafka, headers); | ||
MessageConsumeParameters params = MessageConsumeParameters.library("Kafka").destinationType(DestinationType.NAMED_TOPIC).destinationName(partition.topic()).inboundHeaders(headers).build(); | ||
NewRelic.getAgent().getTracedMethod().reportAsExternal(params); | ||
return Weaver.callOriginal(); | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
...in/java/org/apache/camel/component/kafka/consumer/support/KafkaRecordProcessorFacade.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
camel-kafka-3.18.3/src/main/java/org/apache/camel/component/kafka/NRKafkaWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.apache.camel.component.kafka; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.DestinationType; | ||
import com.newrelic.api.agent.MessageProduceParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
public class NRKafkaWrapper { | ||
|
||
private static boolean isTransformed = false; | ||
|
||
public static ThreadLocal<String> currentTopic = new ThreadLocal<>(); | ||
public static ThreadLocal<Boolean> isSingleMessage = new ThreadLocal<>(); | ||
|
||
public NRKafkaWrapper() { | ||
if(!isTransformed) { | ||
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); | ||
isTransformed = true; | ||
} | ||
} | ||
|
||
@Trace | ||
public void sendMessage() { | ||
String topic = currentTopic.get(); | ||
if(topic == null) topic = "UnknownTopic"; | ||
currentTopic.remove(); | ||
isSingleMessage.remove(); | ||
MessageProduceParameters params = MessageProduceParameters.library("Kafka").destinationType(DestinationType.NAMED_TOPIC).destinationName(topic).outboundHeaders(null).build(); | ||
NewRelic.getAgent().getTracedMethod().reportAsExternal(params); | ||
} | ||
|
||
} |
Oops, something went wrong.