generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,373 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// Build.gradle generated for instrumentation module Kotlin-Coroutines_1.2 | ||
|
||
apply plugin: 'java' | ||
|
||
targetCompatibility = JavaVersion.VERSION_1_9 | ||
|
||
dependencies { | ||
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.7.0' | ||
|
||
// New Relic Java Agent dependencies | ||
implementation 'com.newrelic.agent.java:newrelic-agent:6.0.0' | ||
implementation 'com.newrelic.agent.java:newrelic-api:6.0.0' | ||
implementation fileTree(include: ['*.jar'], dir: '../libs') | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.Kotlin-Coroutines_1.7' | ||
attributes 'Implementation-Vendor': 'New Relic Labs' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.7.0,)' | ||
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:[1.7.0,)' | ||
excludeRegex '.*SNAPSHOT' | ||
excludeRegex '.*alpha' | ||
excludeRegex '.*-eap-.*' | ||
excludeRegex '.*-native-.*' | ||
excludeRegex '.*-M[0-9]' | ||
excludeRegex '.*-rc' | ||
excludeRegex '.*-RC' | ||
excludeRegex '.*-Beta' | ||
} |
43 changes: 43 additions & 0 deletions
43
...utines_1.7/java/com/newrelic/instrumentation/kotlin/coroutines/NRContinuationWrapper.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,43 @@ | ||
package com.newrelic.instrumentation.kotlin.coroutines; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
import kotlin.coroutines.Continuation; | ||
import kotlin.coroutines.CoroutineContext; | ||
|
||
public class NRContinuationWrapper<T> implements Continuation<T> { | ||
|
||
private Continuation<T> delegate = null; | ||
private String name = null; | ||
private static boolean isTransformed = false; | ||
|
||
public NRContinuationWrapper(Continuation<T> d, String n) { | ||
delegate = d; | ||
name = n; | ||
if(!isTransformed) { | ||
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); | ||
isTransformed = true; | ||
} | ||
} | ||
|
||
@Override | ||
public CoroutineContext getContext() { | ||
return delegate.getContext(); | ||
} | ||
|
||
@Override | ||
@Trace(async=true) | ||
public void resumeWith(Object p0) { | ||
|
||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",name != null ? name : Utils.getCoroutineName(getContext(), delegate.getClass())); | ||
Token token = Utils.getToken(getContext()); | ||
if(token != null) { | ||
token.link(); | ||
} | ||
delegate.resumeWith(p0); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...-Coroutines_1.7/java/com/newrelic/instrumentation/kotlin/coroutines/NRCoroutineToken.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,51 @@ | ||
package com.newrelic.instrumentation.kotlin.coroutines; | ||
|
||
import com.newrelic.api.agent.Token; | ||
|
||
import kotlin.coroutines.AbstractCoroutineContextElement; | ||
import kotlin.coroutines.CoroutineContext; | ||
|
||
public class NRCoroutineToken extends AbstractCoroutineContextElement | ||
{ | ||
public static Key key = new Key(); | ||
|
||
public NRCoroutineToken(Token t) { | ||
super(key); | ||
token = t; | ||
} | ||
|
||
private Token token = null; | ||
|
||
public static final class Key implements CoroutineContext.Key<NRCoroutineToken> { | ||
private Key() {} | ||
} | ||
|
||
public Token getToken() { | ||
return token; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return token.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(this != obj ) { | ||
if(obj instanceof NRCoroutineToken) { | ||
NRCoroutineToken t = (NRCoroutineToken)obj; | ||
return t.token == token; | ||
} | ||
} else { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NRCoroutineToken"; | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...oroutines_1.7/java/com/newrelic/instrumentation/kotlin/coroutines/NRFunction1Wrapper.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,34 @@ | ||
package com.newrelic.instrumentation.kotlin.coroutines; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
import kotlin.jvm.functions.Function1; | ||
|
||
public class NRFunction1Wrapper<P1,R> implements Function1<P1, R> { | ||
|
||
private Function1<P1, R> delegate = null; | ||
private String name = null; | ||
private static boolean isTransformed = false; | ||
|
||
public NRFunction1Wrapper(Function1<P1, R> d, String n) { | ||
delegate = d; | ||
name = n; | ||
if(!isTransformed) { | ||
isTransformed = true; | ||
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); | ||
} | ||
} | ||
|
||
@Override | ||
@Trace(dispatcher=true) | ||
public R invoke(P1 p1) { | ||
if(name != null) NewRelic.getAgent().getTracedMethod().setMetricName("Custom","WrappedSuspend",name); | ||
if(delegate != null) { | ||
return delegate.invoke(p1); | ||
} | ||
return null; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...oroutines_1.7/java/com/newrelic/instrumentation/kotlin/coroutines/NRFunction2Wrapper.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,56 @@ | ||
package com.newrelic.instrumentation.kotlin.coroutines; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
import kotlin.coroutines.Continuation; | ||
import kotlin.jvm.functions.Function2; | ||
|
||
public class NRFunction2Wrapper<P1, P2, R> implements Function2<P1, P2, R> { | ||
|
||
private Function2<P1, P2, R> delegate = null; | ||
private String name = null; | ||
private static boolean isTransformed = false; | ||
public Token token = null; | ||
|
||
public NRFunction2Wrapper(Function2<P1, P2, R> d,String n) { | ||
delegate = d; | ||
name = n; | ||
if(!isTransformed) { | ||
isTransformed = true; | ||
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); | ||
} | ||
} | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
@Override | ||
@Trace(async=true) | ||
public R invoke(P1 p1, P2 p2) { | ||
if(token != null) { | ||
token.linkAndExpire(); | ||
token = null; | ||
} | ||
String nameStr = null; | ||
if(p2 instanceof Continuation) { | ||
Continuation continuation = (Continuation)p2; | ||
|
||
if (!Utils.ignoreContinuation(continuation.getClass(), continuation.getContext())) { | ||
NRContinuationWrapper wrapper = new NRContinuationWrapper(continuation, name); | ||
p2 = (P2) wrapper; | ||
} | ||
} | ||
if(nameStr == null) { | ||
nameStr = name; | ||
} | ||
if(nameStr != null) { | ||
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","WrappedSuspend",nameStr); | ||
} | ||
if(delegate != null) { | ||
return delegate.invoke(p1, p2); | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.