-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Spring modules for X-Ray. * Adding POM description * Fixing issues highlighted from PR #1 * Removing GPG maven plugin override * Reformatting code * Homologizing logging declarations * abstracting spring version to property and removing SLF4J dependency * referencing parent version for module version * removing redundant groupId from POM * adding newline at EOF * Incorporating feedback from PR #1 * Adding newline at EOF * updating POMs * Adding module into main pom * Removing beginSegment() per comments on PR #1
- Loading branch information
1 parent
c821d01
commit 01d52ae
Showing
18 changed files
with
334 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ | |
.project | ||
.classpath | ||
.DS_Store | ||
|
||
*.iml | ||
/.idea |
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
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,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-xray-recorder-sdk-pom</artifactId> | ||
<version>1.2.2</version> | ||
</parent> | ||
|
||
<artifactId>aws-xray-recorder-sdk-spring</artifactId> | ||
<version>${awsxrayrecordersdk.version}</version> | ||
<name>AWS X-Ray Recorder SDK for Java - Spring Framework Interceptors</name> | ||
|
||
<properties> | ||
<spring.version>4.3.12.RELEASE</spring.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-aspects</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-xray-recorder-sdk-core</artifactId> | ||
<version>${awsxrayrecordersdk.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
<version>1.8.11</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
<version>2.0.0.RELEASE</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.10.4</version> | ||
<configuration> | ||
<javadocDirectory>${basedir}/docs</javadocDirectory> | ||
<docfilessubdirs>true</docfilessubdirs> | ||
<overview>${basedir}/docs/overview.html</overview> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerVersion>1.8</compilerVersion> | ||
<fork>true</fork> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
94 changes: 94 additions & 0 deletions
94
...order-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/AbstractXRayInterceptor.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,94 @@ | ||
package com.amazonaws.xray.spring.aop; | ||
|
||
import com.amazonaws.xray.AWSXRay; | ||
import com.amazonaws.xray.entities.Segment; | ||
import com.amazonaws.xray.entities.Subsegment; | ||
import com.amazonaws.xray.exceptions.SegmentNotFoundException; | ||
import com.amazonaws.xray.strategy.ContextMissingStrategy; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.amazonaws.xray.AWSXRay.getCurrentSegmentOptional; | ||
|
||
public abstract class AbstractXRayInterceptor { | ||
|
||
private static final Log logger = LogFactory.getLog(AbstractXRayInterceptor.class); | ||
|
||
private static ContextMissingStrategy getContextMissingStrategy() { | ||
return AWSXRay.getGlobalRecorder().getContextMissingStrategy(); | ||
} | ||
|
||
private static Segment getCurrentSegment() { | ||
Optional<Segment> segment = getCurrentSegmentOptional(); | ||
if (segment.isPresent()) { | ||
return segment.get(); | ||
} | ||
ContextMissingStrategy contextMissingStrategy = getContextMissingStrategy(); | ||
contextMissingStrategy.contextMissing("No segment in progress.", SegmentNotFoundException.class); | ||
return null; | ||
} | ||
|
||
/** | ||
* @param pjp the proceeding join point | ||
* @return the result of the method being wrapped | ||
* @throws Throwable | ||
*/ | ||
@Around("xrayTracedClasses() || xrayEnabledClasses()") | ||
public Object traceAroundMethods(ProceedingJoinPoint pjp) throws Throwable { | ||
return this.processXRayTrace(pjp); | ||
} | ||
|
||
protected Object processXRayTrace(ProceedingJoinPoint pjp) throws Throwable { | ||
try { | ||
Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName()); | ||
subsegment.setMetadata(XRayInterceptorUtils.generateMetadata(pjp, subsegment)); | ||
return XRayInterceptorUtils.conditionalProceed(pjp); | ||
} catch (Exception e) { | ||
AWSXRay.getCurrentSegment().addException(e); | ||
throw e; | ||
} finally { | ||
logger.trace("Ending Subsegment"); | ||
AWSXRay.endSubsegment(); | ||
} | ||
} | ||
|
||
protected abstract void xrayEnabledClasses(); | ||
|
||
@Pointcut("execution(* XRayTraced+.*(..))") | ||
protected void xrayTracedClasses() { | ||
} | ||
|
||
@Pointcut("execution(public !void org.springframework.data.repository.Repository+.*(..))") | ||
protected void springRepositories() { | ||
} | ||
|
||
/** | ||
* @param pjp the proceeding join point | ||
* @return the result of the method being wrapped | ||
* @throws Throwable | ||
*/ | ||
@Around("springRepositories()") | ||
public Object traceAroundRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable { | ||
logger.trace("Advising repository"); | ||
boolean hasClassAnnotation = false; | ||
|
||
for (Class<?> i : pjp.getTarget().getClass().getInterfaces()) { | ||
if (i.getAnnotation(XRayEnabled.class) != null) { | ||
hasClassAnnotation = true; | ||
break; | ||
} | ||
} | ||
|
||
if (hasClassAnnotation) { | ||
return this.processXRayTrace(pjp); | ||
} else { | ||
return XRayInterceptorUtils.conditionalProceed(pjp); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
aws-xray-recorder-sdk-spring/src/main/java/com/amazonaws/xray/spring/aop/XRayEnabled.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,10 @@ | ||
package com.amazonaws.xray.spring.aop; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface XRayEnabled { | ||
|
||
|
||
} |
Oops, something went wrong.