Skip to content

Commit 7c305fe

Browse files
ascrutaewu-sheng
authored andcommitted
Add witness class for kafka plugin (apache#1300)
1 parent 307bd4c commit 7c305fe

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.plugin.kafka.v1.define;
20+
21+
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
22+
23+
public abstract class AbstractKafkaInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
24+
25+
@Override protected String[] witnessClasses() {
26+
return new String[]{"org.apache.kafka.clients.ApiVersions"};
27+
}
28+
}

apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/CallbackInstrumentation.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import net.bytebuddy.matcher.ElementMatcher;
2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2424
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2625
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2726

2827
import static net.bytebuddy.matcher.ElementMatchers.named;
2928
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
3029

31-
public class CallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
30+
public class CallbackInstrumentation extends AbstractKafkaInstrumentation {
3231

3332
public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.Callback";
3433
public static final String ENHANCE_METHOD = "onCompletion";

apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaConsumerInstrumentation.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import net.bytebuddy.matcher.ElementMatcher;
2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2424
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2625
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2726

2827
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -41,7 +40,7 @@
4140
*
4241
* @author zhang xin
4342
*/
44-
public class KafkaConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
43+
public class KafkaConsumerInstrumentation extends AbstractKafkaInstrumentation {
4544

4645
public static final String CONSTRUCTOR_INTERCEPT_TYPE = "org.apache.kafka.clients.consumer.ConsumerConfig";
4746
public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v1.ConsumerConstructorInterceptor";

apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaProducerInstrumentation.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import net.bytebuddy.matcher.ElementMatcher;
2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2424
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2625
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2726

2827
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -42,7 +41,7 @@
4241
*
4342
* @author zhang xin
4443
*/
45-
public class KafkaProducerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
44+
public class KafkaProducerInstrumentation extends AbstractKafkaInstrumentation {
4645

4746
public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v1.KafkaProducerInterceptor";
4847
public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.KafkaProducer";

apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/ProducerRecordInstrumentation.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import net.bytebuddy.matcher.ElementMatcher;
2323
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2424
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
25-
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
2625
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2726

2827
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
2928
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3029

31-
public class ProducerRecordInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
30+
public class ProducerRecordInstrumentation extends AbstractKafkaInstrumentation {
3231

3332
public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v1.ProducerRecordConstructorInterceptor";
3433
public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.ProducerRecord";

0 commit comments

Comments
 (0)