Skip to content

Commit f10262f

Browse files
weaver instrumentation skeleton
1 parent baedf8d commit f10262f

File tree

7 files changed

+431
-0
lines changed

7 files changed

+431
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply from: "$rootDir/gradle/java.gradle"
2+
apply plugin: 'scala'
3+
4+
muzzle {
5+
pass {
6+
group = 'com.disneystreaming'
7+
module = 'weaver-cats_3'
8+
versions = '[0.8.4,)'
9+
}
10+
}
11+
12+
addTestSuiteForDir('latestDepTest', 'test')
13+
14+
dependencies {
15+
compileOnly group: 'com.disneystreaming', name: 'weaver-cats_3', version: '0.8.4'
16+
17+
testImplementation testFixtures(project(':dd-java-agent:agent-ci-visibility'))
18+
19+
testImplementation group: 'org.scala-lang', name: 'scala-library', version: '2.12.15'
20+
testImplementation group: 'com.disneystreaming', name: 'weaver-cats_3', version: '0.8.4'
21+
22+
testImplementation group: 'com.disneystreaming', name: 'weaver-cats_3', version: '+'
23+
}
24+
25+
compileTestGroovy {
26+
dependsOn compileTestScala
27+
classpath += files(sourceSets.test.scala.destinationDirectory)
28+
}
29+
30+
compileLatestDepTestGroovy {
31+
dependsOn compileLatestDepTestScala
32+
classpath += files(sourceSets.latestDepTest.scala.destinationDirectory)
33+
}

dd-java-agent/instrumentation/weaver/gradle.lockfile

Lines changed: 249 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package datadog.trace.instrumentation.weaver;
2+
3+
import weaver.framework.SuiteEvent;
4+
import weaver.framework.SuiteFinished;
5+
import weaver.framework.SuiteStarted;
6+
import weaver.framework.TestFinished;
7+
8+
public class DatadogWeaverReporter {
9+
10+
public static void handle(SuiteEvent event) {
11+
if (event instanceof SuiteStarted) {
12+
System.out.println("!!! Suite started");
13+
} else if (event instanceof SuiteFinished) {
14+
System.out.println("!!! Suite Finished");
15+
} else if (event instanceof TestFinished) {
16+
System.out.println("!!! Test finished");
17+
}
18+
}
19+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package datadog.trace.instrumentation.weaver;
2+
3+
import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.implementsInterface;
4+
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
5+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
6+
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
7+
8+
import com.google.auto.service.AutoService;
9+
import datadog.trace.agent.tooling.Instrumenter;
10+
import datadog.trace.agent.tooling.InstrumenterModule;
11+
import java.util.Set;
12+
import net.bytebuddy.asm.Advice;
13+
import net.bytebuddy.description.type.TypeDescription;
14+
import net.bytebuddy.matcher.ElementMatcher;
15+
import weaver.framework.SuiteEvent;
16+
17+
@AutoService(InstrumenterModule.class)
18+
public class WeaverInstrumentation extends InstrumenterModule.CiVisibility
19+
implements Instrumenter.ForTypeHierarchy {
20+
21+
public WeaverInstrumentation() {
22+
super("ci-visibility", "weaver");
23+
}
24+
25+
@Override
26+
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
27+
return super.isApplicable(enabledSystems);
28+
}
29+
30+
@Override
31+
public String hierarchyMarkerType() {
32+
return null;
33+
}
34+
35+
@Override
36+
public ElementMatcher<TypeDescription> hierarchyMatcher() {
37+
return implementsInterface(named("weaver.framework.RunnerCompat.SuiteEventBroker"));
38+
}
39+
40+
@Override
41+
public String[] helperClassNames() {
42+
return new String[] {
43+
packageName + ".DatadogWeaverReporter",
44+
};
45+
}
46+
47+
@Override
48+
public void methodAdvice(MethodTransformer transformer) {
49+
transformer.applyAdvice(
50+
named("send")
51+
.and(takesArguments(1))
52+
.and(takesArgument(0, named("weaver.framework.SuiteEvent"))),
53+
WeaverInstrumentation.class.getName() + "$SendEventAdvice");
54+
}
55+
56+
public static class SendEventAdvice {
57+
@Advice.OnMethodEnter(suppress = Throwable.class)
58+
public static void onSendEvent(@Advice.Argument(value = 0) SuiteEvent event) {
59+
DatadogWeaverReporter.handle(event);
60+
}
61+
}
62+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import datadog.trace.api.DisableTestTrace
2+
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
3+
import cats.effect.IO
4+
import weaver.Runner
5+
6+
@DisableTestTrace(reason = "avoid self-tracing")
7+
class WeaverTest extends CiVisibilityInstrumentationTest {
8+
9+
def "default test"() {
10+
expect:
11+
2 + 2 == 4
12+
}
13+
14+
//def "simple weaver test"() {
15+
// given: "test runner instantiated"
16+
// List<String> args = []
17+
// int maxConcurrentSuites = 1
18+
// def printLine = { String line -> IO(println(line)) }
19+
// def runner = new Runner[IO](args, maxConcurrentSuites)(printLine)
20+
21+
// when: "we run the IO effect"
22+
// runner.printLine("Runner is running inside a Spock test!")
23+
24+
// then: "no exceptions are thrown"
25+
26+
//}
27+
28+
@Override
29+
String instrumentedLibraryName() {
30+
return "weaver"
31+
}
32+
33+
@Override
34+
String instrumentedLibraryVersion() {
35+
return "0.8.4"
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.example
2+
3+
import weaver.SimpleIOSuite
4+
import cats.effect._
5+
6+
// Suites must be "objects" for them to be picked by the framework
7+
object TestSucceed extends SimpleIOSuite {
8+
9+
pureTest("non-effectful (pure) test"){
10+
expect("hello".length == 6)
11+
}
12+
13+
private val random = IO(java.util.UUID.randomUUID())
14+
15+
test("test with side-effects") {
16+
for {
17+
x <- random
18+
y <- random
19+
} yield expect(x != y)
20+
}
21+
22+
loggedTest("test with side-effects and a logger"){ log =>
23+
for {
24+
x <- random
25+
_ <- log.info(s"x : $x")
26+
y <- random
27+
_ <- log.info(s"y : $y")
28+
} yield expect(x != y)
29+
}
30+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ include ':dd-java-agent:instrumentation:redisson'
503503
include ':dd-java-agent:instrumentation:redisson:redisson-2.0.0'
504504
include ':dd-java-agent:instrumentation:redisson:redisson-2.3.0'
505505
include ':dd-java-agent:instrumentation:redisson:redisson-3.10.3'
506+
include ':dd-java-agent:instrumentation:weaver'
506507
include ':dd-java-agent:instrumentation:websphere-jmx'
507508
include ':dd-java-agent:instrumentation:zio'
508509
include ':dd-java-agent:instrumentation:zio:zio-2.0'

0 commit comments

Comments
 (0)