Skip to content

Commit

Permalink
feat: support powerjob
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewest authored and i36lib committed Aug 17, 2024
1 parent bfd54d0 commit 6489cd8
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.artlibs.autotrace4j.interceptor.impl;

import io.github.artlibs.autotrace4j.context.AutoTraceCtx;
import io.github.artlibs.autotrace4j.interceptor.base.AbstractInstanceInterceptor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.lang.reflect.Method;

import static net.bytebuddy.matcher.ElementMatchers.*;

/**
* PowerJob Interceptor
*
* @author orangewest
* @since 2024-07-30
* <p>
*/
public class PowerJobScheduleTaskInterceptor extends AbstractInstanceInterceptor {

/**
* {@inheritDoc}
*/
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return hasSuperType(named("tech.powerjob.worker.core.processor.sdk.BasicProcessor"))
.and(not(isInterface())).and(not(isAbstract()));
}

/**
* {@inheritDoc}
*/
@Override
public ElementMatcher<? super MethodDescription> methodMatcher() {
return named("process")
.and(takesArgument(0, named("tech.powerjob.worker.core.processor.TaskContext")));
}

/**
* {@inheritDoc}
*/
@Override
public void onMethodEnter(Object obj, Object[] allArgs, Method originMethod) throws Exception {
AutoTraceCtx.setTraceId(AutoTraceCtx.generate());
AutoTraceCtx.setSpanId(AutoTraceCtx.generate());
// There will be no parent span as this is a startup context
AutoTraceCtx.setParentSpanId(null);
}

/**
* {@inheritDoc}
*/
@Override
public Object onMethodExit(Object obj, Object[] allArgs, Object result, Method originMethod) throws Exception {
AutoTraceCtx.removeAll();
return result;
}

}

0 comments on commit 6489cd8

Please sign in to comment.