Skip to content

Commit 7be3bee

Browse files
committed
1. Solved some comment problems.
2. Found there is a bug in setting span status in 2.3.0+, so added a new module of xxl-job-2.3.0 to solve it.
1 parent 53119af commit 7be3bee

File tree

36 files changed

+628
-106
lines changed

36 files changed

+628
-106
lines changed

docs/supported-libraries.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ These are the supported libraries and frameworks:
145145
| [Vert.x SQL Client](https://github.com/eclipse-vertx/vertx-sql-client/) | 4.0+ | N/A | [Database Client Spans] |
146146
| [Vert.x Web](https://vertx.io/docs/vertx-web/java/) | 3.0+ | N/A | Provides `http.route` [2] |
147147
| [Vibur DBCP](https://www.vibur.org/) | 11.0+ | [opentelemetry-vibur-dbcp-11.0](../instrumentation/vibur-dbcp-11.0/library) | [Database Pool Metrics] |
148-
| [XXL-JOB](https://www.xuxueli.com/xxl-job/en/) | 1.9.2+ | N/A | none |
148+
| [XXL-JOB](https://www.xuxueli.com/xxl-job/en/) | 1.9.2+ | N/A | none |
149149
| [ZIO](https://zio.dev/) | 2.0+ | N/A | Context propagation |
150150

151151
**[1]** Standalone library instrumentation refers to instrumentation that can be used without the Java agent.

instrumentation/xxl-job/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Settings for the XXL-JOB instrumentation
2+
3+
| System property | Type | Default | Description |
4+
|-------------------------------------------------------------|---------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| `otel.instrumentation.xxl-job.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental span attributes. |

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/build.gradle.kts

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ muzzle {
77
group.set("com.xuxueli")
88
module.set("xxl-job-core")
99
versions.set("[1.9.2, 2.1.2)")
10-
// except these versions, they are too old and the capabilities provided are not comprehensive.
11-
skip("1.7.0", "1.7.1", "1.7.2", "1.8.0", "1.8.1", "1.8.2", "1.9.0", "1.9.1")
1210
assertInverse.set(true)
1311
}
1412
}
1513

1614
dependencies {
17-
compileOnly("com.xuxueli:xxl-job-core:1.9.2")
18-
implementation(project(":instrumentation:xxl-job:xxl-job-common:javaagent"))
19-
20-
testLibrary("com.xuxueli:xxl-job-core:1.9.2") {
15+
library("com.xuxueli:xxl-job-core:1.9.2") {
2116
exclude("org.codehaus.groovy", "groovy")
2217
}
18+
implementation(project(":instrumentation:xxl-job:xxl-job-common:javaagent"))
19+
20+
// It needs the javax.annotation-api in xxl-job-core 1.9.2.
2321
testImplementation("javax.annotation:javax.annotation-api:1.3.2")
2422
testImplementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
2523
latestDepTestLibrary("com.xuxueli:xxl-job-core:2.1.1") {

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/GlueJobHandlerInstrumentation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3434
public void transform(TypeTransformer transformer) {
3535
transformer.applyAdviceToMethod(
3636
named("execute").and(isPublic()).and(takesArguments(1).and(takesArgument(0, String.class))),
37-
ScheduleAdvice.class.getName());
37+
GlueJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
3838
}
3939

4040
@SuppressWarnings("unused")

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/ScriptJobHandlerInstrumentation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3333
public void transform(TypeTransformer transformer) {
3434
transformer.applyAdviceToMethod(
3535
named("execute").and(isPublic()).and(takesArguments(1).and(takesArgument(0, String.class))),
36-
ScheduleAdvice.class.getName());
36+
ScriptJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
3737
}
3838

3939
@SuppressWarnings("unused")

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/SimpleJobHandlerInstrumentation.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
import com.xxl.job.core.glue.GlueTypeEnum;
2121
import com.xxl.job.core.handler.IJobHandler;
22-
import com.xxl.job.core.handler.impl.GlueJobHandler;
2322
import io.opentelemetry.context.Context;
2423
import io.opentelemetry.context.Scope;
25-
import io.opentelemetry.instrumentation.api.util.VirtualField;
2624
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2725
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2826
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
@@ -43,7 +41,7 @@ public ElementMatcher<TypeDescription> typeMatcher() {
4341
public void transform(TypeTransformer transformer) {
4442
transformer.applyAdviceToMethod(
4543
named("execute").and(isPublic()).and(takesArguments(1).and(takesArgument(0, String.class))),
46-
ScheduleAdvice.class.getName());
44+
ScriptJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
4745
}
4846

4947
public static class ScheduleAdvice {
@@ -56,8 +54,6 @@ public static void onSchedule(
5654
@Advice.Local("otelContext") Context context,
5755
@Advice.Local("otelScope") Scope scope) {
5856
Context parentContext = currentContext();
59-
VirtualField<GlueJobHandler, IJobHandler> handlerMap =
60-
VirtualField.find(GlueJobHandler.class, IJobHandler.class);
6157
request = new XxlJobProcessRequest();
6258
request.setDeclaringClass(handler.getClass());
6359
request.setGlueTypeEnum(GlueTypeEnum.BEAN);

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/XxlJobHelper.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
77

8+
import static io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2.XxlJobSingletons.instrumenter;
9+
810
import com.xxl.job.core.biz.model.ReturnT;
911
import io.opentelemetry.context.Context;
1012
import io.opentelemetry.context.Scope;
@@ -15,10 +17,10 @@ public class XxlJobHelper {
1517
private XxlJobHelper() {}
1618

1719
public static Context startSpan(Context parentContext, XxlJobProcessRequest request) {
18-
if (!XxlJobSingletons.xxlJobProcessInstrumenter().shouldStart(parentContext, request)) {
20+
if (!instrumenter().shouldStart(parentContext, request)) {
1921
return null;
2022
}
21-
return XxlJobSingletons.xxlJobProcessInstrumenter().start(parentContext, request);
23+
return instrumenter().start(parentContext, request);
2224
}
2325

2426
public static void stopSpan(
@@ -27,18 +29,19 @@ public static void stopSpan(
2729
Throwable throwable,
2830
Scope scope,
2931
Context context) {
32+
if (scope == null) {
33+
return;
34+
}
3035
if (result != null && (result instanceof ReturnT)) {
3136
ReturnT<?> res = (ReturnT<?>) result;
3237
if (res.getCode() == ReturnT.FAIL_CODE) {
33-
request.setResultStatus(Boolean.FALSE.toString());
38+
request.setSchedulingSuccess(Boolean.FALSE);
3439
}
3540
}
3641
if (throwable != null) {
37-
request.setResultStatus(Boolean.FALSE.toString());
38-
}
39-
if (scope != null) {
40-
scope.close();
41-
XxlJobSingletons.xxlJobProcessInstrumenter().end(context, request, null, throwable);
42+
request.setSchedulingSuccess(Boolean.FALSE);
4243
}
44+
scope.close();
45+
instrumenter().end(context, request, null, throwable);
4346
}
4447
}

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/XxlJobInstrumentationModule.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public XxlJobInstrumentationModule() {
2424

2525
@Override
2626
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
27+
// Class was added in 2.1.2
2728
return not(hasClassesNamed("com.xxl.job.core.handler.impl.MethodJobHandler"));
2829
}
2930

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/XxlJobSingletons.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
77

8+
import com.xxl.job.core.glue.GlueTypeEnum;
89
import io.opentelemetry.api.GlobalOpenTelemetry;
910
import io.opentelemetry.api.common.AttributeKey;
11+
import io.opentelemetry.api.trace.StatusCode;
1012
import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor;
1113
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1214
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
@@ -24,25 +26,39 @@ public final class XxlJobSingletons {
2426
InstrumentationConfig.get()
2527
.getBoolean("otel.instrumentation.xxl-job.experimental-span-attributes", false);
2628

27-
private static final Instrumenter<XxlJobProcessRequest, Void> XXL_JOB_PROCESS_INSTRUMENTER;
29+
private static final Instrumenter<XxlJobProcessRequest, Void> INSTRUMENTER;
2830

2931
static {
3032
XxlJobSpanNameExtractor spanNameExtractor = new XxlJobSpanNameExtractor();
3133
InstrumenterBuilder<XxlJobProcessRequest, Void> builder =
3234
Instrumenter.<XxlJobProcessRequest, Void>builder(
3335
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
3436
.addAttributesExtractor(
35-
CodeAttributesExtractor.create(new XxlJobCodeAttributesGetter()));
37+
CodeAttributesExtractor.create(new XxlJobCodeAttributesGetter()))
38+
.setSpanStatusExtractor(
39+
(spanStatusBuilder, xxlJobProcessRequest, response, error) -> {
40+
if (error != null
41+
|| Boolean.FALSE.equals(xxlJobProcessRequest.getSchedulingSuccess())) {
42+
spanStatusBuilder.setStatus(StatusCode.ERROR);
43+
}
44+
});
3645
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
3746
builder.addAttributesExtractor(
3847
AttributesExtractor.constant(AttributeKey.stringKey("job.system"), "xxl-job"));
3948
builder.addAttributesExtractor(new XxlJobExperimentalAttributeExtractor());
4049
}
41-
XXL_JOB_PROCESS_INSTRUMENTER = builder.buildInstrumenter();
50+
INSTRUMENTER = builder.buildInstrumenter();
4251
}
4352

44-
public static Instrumenter<XxlJobProcessRequest, Void> xxlJobProcessInstrumenter() {
45-
return XXL_JOB_PROCESS_INSTRUMENTER;
53+
public static Instrumenter<XxlJobProcessRequest, Void> instrumenter() {
54+
return INSTRUMENTER;
55+
}
56+
57+
@SuppressWarnings({"Unused", "ReturnValueIgnored"})
58+
private static void limitSupportedVersions() {
59+
// GLUE_POWERSHELL was added in 1.9.2. Using this constant here ensures that muzzle will disable
60+
// this instrumentation on earlier versions where this constant does not exist.
61+
GlueTypeEnum.GLUE_POWERSHELL.name();
4662
}
4763

4864
private XxlJobSingletons() {}

instrumentation/xxl-job/xxl-job-1.9.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/xxljob/v1_9_2/XxlJobTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.xxl.job.core.handler.impl.GlueJobHandler;
1616
import com.xxl.job.core.handler.impl.ScriptJobHandler;
1717
import io.opentelemetry.instrumentation.xxljob.AbstractXxlJobTest;
18+
import io.opentelemetry.instrumentation.xxljob.CustomizedFailedHandler;
19+
import io.opentelemetry.instrumentation.xxljob.SimpleCustomizedHandler;
1820

1921
class XxlJobTest extends AbstractXxlJobTest {
2022

@@ -37,7 +39,7 @@ class XxlJobTest extends AbstractXxlJobTest {
3739

3840
@Override
3941
protected String getPackageName() {
40-
return "io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2";
42+
return "io.opentelemetry.instrumentation.xxljob";
4143
}
4244

4345
@Override
@@ -55,13 +57,18 @@ protected IJobHandler getCustomizeHandler() {
5557
return new SimpleCustomizedHandler();
5658
}
5759

60+
@Override
61+
protected IJobHandler getCustomizeFailedHandler() {
62+
return new CustomizedFailedHandler();
63+
}
64+
5865
@Override
5966
protected IJobHandler getMethodHandler() {
6067
return null;
6168
}
6269

6370
@Override
6471
public void testMethodJob() {
65-
// version 1.9.2 does not support method job
72+
// The version [1.9.2~2.1.2) of the module does not support method job.
6673
}
6774
}

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/build.gradle.kts

+4-30
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,23 @@ muzzle {
66
pass {
77
group.set("com.xuxueli")
88
module.set("xxl-job-core")
9-
versions.set("[2.1.2,)")
9+
versions.set("[2.1.2,2.3.0)")
1010
assertInverse.set(true)
1111
}
1212
}
1313

1414
dependencies {
15-
compileOnly("com.xuxueli:xxl-job-core:2.1.2")
16-
implementation(project(":instrumentation:xxl-job:xxl-job-common:javaagent"))
17-
18-
testLibrary("com.xuxueli:xxl-job-core:2.1.2") {
15+
library("com.xuxueli:xxl-job-core:2.1.2") {
1916
exclude("org.codehaus.groovy", "groovy")
2017
}
18+
implementation(project(":instrumentation:xxl-job:xxl-job-common:javaagent"))
19+
2120
testImplementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
2221
latestDepTestLibrary("com.xuxueli:xxl-job-core:2.2.+") {
2322
exclude("org.codehaus.groovy", "groovy")
2423
}
2524
}
2625

27-
testing {
28-
suites {
29-
val version23Test by registering(JvmTestSuite::class) {
30-
dependencies {
31-
implementation(project(":instrumentation:xxl-job:xxl-job-common:testing"))
32-
if (findProperty("testLatestDeps") as Boolean) {
33-
implementation("com.xuxueli:xxl-job-core:+") {
34-
exclude("org.codehaus.groovy", "groovy")
35-
}
36-
} else {
37-
implementation("com.xuxueli:xxl-job-core:2.3.0") {
38-
exclude("org.codehaus.groovy", "groovy")
39-
}
40-
}
41-
}
42-
}
43-
}
44-
}
45-
46-
tasks {
47-
check {
48-
dependsOn(testing.suites)
49-
}
50-
}
51-
5226
tasks.withType<Test>().configureEach {
5327
// required on jdk17
5428
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_1_2/GlueJobHandlerInstrumentation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3131
@Override
3232
public void transform(TypeTransformer transformer) {
3333
transformer.applyAdviceToMethod(
34-
named("execute").and(isPublic()), ScheduleAdvice.class.getName());
34+
named("execute").and(isPublic()),
35+
GlueJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
3536
}
3637

3738
@SuppressWarnings("unused")

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_1_2/MethodJobHandlerInstrumentation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3232
@Override
3333
public void transform(TypeTransformer transformer) {
3434
transformer.applyAdviceToMethod(
35-
named("execute").and(isPublic()), ScheduleAdvice.class.getName());
35+
named("execute").and(isPublic()),
36+
MethodJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
3637
}
3738

3839
@SuppressWarnings("unused")

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_1_2/ScriptJobHandlerInstrumentation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
3030
@Override
3131
public void transform(TypeTransformer transformer) {
3232
transformer.applyAdviceToMethod(
33-
named("execute").and(isPublic()), ScheduleAdvice.class.getName());
33+
named("execute").and(isPublic()),
34+
ScriptJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
3435
}
3536

3637
@SuppressWarnings("unused")

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_1_2/SimpleJobHandlerInstrumentation.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
import com.xxl.job.core.glue.GlueTypeEnum;
1919
import com.xxl.job.core.handler.IJobHandler;
20-
import com.xxl.job.core.handler.impl.GlueJobHandler;
2120
import io.opentelemetry.context.Context;
2221
import io.opentelemetry.context.Scope;
23-
import io.opentelemetry.instrumentation.api.util.VirtualField;
2422
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2523
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2624
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
@@ -40,7 +38,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
4038
@Override
4139
public void transform(TypeTransformer transformer) {
4240
transformer.applyAdviceToMethod(
43-
named("execute").and(isPublic()), ScheduleAdvice.class.getName());
41+
named("execute").and(isPublic()),
42+
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
4443
}
4544

4645
public static class ScheduleAdvice {
@@ -53,8 +52,6 @@ public static void onSchedule(
5352
@Advice.Local("otelContext") Context context,
5453
@Advice.Local("otelScope") Scope scope) {
5554
Context parentContext = currentContext();
56-
VirtualField<GlueJobHandler, IJobHandler> handlerMap =
57-
VirtualField.find(GlueJobHandler.class, IJobHandler.class);
5855
request = new XxlJobProcessRequest();
5956
request.setDeclaringClass(handler.getClass());
6057
request.setGlueTypeEnum(GlueTypeEnum.BEAN);

instrumentation/xxl-job/xxl-job-2.1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/xxljob/v2_1_2/XxlJobHelper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class XxlJobHelper {
1515
private XxlJobHelper() {}
1616

1717
public static Context startSpan(Context parentContext, XxlJobProcessRequest request) {
18-
if (!XxlJobSingletons.xxlJobProcessInstrumenter().shouldStart(parentContext, request)) {
18+
if (!instrumenter().shouldStart(parentContext, request)) {
1919
return null;
2020
}
21-
return XxlJobSingletons.xxlJobProcessInstrumenter().start(parentContext, request);
21+
return instrumenter().start(parentContext, request);
2222
}
2323

2424
public static void stopSpan(
@@ -27,18 +27,19 @@ public static void stopSpan(
2727
Throwable throwable,
2828
Scope scope,
2929
Context context) {
30+
if (scope == null) {
31+
return;
32+
}
3033
if (result != null && (result instanceof ReturnT)) {
3134
ReturnT<?> res = (ReturnT<?>) result;
3235
if (res.getCode() == ReturnT.FAIL_CODE) {
33-
request.setResultStatus(Boolean.FALSE.toString());
36+
request.setSchedulingSuccess(Boolean.FALSE);
3437
}
3538
}
3639
if (throwable != null) {
37-
request.setResultStatus(Boolean.FALSE.toString());
38-
}
39-
if (scope != null) {
40-
scope.close();
41-
XxlJobSingletons.xxlJobProcessInstrumenter().end(context, request, null, throwable);
40+
request.setSchedulingSuccess(Boolean.FALSE);
4241
}
42+
scope.close();
43+
instrumenter().end(context, request, null, throwable);
4344
}
4445
}

0 commit comments

Comments
 (0)