Skip to content

Commit 6357e23

Browse files
authored
Merge pull request #2 from newrelic-experimental/minimize
Minimize
2 parents 566597e + e810d4a commit 6357e23

File tree

83 files changed

+274
-2061
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+274
-2061
lines changed

Kotlin-Coroutines_1.1/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jar {
2222
}
2323

2424
verifyInstrumentation {
25-
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.1.0,1.1.1]'
25+
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.1.0,1.2.0]'
2626
excludeRegex '.*SNAPSHOT'
2727
excludeRegex '.*alpha'
2828
excludeRegex '.*eap.*'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.newrelic.api.agent.Token;
55
import com.newrelic.api.agent.Trace;
66

7-
public class NRWrappedRunnable implements Runnable {
7+
public class NRRunnable implements Runnable {
88

99

1010
private static boolean isTranformed = false;
@@ -16,7 +16,7 @@ public void expireAndNullToken() {
1616
token = null;
1717
}
1818

19-
public NRWrappedRunnable(Runnable d, Token t) {
19+
public NRRunnable(Runnable d, Token t) {
2020
token = t;
2121
delegate = d;
2222
if(!isTranformed) {

Kotlin-Coroutines_1.1/src/main/java/kotlinx/coroutines/CoroutineDispatcher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.newrelic.api.agent.weaver.MatchType;
66
import com.newrelic.api.agent.weaver.Weave;
77
import com.newrelic.api.agent.weaver.Weaver;
8-
import com.nr.instrumentation.kotlin.coroutines.NRWrappedRunnable;
8+
import com.nr.instrumentation.kotlin.coroutines.NRRunnable;
99

1010
import kotlin.coroutines.CoroutineContext;;
1111

@@ -14,8 +14,8 @@ public abstract class CoroutineDispatcher {
1414

1515
@Trace(excludeFromTransactionTrace=true)
1616
public void dispatch(CoroutineContext ctx, Runnable r) {
17-
if(!NRWrappedRunnable.class.isInstance(r)) {
18-
NRWrappedRunnable wrapper = new NRWrappedRunnable(r, NewRelic.getAgent().getTransaction().getToken());
17+
if(!NRRunnable.class.isInstance(r)) {
18+
NRRunnable wrapper = new NRRunnable(r, NewRelic.getAgent().getTransaction().getToken());
1919
r = wrapper;
2020
}
2121
Weaver.callOriginal();

Kotlin-Coroutines_1.1/src/main/java/kotlinx/coroutines/EventLoopImplBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import com.newrelic.api.agent.weaver.MatchType;
66
import com.newrelic.api.agent.weaver.Weave;
77
import com.newrelic.api.agent.weaver.Weaver;
8-
import com.nr.instrumentation.kotlin.coroutines.NRWrappedRunnable;
8+
import com.nr.instrumentation.kotlin.coroutines.NRRunnable;
99

1010
@Weave(type=MatchType.BaseClass)
1111
public abstract class EventLoopImplBase {
1212

1313
@SuppressWarnings("unused")
1414
private boolean enqueueImpl(Runnable r) {
1515
Token token = NewRelic.getAgent().getTransaction().getToken();
16-
NRWrappedRunnable wrapper = new NRWrappedRunnable(r, token);
16+
NRRunnable wrapper = new NRRunnable(r, token);
1717
r = wrapper;
1818
boolean b = Weaver.callOriginal();
1919
if(!b) {
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package kotlinx.coroutines;
22

3-
import java.util.concurrent.ScheduledFuture;
4-
import java.util.concurrent.TimeUnit;
5-
6-
import com.newrelic.api.agent.Trace;
3+
import com.newrelic.api.agent.NewRelic;
4+
import com.newrelic.api.agent.Token;
75
import com.newrelic.api.agent.weaver.MatchType;
86
import com.newrelic.api.agent.weaver.Weave;
97
import com.newrelic.api.agent.weaver.Weaver;
8+
import com.nr.instrumentation.kotlin.coroutines.NRRunnable;
109

11-
import kotlin.Unit;
10+
import kotlin.coroutines.CoroutineContext;
1211

1312
@Weave(type=MatchType.BaseClass)
1413
public abstract class ExecutorCoroutineDispatcherBase {
1514

16-
@Trace(dispatcher=true)
17-
public abstract void scheduleResumeAfterDelay(long timeInMS, CancellableContinuation<? super Unit> f);
18-
@Trace(dispatcher=true)
19-
public abstract DisposableHandle invokeOnTimeout(long ms, Runnable r);
20-
@Trace(dispatcher=true)
21-
private ScheduledFuture<?> scheduleBlock(Runnable r, long ms, TimeUnit tu) {
22-
return Weaver.callOriginal();
23-
}
15+
16+
public void dispatch(CoroutineContext context, Runnable block) {
17+
if(!(block instanceof NRRunnable)) {
18+
Token t = NewRelic.getAgent().getTransaction().getToken();
19+
if(t != null && t.isActive()) {
20+
NRRunnable wrapper = new NRRunnable(block, t);
21+
block = wrapper;
22+
} else if(t != null) {
23+
t.expire();
24+
}
25+
}
26+
Weaver.callOriginal();
27+
}
2428
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package kotlinx.coroutines.scheduling;
2+
3+
import com.newrelic.api.agent.NewRelic;
4+
import com.newrelic.api.agent.Token;
5+
import com.newrelic.api.agent.weaver.Weave;
6+
import com.newrelic.api.agent.weaver.Weaver;
7+
import com.nr.instrumentation.kotlin.coroutines.NRRunnable;
8+
9+
import kotlin.coroutines.CoroutineContext;
10+
11+
@Weave
12+
public abstract class ExperimentalCoroutineDispatcher {
13+
14+
public void dispatch(CoroutineContext context, Runnable block) {
15+
if(!(block instanceof NRRunnable)) {
16+
Token t = NewRelic.getAgent().getTransaction().getToken();
17+
if(t != null && t.isActive()) {
18+
NRRunnable wrapper = new NRRunnable(block, t);
19+
block = wrapper;
20+
} else if(t != null) {
21+
t.expire();
22+
}
23+
}
24+
Weaver.callOriginal();
25+
}
26+
27+
}

Kotlin-Coroutines_1.2/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ jar {
2222
}
2323

2424
verifyInstrumentation {
25-
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.2.0,1.3.0)'
25+
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.2.0,)'
2626
excludeRegex '.*SNAPSHOT'
2727
excludeRegex '.*alpha'
2828
excludeRegex '.*-eap-.*'
29+
excludeRegex '.*-native-.*'
2930
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.nr.instrumentation.kotlin.coroutines;
1+
package com.newrelic.instrumentation.kotlin.coroutines;
22
import com.newrelic.agent.bridge.AgentBridge;
33
import com.newrelic.api.agent.NewRelic;
44
import com.newrelic.api.agent.Token;
55
import com.newrelic.api.agent.Trace;
66

7-
public class NRWrappedRunnable implements Runnable {
7+
public class NRRunnable implements Runnable {
88

99

1010
private static boolean isTranformed = false;
@@ -16,7 +16,7 @@ public void expireAndNullToken() {
1616
token = null;
1717
}
1818

19-
public NRWrappedRunnable(Runnable d, Token t) {
19+
public NRRunnable(Runnable d, Token t) {
2020
token = t;
2121
delegate = d;
2222
if(!isTranformed) {

Kotlin-Coroutines_1.2/src/main/java/com/nr/instrumentation/kotlin/coroutines/NRWrappedRunnable.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

Kotlin-Coroutines_1.2/src/main/java/kotlin/coroutines/jvm/internal/BaseContinuationImpl.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
@Weave(type=MatchType.BaseClass)
1010
public abstract class BaseContinuationImpl {
11-
12-
11+
12+
1313
@Trace
1414
public void resumeWith(Object obj) {
1515
String name = null;
@@ -23,5 +23,17 @@ public void resumeWith(Object obj) {
2323
Weaver.callOriginal();
2424
}
2525

26+
@Trace
27+
protected Object invokeSuspend(Object obj) {
28+
String name = null;
29+
StackTraceElement element = getStackTraceElement();
30+
if (element != null)
31+
name = element.getClassName() + "." + element.getMethodName();
32+
if (name != null)
33+
NewRelic.getAgent().getTracedMethod().setMetricName(new String[] { "Custom", "Continuation", name, "invokeSuspend" });
34+
return Weaver.callOriginal();
35+
}
36+
37+
2638
public abstract StackTraceElement getStackTraceElement();
2739
}

0 commit comments

Comments
 (0)