|
| 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.lettuce.v65.define; |
| 20 | + |
| 21 | +import java.util.Collections; |
| 22 | +import java.util.List; |
| 23 | +import net.bytebuddy.description.method.MethodDescription; |
| 24 | +import net.bytebuddy.matcher.ElementMatcher; |
| 25 | +import net.bytebuddy.matcher.ElementMatchers; |
| 26 | +import org.apache.skywalking.apm.agent.core.plugin.WitnessMethod; |
| 27 | +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; |
| 28 | +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; |
| 29 | +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; |
| 30 | +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; |
| 31 | + |
| 32 | +import static net.bytebuddy.matcher.ElementMatchers.named; |
| 33 | +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; |
| 34 | +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; |
| 35 | + |
| 36 | +public class RedisChannelWriterInstrumentationV65 extends ClassInstanceMethodsEnhancePluginDefine { |
| 37 | + |
| 38 | + private static final String ENHANCE_CLASS = "io.lettuce.core.RedisChannelWriter"; |
| 39 | + |
| 40 | + private static final String REDIS_CHANNEL_WRITER_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.lettuce.v65.RedisChannelWriterInterceptorV65"; |
| 41 | + |
| 42 | + @Override |
| 43 | + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { |
| 44 | + return new ConstructorInterceptPoint[0]; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { |
| 49 | + return new InstanceMethodsInterceptPoint[] { |
| 50 | + new InstanceMethodsInterceptPoint() { |
| 51 | + @Override |
| 52 | + public ElementMatcher<MethodDescription> getMethodsMatcher() { |
| 53 | + return named("write").and(takesArgument(0, named("io.lettuce.core.protocol.RedisCommand")).or( |
| 54 | + takesArgument(0, List.class))); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String getMethodsInterceptor() { |
| 59 | + return REDIS_CHANNEL_WRITER_INTERCEPTOR_CLASS; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean isOverrideArgs() { |
| 64 | + return false; |
| 65 | + } |
| 66 | + }, |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public ClassMatch enhanceClass() { |
| 72 | + return byHierarchyMatch(ENHANCE_CLASS); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + protected List<WitnessMethod> witnessMethods() { |
| 77 | + return Collections.singletonList(new WitnessMethod( |
| 78 | + "io.lettuce.core.protocol.ProtocolKeyword", |
| 79 | + ElementMatchers.named("toString") |
| 80 | + )); |
| 81 | + } |
| 82 | +} |
0 commit comments