Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
2,453 additions
and
10 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
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,21 @@ | ||
|
||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("org.apache.kafka:connect-runtime:3.2.3") | ||
|
||
testImplementation("org.mockito:mockito-inline:$mockitoVersion") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.kafka-connect-spans-2.0.0', | ||
'Implementation-Title-Alias': 'kafka-connect' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'org.apache.kafka:connect-runtime:[2.0.0,3.3.0)' | ||
} | ||
|
||
site { | ||
title 'Kafka' | ||
type 'Messaging' | ||
} |
89 changes: 89 additions & 0 deletions
89
...connect-spans-2.0.0/src/main/java/com/nr/instrumentation/kafka/connect/HeaderWrapper.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,89 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.instrumentation.kafka.connect; | ||
|
||
import com.newrelic.api.agent.HeaderType; | ||
import com.newrelic.api.agent.Headers; | ||
import org.apache.kafka.common.header.Header; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Objects; | ||
|
||
public class HeaderWrapper implements Headers { | ||
|
||
private final org.apache.kafka.common.header.Headers delegate; | ||
|
||
public HeaderWrapper(org.apache.kafka.common.header.Headers headers) { | ||
this.delegate = headers; | ||
} | ||
|
||
@Override | ||
public HeaderType getHeaderType() { | ||
return HeaderType.MESSAGE; | ||
} | ||
|
||
@Override | ||
public String getHeader(String name) { | ||
String value = null; | ||
Iterator<Header> iterator = delegate.headers(name).iterator(); | ||
if (iterator.hasNext()) { | ||
byte[] bytes = iterator.next().value(); | ||
if (bytes != null) { | ||
value = new String(bytes); | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaders(String name) { | ||
Collection<String> headers = new ArrayList<>(); | ||
Iterator<Header> iterator = delegate.headers(name).iterator(); | ||
while (iterator.hasNext()) { | ||
byte[] bytes = iterator.next().value(); | ||
if (bytes != null) { | ||
headers.add(new String(bytes)); | ||
} | ||
} | ||
return headers; | ||
} | ||
|
||
@Override | ||
public void setHeader(String name, String value) { | ||
delegate.remove(name); | ||
delegate.add(name, value.getBytes()); | ||
} | ||
|
||
@Override | ||
public void addHeader(String name, String value) { | ||
delegate.add(name, value.getBytes()); | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaderNames() { | ||
Collection<String> headerNames = new HashSet<>(); | ||
for(Header header : delegate) { | ||
headerNames.add(header.key()); | ||
} | ||
return headerNames; | ||
} | ||
|
||
@Override | ||
public boolean containsHeader(String name) { | ||
for(Header header : delegate) { | ||
if (Objects.equals(name,header.key())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...spans-2.0.0/src/main/java/com/nr/instrumentation/kafka/connect/KafkaConnectConstants.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,13 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.instrumentation.kafka.connect; | ||
|
||
public class KafkaConnectConstants { | ||
public static final String MESSAGE = "Message"; | ||
public static final String KAFKA_CONNECT = "Kafka/Connect"; | ||
} |
17 changes: 17 additions & 0 deletions
17
...s-2.0.0/src/main/java/org/apache/kafka/connect/runtime/AbstractWorkerSourceTask_Skip.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,17 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.runtime; | ||
|
||
import com.newrelic.api.agent.weaver.SkipIfPresent; | ||
|
||
/** | ||
* This class was introduced in Kafka 3 and is a base for 2 WorkerSourceTasks. | ||
*/ | ||
@SkipIfPresent(originalName = "org.apache.kafka.connect.runtime.AbstractWorkerSourceTask") | ||
public abstract class AbstractWorkerSourceTask_Skip { | ||
} |
44 changes: 44 additions & 0 deletions
44
...-2.0.0/src/main/java/org/apache/kafka/connect/runtime/WorkerSinkTask_Instrumentation.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,44 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.runtime; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.TransactionNamePriority; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import org.apache.kafka.clients.consumer.ConsumerRecords; | ||
import org.apache.kafka.connect.util.ConnectorTaskId; | ||
|
||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.MESSAGE; | ||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.KAFKA_CONNECT; | ||
|
||
@Weave(originalName = "org.apache.kafka.connect.runtime.WorkerSinkTask") | ||
abstract class WorkerSinkTask_Instrumentation { | ||
|
||
@Trace(dispatcher = true) | ||
protected void poll(long timeoutMs) { | ||
NewRelic.getAgent().getTransaction() | ||
.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, MESSAGE, KAFKA_CONNECT, id().connector()); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
private void convertMessages(ConsumerRecords<byte[], byte[]> msgs) { | ||
if (msgs.isEmpty()) { | ||
NewRelic.getAgent().getTransaction().ignore(); | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace | ||
private void deliverMessages() { | ||
Weaver.callOriginal(); | ||
} | ||
|
||
public abstract ConnectorTaskId id(); | ||
} |
54 changes: 54 additions & 0 deletions
54
....0.0/src/main/java/org/apache/kafka/connect/runtime/WorkerSourceTask_Instrumentation.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,54 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.runtime; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.TransactionNamePriority; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
import org.apache.kafka.connect.util.ConnectorTaskId; | ||
|
||
import java.util.List; | ||
|
||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.MESSAGE; | ||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.KAFKA_CONNECT; | ||
|
||
@Weave(originalName = "org.apache.kafka.connect.runtime.WorkerSourceTask") | ||
abstract class WorkerSourceTask_Instrumentation { | ||
|
||
@NewField | ||
private Token token; | ||
|
||
@Trace(dispatcher = true) | ||
protected List<SourceRecord> poll() throws InterruptedException { | ||
NewRelic.getAgent().getTransaction() | ||
.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, MESSAGE, KAFKA_CONNECT, id().connector()); | ||
List<SourceRecord> returnValue = Weaver.callOriginal(); | ||
if (returnValue == null || returnValue.isEmpty()) { | ||
NewRelic.getAgent().getTransaction().ignore(); | ||
} else { | ||
token = NewRelic.getAgent().getTransaction().getToken(); | ||
} | ||
return returnValue; | ||
} | ||
|
||
@Trace(async = true) | ||
private boolean sendRecords() { | ||
if (token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public abstract ConnectorTaskId id(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...ect-spans-2.0.0/src/main/java/org/apache/kafka/connect/sink/SinkTask_Instrumentation.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,25 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.sink; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import java.util.Collection; | ||
|
||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.KAFKA_CONNECT; | ||
|
||
@Weave(originalName = "org.apache.kafka.connect.sink.SinkTask", type = MatchType.BaseClass) | ||
public abstract class SinkTask_Instrumentation<K, V> { | ||
|
||
@Trace | ||
public abstract void put(Collection<SinkRecord> records); | ||
} |
25 changes: 25 additions & 0 deletions
25
...spans-2.0.0/src/main/java/org/apache/kafka/connect/source/SourceTask_Instrumentation.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,25 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.source; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import java.util.List; | ||
|
||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.KAFKA_CONNECT; | ||
|
||
@Weave(originalName = "org.apache.kafka.connect.source.SourceTask", type = MatchType.BaseClass) | ||
public abstract class SourceTask_Instrumentation<K, V> { | ||
|
||
@Trace | ||
public abstract List<SourceRecord> poll() throws InterruptedException; | ||
} |
30 changes: 30 additions & 0 deletions
30
...spans-2.0.0/src/main/java/org/apache/kafka/connect/storage/Converter_Instrumentation.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,30 @@ | ||
/* | ||
* | ||
* * Copyright 2023 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.kafka.connect.storage; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaAndValue; | ||
|
||
import java.util.logging.Level; | ||
|
||
import static com.nr.instrumentation.kafka.connect.KafkaConnectConstants.KAFKA_CONNECT; | ||
|
||
@Weave(originalName = "org.apache.kafka.connect.storage.Converter", type = MatchType.Interface) | ||
public abstract class Converter_Instrumentation { | ||
|
||
@Trace(excludeFromTransactionTrace = true) | ||
public abstract byte[] fromConnectData(String topic, Schema schema, Object value); | ||
|
||
@Trace(excludeFromTransactionTrace = true) | ||
public abstract SchemaAndValue toConnectData(String topic, byte[] value); | ||
} |
Oops, something went wrong.