尝试将aws x-ray与java spring@scheduled一起使用时收到subsegmentnotfoundexception

doinxwow  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(392)

我在javaspring项目中实现了awsx-ray,一般来说,它工作正常。记录请求,我可以在aws控制台上看到跟踪。
但是,在特定情况下,它会在启动应用程序时生成异常。
我调试了代码,问题出现在一个任务调度类中,这个类用@enablescheduling注解。如果该类中有任何方法带有@scheduled注解,则应用程序将返回以下错误:

2020-12-17 22:50:51.427 ERROR 24379 --- [pool-2-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task.

com.amazonaws.xray.exceptions.SubsegmentNotFoundException: Failed to end subsegment: subsegment cannot be found.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_265]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_265]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_265]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_265]
    at com.amazonaws.xray.strategy.RuntimeErrorContextMissingStrategy.contextMissing(RuntimeErrorContextMissingStrategy.java:32) ~[aws-xray-recorder-sdk-core-2.8.0.jar:na]
    at com.amazonaws.xray.contexts.ThreadLocalSegmentContext.endSubsegment(ThreadLocalSegmentContext.java:93) ~[aws-xray-recorder-sdk-core-2.8.0.jar:na]
    at com.amazonaws.xray.AWSXRayRecorder.endSubsegment(AWSXRayRecorder.java:627) ~[aws-xray-recorder-sdk-core-2.8.0.jar:na]
    at com.amazonaws.xray.AWSXRay.endSubsegment(AWSXRay.java:125) ~[aws-xray-recorder-sdk-core-2.8.0.jar:na]
    at com.amazonaws.xray.spring.aop.BaseAbstractXRayInterceptor.processXRayTrace(BaseAbstractXRayInterceptor.java:58) ~[aws-xray-recorder-sdk-spring-2.8.0.jar:na]
    at com.amazonaws.xray.spring.aop.BaseAbstractXRayInterceptor.traceAroundMethods(BaseAbstractXRayInterceptor.java:43) ~[aws-xray-recorder-sdk-spring-2.8.0.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_265]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_265]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_265]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_265]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671) ~[spring-aop-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at com.domain.common.ToolBox$$EnhancerBySpringCGLIB$$a2712230.convertStackTraceToString(<generated>) ~[classes/:na]
    at com.domain.event.ScheduledEventHandler.runsEvery1Minute(ScheduledEventHandler.java:111) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_265]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_265]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_265]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_265]
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.3.19.RELEASE.jar:4.3.19.RELEASE]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_265]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_265]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_265]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_265]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_265]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_265]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_265]

我尝试使用自定义子段,例如:使用x光sdkforjava生成自定义子段,什么都没有。
代码如下所示:

@XRayEnabled
@Component
@EnableScheduling
public class ScheduledEventHandler {

    ...

    @Scheduled(fixedDelay = 1*60*1000)
    protected void runsEvery1Minute() {
       ...
    }

    ...
}

在我看来,@xrayenabled注解与@scheduled注解有些不兼容,或者对于这种情况有一个特定的配置。
有人能帮我吗?
谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题