-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Framework Integration #1
Changes from all commits
4bbc49b
3129859
1c0e4f7
52a55cc
9d29090
cc58326
96ba6af
b7a04c4
3549c7b
1a68dbf
3256748
ceb7267
011947a
be2c0f0
3317bb2
440fec1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ | |
.project | ||
.classpath | ||
.DS_Store | ||
|
||
*.iml | ||
/.idea |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I'm missing something but it doesn't look like this dependency on |
||
<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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add the Javadoc plugin to align this with other submodule poms? <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version> Additionally, it may be useful to consider adding another |
||
</plugins> | ||
</build> | ||
</project> |
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); | ||
} | ||
} | ||
|
||
} |
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 { | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 thanks for fixing these across the board!! 😁