public void beforeMethod()

in apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java [75:147]


    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                             MethodInterceptResult result) throws Throwable {
        SolrRequest<?> request = (SolrRequest<?>) allArguments[0];
        SolrjInstance instance = (SolrjInstance) objInst.getSkyWalkingDynamicField();

        SolrParams params = getParams(request.getParams());
        String collection = getCollection(instance, allArguments[2]);

        if ("/update".equals(request.getPath())) {
            AbstractUpdateRequest update = (AbstractUpdateRequest) request;

            AbstractUpdateRequest.ACTION action = update.getAction();
            if (action == null) {
                if (update instanceof UpdateRequest) {
                    AbstractSpan span = null;

                    UpdateRequest ur = (UpdateRequest) update;
                    List<SolrInputDocument> documents = ur.getDocuments();
                    if (documents == null) {
                        String actionName = "DELETE_BY_IDS";

                        List<String> deleteBy = ur.getDeleteById();
                        if (deleteBy == null) {
                            actionName = "DELETE_BY_QUERY";
                            deleteBy = ur.getDeleteQuery();
                        }
                        if (deleteBy == null) {
                            deleteBy = new ArrayList<>();
                        }
                        String operator = getOperatorNameWithAction(collection, request.getPath(), actionName);
                        span = getSpan(operator, instance.getRemotePeer());
                        if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) {
                            span.tag(Tags.DB_STATEMENT, deleteBy.toString());
                        }
                    } else {
                        String operator = getOperatorNameWithAction(collection, request.getPath(), "ADD");
                        span = getSpan(operator, instance.getRemotePeer());
                        if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) {
                            span.tag(SolrjTags.TAG_DOCS_SIZE, String.valueOf(documents.size()));
                        }
                    }
                    if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) {
                        span.tag(SolrjTags.TAG_COMMIT_WITHIN, String.valueOf(ur.getCommitWithin()));
                    }
                } else {
                    getSpan(getOperatorName(collection, request.getPath()), instance.getRemotePeer());
                }
            } else {
                String operator = getOperatorNameWithAction(collection, request.getPath(), action.name());
                AbstractSpan span = getSpan(operator, instance.getRemotePeer());

                if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) {
                    if (action == AbstractUpdateRequest.ACTION.COMMIT) {
                        span.tag(SolrjTags.TAG_SOFT_COMMIT, params.get(UpdateParams.SOFT_COMMIT, ""));
                    } else {
                        span.tag(
                            SolrjTags.TAG_MAX_OPTIMIZE_SEGMENTS, params.get(UpdateParams.MAX_OPTIMIZE_SEGMENTS, "1"));
                    }
                }
            }
        } else if (request instanceof QueryRequest) {
            AbstractSpan span = getSpan(getOperatorName(collection, request.getPath()), instance.getRemotePeer());

            span.tag(SolrjTags.TAG_START, params.get(CommonParams.START, "0"));
            span.tag(SolrjTags.TAG_QT, params.get(CommonParams.QT, request.getPath()));

            if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) {
                span.tag(Tags.DB_STATEMENT, toQueryString(params));
            }
        } else {
            getSpan(getOperatorName(collection, request.getPath()), instance.getRemotePeer());
        }
    }