Skip to content

Commit

Permalink
Merge pull request #382 from ascrutae/zhangxin/feature/netfilx-fegin-…
Browse files Browse the repository at this point in the history
…plugin

support netflix fegin plugin
  • Loading branch information
wu-sheng committed Aug 31, 2017
2 parents ab677f2 + e685ef9 commit 61b4a08
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 5 deletions.
5 changes: 5 additions & 0 deletions apm-sniffer/apm-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
<artifactId>apm-springmvc-annotation-4.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-spring-cloud-feign-1.x-plugin</artifactId>
<version>${project.version}</version>
</dependency>

<!-- activation -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Object ret) throws Throwable {
Response response = (Response)ret;
int statusCode = response.status();
if (response != null) {
int statusCode = response.status();

AbstractSpan span = ContextManager.activeSpan();
if (statusCode >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, statusCode + "");
AbstractSpan span = ContextManager.activeSpan();
if (statusCode >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, statusCode + "");
}
}

ContextManager.stopSpan();
Expand Down
1 change: 1 addition & 0 deletions apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<module>concurrent-util-4.x-plugin</module>
<module>resttemplate-4.x-plugin</module>
<module>mvc-annotation-4.x-plugin</module>
<module>spring-cloud</module>
</modules>
<packaging>pom</packaging>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.skywalking</groupId>
<artifactId>spring-cloud</artifactId>
<version>3.2-2017</version>
</parent>

<artifactId>netflix-plugins</artifactId>
<modules>
<module>spring-cloud-feign-1.x-plugin</module>
</modules>
<packaging>pom</packaging>

<name>netflix-plugins</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.skywalking</groupId>
<artifactId>netflix-plugins</artifactId>
<version>3.2-2017</version>
</parent>

<artifactId>apm-spring-cloud-feign-1.x-plugin</artifactId>
<packaging>jar</packaging>

<!-- only support spring cloud feign 1.1.x, 1.2.x, 1.3.x -->
<name>spring-cloud-feign-1.x-plugin</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.1.0.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-feign-default-http-9.x-plugin</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;

import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;

/**
* {@link NetflixFeignInstrumentation} presents that skywalking intercepts {@link org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient#execute(feign.Request,
* feign.Request.Options)} by using {@link org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor}.
*
* @author zhangxin
*/
public class NetflixFeignInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
/**
* Enhance class.
*/
private static final String ENHANCE_CLASS = "org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient";

/**
* Intercept class.
*/
private static final String INTERCEPT_CLASS = "org.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor";

@Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}

@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}

@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("execute");
}

@Override public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}

@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring-cloud-feign-1.x=org.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define.NetflixFeignInstrumentation
25 changes: 25 additions & 0 deletions apm-sniffer/apm-sdk-plugin/spring-plugins/spring-cloud/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.skywalking</groupId>
<artifactId>spring-plugins</artifactId>
<version>3.2-2017</version>
</parent>

<artifactId>spring-cloud</artifactId>
<modules>
<module>netflix-plugins</module>
</modules>
<packaging>pom</packaging>

<name>spring-cloud</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>

0 comments on commit 61b4a08

Please sign in to comment.