apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientRefreshMethodsInterceptor.java [38:91]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class IndicesClientRefreshMethodsInterceptor implements InstanceMethodsAroundInterceptor {

    @Override
    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        MethodInterceptResult result) throws Throwable {
        RefreshRequest request = (RefreshRequest) (allArguments[0]);

        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField();
        if (restClientEnhanceInfo != null) {
            AbstractSpan span = ContextManager.createExitSpan(Constants.REFRESH_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
            span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

            Tags.DB_TYPE.set(span, DB_TYPE);
            Tags.DB_INSTANCE.set(span, buildIndicesString(request.indices()));
            SpanLayer.asDB(span);
            if (allArguments.length > 2 && allArguments[2] != null && allArguments[2] instanceof ActionListener) {
                allArguments[2] = AdapterUtil.wrapActionListener(restClientEnhanceInfo, Constants.REFRESH_OPERATOR_NAME,
                                                                 (ActionListener) allArguments[2]);
            }
        }
    }

    private String buildIndicesString(String[] indices) {
        if (indices == null || indices.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        int n = indices.length;
        for (int i = 0; i < n; i++) {
            sb.append(indices[i]);
            if (i < n - 1) {
                sb.append(',');
            }
        }
        return sb.toString();
    }

    @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret) throws Throwable {
        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
        if (restClientEnhanceInfo != null) {
            ContextManager.stopSpan();
        }
        return ret;
    }

    @Override
    public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
        Class<?>[] argumentsTypes, Throwable t) {
        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
        if (restClientEnhanceInfo != null) {
            ContextManager.activeSpan().log(t);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientRefreshMethodsInterceptor.java [39:93]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class IndicesClientRefreshMethodsInterceptor implements InstanceMethodsAroundInterceptor {

    @Override
    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        MethodInterceptResult result) throws Throwable {
        RefreshRequest request = (RefreshRequest) (allArguments[0]);

        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField();
        if (restClientEnhanceInfo != null) {
            AbstractSpan span = ContextManager.createExitSpan(Constants.REFRESH_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
            span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

            Tags.DB_TYPE.set(span, DB_TYPE);
            Tags.DB_INSTANCE.set(span, buildIndicesString(request.indices()));
            SpanLayer.asDB(span);

            if (allArguments.length > 2 && allArguments[2] != null && allArguments[2] instanceof ActionListener) {
                allArguments[2] = AdapterUtil.wrapActionListener(restClientEnhanceInfo, Constants.REFRESH_OPERATOR_NAME,
                                                                 (ActionListener) allArguments[2]);
            }
        }
    }

    private String buildIndicesString(String[] indices) {
        if (indices == null || indices.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        int n = indices.length;
        for (int i = 0; i < n; i++) {
            sb.append(indices[i]);
            if (i < n - 1) {
                sb.append(',');
            }
        }
        return sb.toString();
    }

    @Override
    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret) throws Throwable {
        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
        if (restClientEnhanceInfo != null) {
            ContextManager.stopSpan();
        }
        return ret;
    }

    @Override
    public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
        Class<?>[] argumentsTypes, Throwable t) {
        RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
        if (restClientEnhanceInfo != null) {
            ContextManager.activeSpan().log(t);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



