-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfd54d0
commit 6489cd8
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.../java/io/github/artlibs/autotrace4j/interceptor/impl/PowerJobScheduleTaskInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |