xzyJavaX opened a new issue, #8969: URL: https://github.com/apache/skywalking/issues/8969
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues. ### Apache SkyWalking Component Java Agent (apache/skywalking-java) ### What happened elasticsearch-6.x-plugin, elasticsearch-7.x-plugin throw NPE. `org.elasticsearch.client.transport.TransportClientNodesService$ScheduledNodeSampler.run` calls `org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.AdapterActionFutureActionGetMethodsInterceptor#handleMethodException()` or `org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor.AdapterActionFutureActionGetMethodsInterceptor#handleMethodException()` respectively in elasticsearch-6.x-plugin, elasticsearch-7.x-plugin when an exception is thrown. `ContextManager.activeSpan().log(t)` or similar is called in the error handling method without NULL check. Since the `ScheduledNodeSampler` runs on a separate thread, active span may not exist. Error log: `ERROR 2022-04-28 11:49:29:300 elasticsearch[_client_][generic][T#4] InstMethodsInter : class[class org.elasticsearch.action.support.PlainActionFuture] handle method[actionGet] exception failure java.lang.NullPointerException at org.apache.skywalking.apm.agent.core.context.ContextManager.activeSpan(ContextManager.java:176) at org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.AdapterActionFutureActionGetMethodsInterceptor.handleMethodException(AdapterActionFutureActionGetMethodsInterceptor.java:69) at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:90) at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java) at org.elasticsearch.transport.ConnectionManager.internalOpenConnection(ConnectionManager.java:209) at org.elasticsearch.transport.ConnectionManager.openConnection(ConnectionManager.java:80) at org.elasticsearch.transport.TransportService.openConnection(TransportService.java:366) at org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler.doSample(TransportClientNodesService.java:411) at org.elasticsearch.client.transport.TransportClientNodesService$NodeSampler.sample(TransportClientNodesService.java:362) at org.elasticsearch.client.transport.TransportClientNodesService$ScheduledNodeSampler.run(TransportClientNodesService.java:394) at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:708) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750)` ### What you expected to happen Check the current tracing context or call `isTrace` to check enhanced obejct instead of recoding the error directly For example, ```java RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); if (restClientEnhanceInfo != null) { ContextManager.activeSpan().log(t); } ``` We have to check every interceptor in these plugins to prevent NPE ### How to reproduce Specify an elasticsearch source that cannot be connected,ensure that org.elasticsearch.client.transport.TransportClientNodesService are used in the project and mount skywalking-agent to start. ### Anything else _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
