Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 5c09a21

Browse files
committed
moved tracing of suspend functions to its own extension
1 parent fe3fcb7 commit 5c09a21

File tree

116 files changed

+267
-3697
lines changed

Some content is hidden

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

116 files changed

+267
-3697
lines changed

Kotlin-Coroutines-Core.tar

79.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11

2-
// Build.gradle generated for instrumentation module Kotlin-Coroutines_1.2
2+
// Build.gradle generated for instrumentation module Kotlin-Coroutines-Core
33

44
apply plugin: 'java'
55

6-
targetCompatibility = JavaVersion.VERSION_1_9
7-
86
dependencies {
9-
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.8.0'
7+
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.4.0'
108

119
// New Relic Java Agent dependencies
1210
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.1'
1311
implementation 'com.newrelic.agent.java:newrelic-api:6.4.1'
1412
implementation fileTree(include: ['*.jar'], dir: '../libs')
13+
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
1514
}
1615

1716
jar {
1817
manifest {
19-
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.Kotlin-Coroutines_1.8'
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.Kotlin-Coroutines-Suspends'
2019
attributes 'Implementation-Vendor': 'New Relic Labs'
2120
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
2221
attributes 'Implementation-Version': 2.0
23-
attributes 'Agent-Class': 'com.newrelic.instrumentation.kotlin.coroutines_18.tracing.CoroutinesPreMain'
22+
attributes 'Agent-Class': 'com.newrelic.instrumentation.kotlin.coroutines.tracing.CoroutinesPreMain'
2423
}
2524
}
2625

2726
verifyInstrumentation {
28-
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.8.0,)'
29-
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:[1.8.0,)'
30-
excludeRegex '.*SNAPSHOT'
31-
excludeRegex '.*alpha'
32-
excludeRegex '.*-eap-.*'
33-
excludeRegex '.*-native-.*'
34-
excludeRegex '.*-M[0-9]'
35-
excludeRegex '.*-rc'
36-
excludeRegex '.*-RC'
37-
excludeRegex '.*-RC[0-9]'
38-
excludeRegex '.*-Beta'
39-
}
27+
// Verifier plugin documentation:
28+
// https://github.com/newrelic/newrelic-gradle-verify-instrumentation
29+
// Example:
30+
// passes 'javax.servlet:servlet-api:[2.2,2.5]'
31+
// exclude 'javax.servlet:servlet-api:2.4.public_draft'
32+
}

Kotlin-Coroutines_1.8/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_18/SuspendIgnores.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/SuspendIgnores.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_18;
1+
package com.newrelic.instrumentation.kotlin.coroutines;
22

33
import java.util.ArrayList;
44
import java.util.List;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.newrelic.instrumentation.kotlin.coroutines;
2+
3+
import com.newrelic.agent.config.AgentConfig;
4+
import com.newrelic.agent.config.AgentConfigListener;
5+
import com.newrelic.agent.service.ServiceFactory;
6+
import com.newrelic.api.agent.Config;
7+
import com.newrelic.api.agent.NewRelic;
8+
9+
public class Utils implements AgentConfigListener {
10+
11+
private static final String SUSPENDSIGNORECONFIG = "Coroutines.ignores.suspends";
12+
13+
private static final Utils INSTANCE = new Utils();
14+
15+
16+
static {
17+
ServiceFactory.getConfigService().addIAgentConfigListener(INSTANCE);
18+
Config config = NewRelic.getAgent().getConfig();
19+
loadConfig(config);
20+
21+
}
22+
23+
private static void loadConfig(Config config) {
24+
String ignores = config.getValue(SUSPENDSIGNORECONFIG);
25+
if (ignores != null && !ignores.isEmpty()) {
26+
SuspendIgnores.reset(config);
27+
}
28+
}
29+
30+
public static String sub = "createCoroutineFromSuspendFunction";
31+
32+
@Override
33+
public void configChanged(String appName, AgentConfig agentConfig) {
34+
loadConfig(agentConfig);
35+
36+
}
37+
38+
}

Kotlin-Coroutines_1.4/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_14/tracing/CoroutinesPreMain.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/CoroutinesPreMain.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_14.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import java.lang.instrument.Instrumentation;
44
import java.util.HashSet;
@@ -38,7 +38,6 @@ public static boolean setup() {
3838

3939
if(tracerService != null && classTransformerService != null && coreService != null) {
4040
tracerService.registerTracerFactory(SuspendTracerFactory.TRACER_FACTORY_NAME, new SuspendTracerFactory());
41-
tracerService.registerTracerFactory(DispatchedTaskTracerFactory.TRACER_FACTORY_NAME, new DispatchedTaskTracerFactory());
4241
InstrumentationContextManager contextMgr = classTransformerService.getContextManager();
4342

4443
if(contextMgr != null) {
@@ -48,16 +47,9 @@ public static boolean setup() {
4847

4948
Set<ClassMatchVisitorFactory> factories = new HashSet<>();
5049
factories.add(suspendMatchVistor);
51-
52-
53-
DispatchedClassTransformer dispatchedTransformer = new DispatchedClassTransformer(contextMgr);
54-
DispatchedTaskClassAndMethod dispatchedMatcher = new DispatchedTaskClassAndMethod();
55-
ClassMatchVisitorFactory dispatchedMatchVistor = dispatchedTransformer.addMatcher(dispatchedMatcher);
56-
5750
Class<?>[] allLoadedClasses = coreService.getInstrumentation().getAllLoadedClasses();
5851

5952
classTransformerService.retransformMatchingClassesImmediately(allLoadedClasses, factories);
60-
factories.add(dispatchedMatchVistor);
6153

6254
return true;
6355
}

Kotlin-Coroutines_1.7/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_17/tracing/SuspendClassAndMethod.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/SuspendClassAndMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_17.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import com.newrelic.agent.instrumentation.classmatchers.ClassAndMethodMatcher;
44
import com.newrelic.agent.instrumentation.classmatchers.ClassMatcher;

Kotlin-Coroutines_1.7/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_17/tracing/SuspendClassMatcher.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/SuspendClassMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_17.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import java.util.ArrayList;
44
import java.util.Collection;

Kotlin-Coroutines_1.7/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_17/tracing/SuspendClassTransformer.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/SuspendClassTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_17.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import java.lang.instrument.IllegalClassFormatException;
44
import java.security.ProtectionDomain;

Kotlin-Coroutines_1.7/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_17/tracing/SuspendMethodMatcher.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/SuspendMethodMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_17.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import java.util.Set;
44

Kotlin-Coroutines_1.4/src/main/java/com/newrelic/instrumentation/kotlin/coroutines_14/tracing/SuspendTracerFactory.java renamed to Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/tracing/SuspendTracerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.newrelic.instrumentation.kotlin.coroutines_14.tracing;
1+
package com.newrelic.instrumentation.kotlin.coroutines.tracing;
22

33
import com.newrelic.agent.Transaction;
44
import com.newrelic.agent.tracers.ClassMethodSignature;
@@ -7,7 +7,7 @@
77
import com.newrelic.agent.tracers.TracerFactory;
88
import com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat;
99
import com.newrelic.api.agent.NewRelic;
10-
import com.newrelic.instrumentation.kotlin.coroutines_14.SuspendIgnores;
10+
import com.newrelic.instrumentation.kotlin.coroutines.SuspendIgnores;
1111

1212
public class SuspendTracerFactory implements TracerFactory {
1313

0 commit comments

Comments
 (0)