generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from newrelic-experimental/sling-jobs
Sling Event and Scripting
- Loading branch information
Showing
8 changed files
with
225 additions
and
0 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 |
---|---|---|
|
@@ -2,3 +2,8 @@ | |
.git | ||
.github | ||
/.metadata/ | ||
.settings | ||
.classpath | ||
.project | ||
build | ||
bin |
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,27 @@ | ||
|
||
// Build.gradle generated for instrumentation module apache-sling-jobs | ||
|
||
apply plugin: 'java' | ||
|
||
dependencies { | ||
implementation 'org.apache.sling:org.apache.sling.event:4.2.0' | ||
|
||
// New Relic Java Agent dependencies | ||
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' | ||
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' | ||
implementation fileTree(include: ['*.jar'], dir: '../libs') | ||
implementation fileTree(include: ['*.jar'], dir: '../test-lib') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.apache-sling-event' | ||
attributes 'Implementation-Vendor': 'New Relic Labs' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'org.apache.sling:org.apache.sling.event:[4.0.0,)' | ||
} |
24 changes: 24 additions & 0 deletions
24
apache-sling-event/src/main/java/org/apache/sling/event/impl/jobs/queues/JobQueueImpl.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,24 @@ | ||
package org.apache.sling.event.impl.jobs.queues; | ||
|
||
import org.apache.sling.event.impl.jobs.JobHandler; | ||
import org.apache.sling.event.impl.jobs.JobImpl; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.TracedMethod; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave | ||
public abstract class JobQueueImpl { | ||
|
||
@Trace(dispatcher = true) | ||
private void startJob(final JobHandler handler) { | ||
JobImpl job = handler.getJob(); | ||
TracedMethod traced = NewRelic.getAgent().getTracedMethod(); | ||
|
||
traced.addCustomAttribute("QueueName",job.getQueueName()); | ||
traced.addCustomAttribute("Topic", job.getTopic()); | ||
Weaver.callOriginal(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...event/src/main/java/org/apache/sling/event/jobs/consumer/JobConsumer_instrumentation.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,70 @@ | ||
package org.apache.sling.event.jobs.consumer; | ||
|
||
import org.apache.sling.event.jobs.Job; | ||
import org.apache.sling.event.jobs.consumer.JobConsumer.JobResult; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.WeaveAllConstructors; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave(type = MatchType.Interface, originalName = "org.apache.sling.event.jobs.consumer.JobConsumer") | ||
public abstract class JobConsumer_instrumentation { | ||
|
||
@Trace(dispatcher = true) | ||
public JobResult process(Job job) { | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
@Weave(type = MatchType.Interface, originalName = "org.apache.sling.event.jobs.consumer.JobConsumer$AsyncHandler") | ||
public static class AsyncHandler { | ||
|
||
@NewField | ||
private Token token = null; | ||
|
||
@WeaveAllConstructors | ||
public AsyncHandler() { | ||
if(token == null) { | ||
Token t = NewRelic.getAgent().getTransaction().getToken(); | ||
if(t != null && t.isActive()) { | ||
token = t; | ||
} else if(t != null) { | ||
t.expire(); | ||
t = null; | ||
} | ||
} | ||
} | ||
|
||
@Trace(async = true) | ||
public void failed() { | ||
if(token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(async = true) | ||
public void ok() { | ||
if(token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace(async = true) | ||
public void cancel() { | ||
if(token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
Weaver.callOriginal(); | ||
} | ||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
apache-sling-event/src/main/java/org/apache/sling/event/jobs/consumer/JobExecutor.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,35 @@ | ||
package org.apache.sling.event.jobs.consumer; | ||
|
||
import org.apache.sling.event.jobs.Job; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.TracedMethod; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave(type = MatchType.Interface) | ||
public abstract class JobExecutor { | ||
|
||
@Trace | ||
public JobExecutionResult process(Job job, JobExecutionContext context) { | ||
TracedMethod traced = NewRelic.getAgent().getTracedMethod(); | ||
traced.setMetricName("Custom","Sling","JobExecutor",getClass().getSimpleName(),"process"); | ||
traced.addCustomAttribute("QueueName", job.getQueueName()); | ||
traced.addCustomAttribute("Topic", job.getTopic()); | ||
JobExecutionResult jobResult = Weaver.callOriginal(); | ||
if(jobResult != null) { | ||
String jobResultStr = null; | ||
if(jobResult.cancelled()) { | ||
jobResultStr = "Cancelled"; | ||
} else if(jobResult.failed()) { | ||
jobResultStr = "Failed"; | ||
} else if(jobResult.succeeded()) { | ||
jobResultStr = "Succeeded"; | ||
} | ||
traced.addCustomAttribute("JobResult", jobResultStr); | ||
} | ||
return jobResult; | ||
} | ||
} |
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,32 @@ | ||
|
||
// Build.gradle generated for instrumentation module apache-sling-scripting | ||
|
||
apply plugin: 'java' | ||
|
||
dependencies { | ||
implementation 'org.apache.sling:org.apache.sling.scripting.core:2.2.0' | ||
implementation 'javax.servlet:javax.servlet-api:3.1.0' | ||
// https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.api | ||
compileOnly 'org.apache.sling:org.apache.sling.api:2.22.0' | ||
|
||
// New Relic Java Agent dependencies | ||
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' | ||
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' | ||
implementation fileTree(include: ['*.jar'], dir: '../libs') | ||
implementation fileTree(include: ['*.jar'], dir: '../test-lib') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.apache-sling-scripting' | ||
attributes 'Implementation-Vendor': 'New Relic Labs' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes('org.apache.sling:org.apache.sling.scripting.core:[2.2.0,)') { | ||
compile 'org.apache.sling:org.apache.sling.api:2.22.0' | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ling-scripting/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.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,30 @@ | ||
package org.apache.sling.scripting.core.impl; | ||
|
||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import org.apache.sling.api.scripting.SlingBindings; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave | ||
abstract class DefaultSlingScript { | ||
|
||
public abstract String getServletName(); | ||
|
||
@Trace | ||
public void service(ServletRequest req, ServletResponse res) { | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Sling","DefaultSlingScript","service",getServletName()); | ||
|
||
Weaver.callOriginal(); | ||
} | ||
|
||
@Trace | ||
public Object call(SlingBindings props, String method, Object... args) { | ||
NewRelic.getAgent().getTracedMethod().addCustomAttribute("Method", method); | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Sling","DefaultSlingScript","call"); | ||
return Weaver.callOriginal(); | ||
} | ||
} |
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