Skip to content

Commit b1cc271

Browse files
feat: support weaver 0.12 release (#10903)
feat: support weaver 0.12 release Co-authored-by: daniel.mohedano <daniel.mohedano@datadoghq.com>
1 parent 95dcacd commit b1cc271

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cafe.cryptography:ed25519-elisabeth:0.1.0=buildTimeInstrumentationPlugin,latestD
66
ch.qos.logback:logback-classic:1.2.13=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
77
ch.qos.logback:logback-core:1.2.13=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
88
co.fs2:fs2-core_3:3.10.2=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
9-
co.fs2:fs2-core_3:3.12.2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
9+
co.fs2:fs2-core_3:3.13.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
1010
com.blogspot.mydailyjava:weak-lock-free:0.17=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
1111
com.datadoghq.okhttp3:okhttp:3.12.15=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
1212
com.datadoghq.okio:okio:1.17.6=buildTimeInstrumentationPlugin,compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
@@ -26,7 +26,6 @@ com.eed3si9n:sjson-new-scalajson_2.13:0.10.1=zinc
2626
com.fasterxml.jackson.core:jackson-annotations:2.20=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
2727
com.fasterxml.jackson.core:jackson-core:2.20.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
2828
com.fasterxml.jackson.core:jackson-databind:2.20.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
29-
com.fasterxml.jackson:jackson-bom:2.20.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
3029
com.github.javaparser:javaparser-core:3.25.6=codenarc
3130
com.github.jnr:jffi:1.3.14=buildTimeInstrumentationPlugin,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath,weaver084TestRuntimeClasspath
3231
com.github.jnr:jnr-a64asm:1.0.0=buildTimeInstrumentationPlugin,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath,weaver084TestRuntimeClasspath
@@ -181,7 +180,8 @@ org.scala-sbt:zinc-core_2.13:1.10.4=zinc
181180
org.scala-sbt:zinc-persist-core-assembly:1.10.4=zinc
182181
org.scala-sbt:zinc-persist_2.13:1.10.4=zinc
183182
org.scala-sbt:zinc_2.13:1.10.4=zinc
184-
org.scodec:scodec-bits_3:1.1.38=compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
183+
org.scodec:scodec-bits_3:1.1.38=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
184+
org.scodec:scodec-bits_3:1.2.4=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
185185
org.skyscreamer:jsonassert:1.5.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
186186
org.slf4j:jcl-over-slf4j:1.7.30=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
187187
org.slf4j:jul-to-slf4j:1.7.30=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
@@ -194,25 +194,27 @@ org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j
194194
org.snakeyaml:snakeyaml-engine:2.9=buildTimeInstrumentationPlugin,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath,weaver084TestRuntimeClasspath
195195
org.spockframework:spock-bom:2.4-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
196196
org.spockframework:spock-core:2.4-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
197+
org.tabletest:tabletest-junit:1.2.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
198+
org.tabletest:tabletest-parser:1.2.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
197199
org.typelevel:cats-core_3:2.10.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
198-
org.typelevel:cats-core_3:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
200+
org.typelevel:cats-core_3:2.13.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
199201
org.typelevel:cats-effect-kernel_3:3.5.4=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
200-
org.typelevel:cats-effect-kernel_3:3.6.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
202+
org.typelevel:cats-effect-kernel_3:3.7.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
201203
org.typelevel:cats-effect-std_3:3.5.4=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
202-
org.typelevel:cats-effect-std_3:3.6.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
204+
org.typelevel:cats-effect-std_3:3.7.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
203205
org.typelevel:cats-effect_3:3.5.4=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
204-
org.typelevel:cats-effect_3:3.6.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
206+
org.typelevel:cats-effect_3:3.7.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
205207
org.typelevel:cats-kernel_3:2.10.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
206-
org.typelevel:cats-kernel_3:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
207-
org.typelevel:cats-mtl_3:1.3.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
208+
org.typelevel:cats-kernel_3:2.13.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
209+
org.typelevel:cats-mtl_3:1.6.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
208210
org.typelevel:scalac-compat-annotation_3:0.1.4=compileClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
209-
org.typelevel:weaver-cats-core_3:0.11.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
211+
org.typelevel:weaver-cats-core_3:0.12.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
210212
org.typelevel:weaver-cats-core_3:0.9.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
211-
org.typelevel:weaver-cats_3:0.11.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
213+
org.typelevel:weaver-cats_3:0.12.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
212214
org.typelevel:weaver-cats_3:0.9.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
213-
org.typelevel:weaver-core_3:0.11.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
215+
org.typelevel:weaver-core_3:0.12.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
214216
org.typelevel:weaver-core_3:0.9.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
215-
org.typelevel:weaver-framework_3:0.11.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
217+
org.typelevel:weaver-framework_3:0.12.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
216218
org.typelevel:weaver-framework_3:0.9.0=compileClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath
217219
org.xmlresolver:xmlresolver:5.3.3=spotbugs
218220
org.xmlunit:xmlunit-core:2.10.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath,weaver084TestCompileClasspath,weaver084TestRuntimeClasspath

dd-java-agent/instrumentation/weaver-0.9/src/latestDepTest/resources/test-failed-pure/events.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"env" : "none",
4747
"error.message" : ${content_meta_error_message},
4848
"error.stack" : ${content_meta_error_stack},
49-
"error.type" : "weaver.ExpectationFailed",
49+
"error.type" : "java.lang.RuntimeException",
5050
"language" : "jvm",
5151
"library_version" : ${content_meta_library_version},
5252
"runtime-id" : ${content_meta_runtime_id},

dd-java-agent/instrumentation/weaver-0.9/src/latestDepTest/resources/test-failed/events.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"env" : "none",
4747
"error.message" : ${content_meta_error_message},
4848
"error.stack" : ${content_meta_error_stack},
49-
"error.type" : "weaver.ExpectationFailed",
49+
"error.type" : "java.lang.RuntimeException",
5050
"language" : "jvm",
5151
"library_version" : ${content_meta_library_version},
5252
"runtime-id" : ${content_meta_runtime_id},

dd-java-agent/instrumentation/weaver-0.9/src/main/java/datadog/trace/instrumentation/weaver/DatadogWeaverReporter.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,17 @@ public static void onTestFinished(TestFinished event, TaskDef taskDef) {
120120
if (testOutcome.result() != null) {
121121
// Failed outcomes
122122
if (WeaverUtils.isResultFailure(testOutcome.result())) {
123-
Throwable throwable =
124-
WeaverUtils.unwrap(
125-
WeaverUtils.METHOD_HANDLES.invoke(
126-
WeaverUtils.GET_FAILURE_SOURCE_HANDLE, testOutcome.result()),
127-
Throwable.class);
123+
Object source =
124+
WeaverUtils.METHOD_HANDLES.invoke(
125+
WeaverUtils.GET_FAILURE_SOURCE_HANDLE, testOutcome.result());
126+
Throwable throwable = WeaverUtils.toThrowable(source);
128127
TEST_EVENTS_HANDLER.onTestFailure(testDescriptor, throwable);
129128
} else if (testOutcome.result() instanceof Result.Failures) {
130129
Result.Failures result = (Result.Failures) testOutcome.result();
131130
Object headFailure = result.failures().head();
132-
Throwable throwable =
133-
WeaverUtils.unwrap(
134-
WeaverUtils.METHOD_HANDLES.invoke(
135-
WeaverUtils.GET_FAILURE_SOURCE_HANDLE, headFailure),
136-
Throwable.class);
131+
Object source =
132+
WeaverUtils.METHOD_HANDLES.invoke(WeaverUtils.GET_FAILURE_SOURCE_HANDLE, headFailure);
133+
Throwable throwable = WeaverUtils.toThrowable(source);
137134
TEST_EVENTS_HANDLER.onTestFailure(testDescriptor, throwable);
138135
} else if (testOutcome.result() instanceof Result.Exception) {
139136
Result.Exception result = (Result.Exception) testOutcome.result();

dd-java-agent/instrumentation/weaver-0.9/src/main/java/datadog/trace/instrumentation/weaver/WeaverUtils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public abstract class WeaverUtils {
3636
private static final String RESULT_FAILURES_FAILURE_CLASS_NAME = "weaver.Result$Failures$Failure";
3737
// - Failure.source changed from Optional<Throwable> to Throwable
3838
public static final MethodHandle GET_FAILURE_SOURCE_HANDLE = createFailureSourceHandle();
39+
// - In v0.12.0, ExpectationFailed is no longer a Throwable
40+
private static final String EXPECTATION_FAILED_CLASS_NAME = "weaver.ExpectationFailed";
41+
private static final MethodHandle GET_EXPECTATION_FAILED_MESSAGE_HANDLE =
42+
METHOD_HANDLES.method(getClass(EXPECTATION_FAILED_CLASS_NAME), "message");
3943

4044
public static final List<LibraryCapability> CAPABILITIES = Collections.emptyList();
4145

@@ -103,4 +107,31 @@ public static <T> T unwrap(Object value, Class<T> type) {
103107
return type.cast(value);
104108
}
105109
}
110+
111+
/**
112+
* Converts a failure source to a Throwable. In weaver v0.9–v0.11, the source is a Throwable (or
113+
* Option&lt;Throwable&gt;). In v0.12.0+, ExpectationFailed is no longer a Throwable, so we
114+
* extract its message and wrap it in a RuntimeException.
115+
*/
116+
@Nullable
117+
public static Throwable toThrowable(@Nullable Object source) {
118+
if (source == null) {
119+
return null;
120+
}
121+
if (source instanceof Option) {
122+
source = ((Option<?>) source).getOrElse(null);
123+
if (source == null) {
124+
return null;
125+
}
126+
}
127+
if (source instanceof Throwable) {
128+
return (Throwable) source;
129+
}
130+
// v0.12.0+: ExpectationFailed is no longer a Throwable
131+
if (GET_EXPECTATION_FAILED_MESSAGE_HANDLE != null) {
132+
String message = METHOD_HANDLES.invoke(GET_EXPECTATION_FAILED_MESSAGE_HANDLE, source);
133+
return new RuntimeException(message);
134+
}
135+
return new RuntimeException(source.toString());
136+
}
106137
}

0 commit comments

Comments
 (0)