make xxl-job indy-ready (#14571)
This commit is contained in:
parent
b3df63556e
commit
14a536051a
|
|
@ -5,18 +5,17 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -39,29 +38,20 @@ public class GlueJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("jobHandler") IJobHandler handler,
|
@Advice.FieldValue("jobHandler") IJobHandler handler) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createGlueJobRequest(handler));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createGlueJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
helper().endSpan(scope, result, throwable);
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
@ -13,11 +12,11 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.glue.GlueTypeEnum;
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -40,30 +39,20 @@ public class ScriptJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
||||||
@Advice.FieldValue("jobId") int jobId,
|
@Advice.FieldValue("jobId") int jobId) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createScriptJobRequest(glueType, jobId));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createScriptJobRequest(glueType, jobId);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v1_9_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
||||||
|
|
@ -19,11 +18,11 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -44,33 +43,21 @@ public class SimpleJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(@Advice.This IJobHandler handler) {
|
||||||
@Advice.This IJobHandler handler,
|
return helper().startSpan(XxlJobProcessRequest.createSimpleJobRequest(handler));
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createSimpleJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
|
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
@AutoService(InstrumentationModule.class)
|
@AutoService(InstrumentationModule.class)
|
||||||
public class XxlJobInstrumentationModule extends InstrumentationModule {
|
public class XxlJobInstrumentationModule extends InstrumentationModule
|
||||||
|
implements ExperimentalInstrumentationModule {
|
||||||
|
|
||||||
public XxlJobInstrumentationModule() {
|
public XxlJobInstrumentationModule() {
|
||||||
super("xxl-job", "xxl-job-1.9.2");
|
super("xxl-job", "xxl-job-1.9.2");
|
||||||
|
|
@ -35,4 +37,9 @@ public class XxlJobInstrumentationModule extends InstrumentationModule {
|
||||||
new SimpleJobHandlerInstrumentation(),
|
new SimpleJobHandlerInstrumentation(),
|
||||||
new GlueJobHandlerInstrumentation());
|
new GlueJobHandlerInstrumentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,16 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -37,29 +36,19 @@ public class GlueJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("jobHandler") IJobHandler handler,
|
@Advice.FieldValue("jobHandler") IJobHandler handler) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createGlueJobRequest(handler));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createGlueJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,16 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -38,29 +37,17 @@ public class MethodJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("target") Object target,
|
@Advice.FieldValue("target") Object target, @Advice.FieldValue("method") Method method) {
|
||||||
@Advice.FieldValue("method") Method method,
|
return helper().startSpan(XxlJobProcessRequest.createMethodJobRequest(target, method));
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createMethodJobRequest(target, method);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,16 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
import com.xxl.job.core.glue.GlueTypeEnum;
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -37,30 +36,21 @@ public class ScriptJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
||||||
@Advice.FieldValue("jobId") int jobId,
|
@Advice.FieldValue("jobId") int jobId) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createScriptJobRequest(glueType, jobId));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createScriptJobRequest(glueType, jobId);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_1_2;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
||||||
|
|
@ -17,11 +16,11 @@ import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
|
|
@ -42,33 +41,20 @@ public class SimpleJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(@Advice.This IJobHandler handler) {
|
||||||
@Advice.This IJobHandler handler,
|
return helper().startSpan(XxlJobProcessRequest.createSimpleJobRequest(handler));
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createSimpleJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelContext") Context context,
|
helper().endSpan(scope, result, throwable);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
helper().stopSpan(result, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
|
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
@AutoService(InstrumentationModule.class)
|
@AutoService(InstrumentationModule.class)
|
||||||
public class XxlJobInstrumentationModule extends InstrumentationModule {
|
public class XxlJobInstrumentationModule extends InstrumentationModule
|
||||||
|
implements ExperimentalInstrumentationModule {
|
||||||
|
|
||||||
public XxlJobInstrumentationModule() {
|
public XxlJobInstrumentationModule() {
|
||||||
super("xxl-job", "xxl-job-2.1.2");
|
super("xxl-job", "xxl-job-2.1.2");
|
||||||
|
|
@ -37,4 +39,9 @@ public class XxlJobInstrumentationModule extends InstrumentationModule {
|
||||||
new SimpleJobHandlerInstrumentation(),
|
new SimpleJobHandlerInstrumentation(),
|
||||||
new GlueJobHandlerInstrumentation());
|
new GlueJobHandlerInstrumentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
public class GlueJobHandlerInstrumentation implements TypeInstrumentation {
|
public class GlueJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
@ -38,28 +38,19 @@ public class GlueJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("jobHandler") IJobHandler handler,
|
@Advice.FieldValue("jobHandler") IJobHandler handler) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createGlueJobRequest(handler));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createGlueJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelContext") Context context,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
helper().endSpan(scope, result, throwable);
|
||||||
helper().stopSpan(request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
||||||
|
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
public class MethodJobHandlerInstrumentation implements TypeInstrumentation {
|
public class MethodJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
@ -38,28 +38,17 @@ public class MethodJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("target") Object target,
|
@Advice.FieldValue("target") Object target, @Advice.FieldValue("method") Method method) {
|
||||||
@Advice.FieldValue("method") Method method,
|
return helper().startSpan(XxlJobProcessRequest.createMethodJobRequest(target, method));
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createMethodJobRequest(target, method);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelContext") Context context,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
helper().endSpan(scope, result, throwable);
|
||||||
helper().stopSpan(request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0.XxlJobSingletons.helper;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.glue.GlueTypeEnum;
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
public class ScriptJobHandlerInstrumentation implements TypeInstrumentation {
|
public class ScriptJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
@ -39,28 +39,18 @@ public class ScriptJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(
|
||||||
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
@Advice.FieldValue("glueType") GlueTypeEnum glueType,
|
||||||
@Advice.FieldValue("jobId") int jobId,
|
@Advice.FieldValue("jobId") int jobId) {
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
return helper().startSpan(XxlJobProcessRequest.createScriptJobRequest(glueType, jobId));
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createScriptJobRequest(glueType, jobId);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) Object result,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelContext") Context context,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
helper().endSpan(scope, result, throwable);
|
||||||
helper().stopSpan(request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
package io.opentelemetry.javaagent.instrumentation.xxljob.v2_3_0;
|
||||||
|
|
||||||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
|
|
||||||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_GLUE_JOB_HANDLER;
|
||||||
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
import static io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobConstants.XXL_METHOD_JOB_HANDLER;
|
||||||
|
|
@ -18,13 +17,14 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;
|
||||||
|
|
||||||
import com.xxl.job.core.handler.IJobHandler;
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobHelper;
|
||||||
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
import io.opentelemetry.javaagent.instrumentation.xxljob.common.XxlJobProcessRequest;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
|
import net.bytebuddy.implementation.bytecode.assign.Assigner;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
public class SimpleJobHandlerInstrumentation implements TypeInstrumentation {
|
public class SimpleJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
|
|
@ -42,32 +42,20 @@ public class SimpleJobHandlerInstrumentation implements TypeInstrumentation {
|
||||||
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
SimpleJobHandlerInstrumentation.class.getName() + "$ScheduleAdvice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class ScheduleAdvice {
|
public static class ScheduleAdvice {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void onSchedule(
|
public static XxlJobHelper.XxlJobScope onSchedule(@Advice.This IJobHandler handler) {
|
||||||
@Advice.This IJobHandler handler,
|
return helper().startSpan(XxlJobProcessRequest.createSimpleJobRequest(handler));
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
|
||||||
@Advice.Local("otelContext") Context context,
|
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
Context parentContext = currentContext();
|
|
||||||
request = XxlJobProcessRequest.createSimpleJobRequest(handler);
|
|
||||||
context = helper().startSpan(parentContext, request);
|
|
||||||
if (context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
scope = context.makeCurrent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||||
public static void stopSpan(
|
public static void stopSpan(
|
||||||
@Advice.Thrown Throwable throwable,
|
@Advice.Return(typing = Assigner.Typing.DYNAMIC) @Nullable Object result,
|
||||||
@Advice.Local("otelRequest") XxlJobProcessRequest request,
|
@Advice.Thrown @Nullable Throwable throwable,
|
||||||
@Advice.Local("otelContext") Context context,
|
@Advice.Enter @Nullable XxlJobHelper.XxlJobScope scope) {
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
helper().endSpan(scope, result, throwable);
|
||||||
helper().stopSpan(request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ import static java.util.Arrays.asList;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
|
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
@AutoService(InstrumentationModule.class)
|
@AutoService(InstrumentationModule.class)
|
||||||
public class XxlJobInstrumentationModule extends InstrumentationModule {
|
public class XxlJobInstrumentationModule extends InstrumentationModule
|
||||||
|
implements ExperimentalInstrumentationModule {
|
||||||
|
|
||||||
public XxlJobInstrumentationModule() {
|
public XxlJobInstrumentationModule() {
|
||||||
super("xxl-job", "xxl-job-2.3.0");
|
super("xxl-job", "xxl-job-2.3.0");
|
||||||
|
|
@ -35,4 +37,9 @@ public class XxlJobInstrumentationModule extends InstrumentationModule {
|
||||||
new SimpleJobHandlerInstrumentation(),
|
new SimpleJobHandlerInstrumentation(),
|
||||||
new GlueJobHandlerInstrumentation());
|
new GlueJobHandlerInstrumentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,24 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class XxlJobHelper {
|
public final class XxlJobHelper {
|
||||||
private final Instrumenter<XxlJobProcessRequest, Void> instrumenter;
|
private final Instrumenter<XxlJobProcessRequest, Void> instrumenter;
|
||||||
private final Predicate<Object> failedStatusPredicate;
|
private final Predicate<Object> failedStatusPredicate;
|
||||||
|
|
||||||
|
public static class XxlJobScope {
|
||||||
|
private final XxlJobProcessRequest request;
|
||||||
|
private final Context context;
|
||||||
|
private final Scope scope;
|
||||||
|
|
||||||
|
private XxlJobScope(XxlJobProcessRequest request, Context context, Scope scope) {
|
||||||
|
this.request = request;
|
||||||
|
this.context = context;
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XxlJobHelper(
|
private XxlJobHelper(
|
||||||
Instrumenter<XxlJobProcessRequest, Void> instrumenter,
|
Instrumenter<XxlJobProcessRequest, Void> instrumenter,
|
||||||
Predicate<Object> failedStatusPredicate) {
|
Predicate<Object> failedStatusPredicate) {
|
||||||
|
|
@ -27,31 +40,25 @@ public final class XxlJobHelper {
|
||||||
return new XxlJobHelper(instrumenter, failedStatusPredicate);
|
return new XxlJobHelper(instrumenter, failedStatusPredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context startSpan(Context parentContext, XxlJobProcessRequest request) {
|
@Nullable
|
||||||
|
public XxlJobScope startSpan(XxlJobProcessRequest request) {
|
||||||
|
Context parentContext = Context.current();
|
||||||
if (!instrumenter.shouldStart(parentContext, request)) {
|
if (!instrumenter.shouldStart(parentContext, request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return instrumenter.start(parentContext, request);
|
Context context = instrumenter.start(parentContext, request);
|
||||||
|
return new XxlJobScope(request, context, context.makeCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSpan(
|
public void endSpan(
|
||||||
Object result,
|
@Nullable XxlJobScope scope, @Nullable Object result, @Nullable Throwable throwable) {
|
||||||
XxlJobProcessRequest request,
|
|
||||||
Throwable throwable,
|
|
||||||
Scope scope,
|
|
||||||
Context context) {
|
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (failedStatusPredicate.test(result)) {
|
if (failedStatusPredicate.test(result)) {
|
||||||
request.setFailed();
|
scope.request.setFailed();
|
||||||
}
|
}
|
||||||
scope.close();
|
scope.scope.close();
|
||||||
instrumenter.end(context, request, null, throwable);
|
instrumenter.end(scope.context, scope.request, null, throwable);
|
||||||
}
|
|
||||||
|
|
||||||
public void stopSpan(
|
|
||||||
XxlJobProcessRequest request, Throwable throwable, Scope scope, Context context) {
|
|
||||||
stopSpan(null, request, throwable, scope, context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue