Java Code Examples for org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asDB()

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asDB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportActionNodeProxyExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                         Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {

    TransportClientEnhanceInfo enhanceInfo = (TransportClientEnhanceInfo) objInst.getSkyWalkingDynamicField();
    ActionRequest request = (ActionRequest) allArguments[1];
    String opType = request.getClass().getSimpleName();
    String operationName = Constants.DB_TYPE + "/" + opType;
    AbstractSpan span = ContextManager.createExitSpan(operationName, enhanceInfo.transportAddresses());
    span.setComponent(ComponentsDefine.TRANSPORT_CLIENT);
    Tags.DB_TYPE.set(span, Constants.DB_TYPE);
    Tags.DB_INSTANCE.set(span, enhanceInfo.getClusterName());
    span.tag(Constants.ES_NODE, ((DiscoveryNode) allArguments[0]).getAddress().toString());
    parseRequestInfo(request, span);

    SpanLayer.asDB(span);
}
 
Example 2
Source File: PreparedStatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    if (connectInfo == null) {
        return;
    }
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject
            .getStatementName()), connectInfo.getDatabasePeer());
    Tags.DB_TYPE.set(span, "sql");
    Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
    Tags.DB_STATEMENT.set(span, cacheObject.getSql());
    span.setComponent(connectInfo.getComponent());

    if (Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS) {
        final Object[] parameters = cacheObject.getParameters();
        if (parameters != null && parameters.length > 0) {
            int maxIndex = cacheObject.getMaxIndex();
            SQL_PARAMETERS.set(span, getParameterString(parameters, maxIndex));
        }
    }

    SpanLayer.asDB(span);
}
 
Example 3
Source File: IndicesClientCreateMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    CreateIndexRequest createIndexRequest = (CreateIndexRequest) (allArguments[0]);

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

        Tags.DB_TYPE.set(span, DB_TYPE);
        Tags.DB_INSTANCE.set(span, createIndexRequest.index());
        if (TRACE_DSL) {
            //Store es mapping parameters
            Tags.DB_STATEMENT.set(span, createIndexRequest.mappings().utf8ToString());
        }
        SpanLayer.asDB(span);
    }
}
 
Example 4
Source File: RestHighLevelClientIndexMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    IndexRequest indexRequest = (IndexRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.INDEX_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, indexRequest.index());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, indexRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example 5
Source File: PreparedStatementExecuteMethodsInterceptor.java    From java-plugin-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
    if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
        ConnectionInfo connectInfo = cacheObject.getConnectionInfo();

        AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        Tags.DB_STATEMENT.set(span, cacheObject.getSql());
        span.setComponent(connectInfo.getComponent());
        SpanLayer.asDB(span);
    }
}
 
Example 6
Source File: RestHighLevelClientSearchMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    SearchRequest searchRequest = (SearchRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.SEARCH_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, Arrays.asList(searchRequest.indices()).toString());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, searchRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example 7
Source File: RestHighLevelClientUpdateMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    UpdateRequest updateRequest = (UpdateRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.UPDATE_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, updateRequest.index());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, updateRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example 8
Source File: StatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    if (connectInfo != null) {
        AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject
                .getStatementName()), connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        String sql = allArguments.length > 0 ? (String) allArguments[0] : "";
        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());
        SpanLayer.asDB(span);
    }
}
 
Example 9
Source File: PreparedStatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo
            .getDatabasePeer());
    Tags.DB_TYPE.set(span, "sql");
    Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
    Tags.DB_STATEMENT.set(span, cacheObject.getSql());
    span.setComponent(connectInfo.getComponent());

    if (Config.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS) {
        final Object[] parameters = cacheObject.getParameters();
        if (parameters != null && parameters.length > 0) {
            int maxIndex = cacheObject.getMaxIndex();
            String parameterString = getParameterString(parameters, maxIndex);
            SQL_PARAMETERS.set(span, parameterString);
        }
    }

    SpanLayer.asDB(span);
}
 
Example 10
Source File: TransportActionNodeProxyInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {

    ElasticSearchEnhanceInfo enhanceInfo = (ElasticSearchEnhanceInfo) ((EnhancedInstance) objInst.getSkyWalkingDynamicField())
        .getSkyWalkingDynamicField();
    String opType = allArguments[1].getClass().getSimpleName();
    String operationName = ELASTICSEARCH_DB_OP_PREFIX + opType;
    AbstractSpan span = ContextManager.createExitSpan(operationName, enhanceInfo.transportAddresses());
    span.setComponent(ComponentsDefine.TRANSPORT_CLIENT);
    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, enhanceInfo.getClusterName());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, enhanceInfo.getSource());
    }
    span.tag(ES_NODE, ((DiscoveryNode) allArguments[0]).getAddress().toString());
    span.tag(ES_INDEX, wrapperNullStringValue(enhanceInfo.getIndices()));
    span.tag(ES_TYPE, wrapperNullStringValue(enhanceInfo.getTypes()));
    SpanLayer.asDB(span);
}
 
Example 11
Source File: StatementExecuteMethodsInterceptor.java    From java-plugin-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField();
    if (cacheObject != null && cacheObject.getConnectionInfo() != null) {
        ConnectionInfo connectInfo = cacheObject.getConnectionInfo();

        AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());

        String sql = "";
        if (allArguments.length > 0) {
            sql = (String)allArguments[0];
        }

        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());

        SpanLayer.asDB(span);
    }
}
 
Example 12
Source File: StatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo
        .getDatabasePeer());
    Tags.DB_TYPE.set(span, "sql");
    Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
    Tags.DB_STATEMENT.set(span, (String) allArguments[0]);
    span.setComponent(connectInfo.getComponent());

    SpanLayer.asDB(span);
}
 
Example 13
Source File: DefaultResultSetFutureGetUninterruptiblyInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    AbstractSpan span = ContextManager.createLocalSpan(Constants.CASSANDRA_OP_PREFIX + method.getName());
    span.setComponent(ComponentsDefine.CASSANDRA_JAVA_DRIVER);
    Tags.DB_TYPE.set(span, Constants.CASSANDRA_DB_TYPE);
    SpanLayer.asDB(span);
}
 
Example 14
Source File: ClusterClientHealthMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {

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

        Tags.DB_TYPE.set(span, DB_TYPE);
        SpanLayer.asDB(span);
    }
}
 
Example 15
Source File: PreparedStatementExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
                               Class<?>[] argumentsTypes, MethodInterceptResult result) {
    StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
    ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
    /**
     * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor,
     * before the interceptor sets the connectionInfo.
     *
     * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object)
     */
    if (connectInfo != null) {

        AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject
                .getStatementName()), connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        Tags.DB_STATEMENT.set(span, cacheObject.getSql());
        span.setComponent(connectInfo.getComponent());

        if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) {
            final Object[] parameters = cacheObject.getParameters();
            if (parameters != null && parameters.length > 0) {
                int maxIndex = cacheObject.getMaxIndex();
                String parameterString = getParameterString(parameters, maxIndex);
                SQL_PARAMETERS.set(span, parameterString);
            }
        }

        SpanLayer.asDB(span);
    }
}
 
Example 16
Source File: IndicesClientDeleteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    DeleteIndexRequest deleteIndexRequest = (DeleteIndexRequest) (allArguments[0]);

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

        Tags.DB_TYPE.set(span, DB_TYPE);
        Tags.DB_INSTANCE.set(span, Arrays.asList(deleteIndexRequest.indices()).toString());
        SpanLayer.asDB(span);
    }
}
 
Example 17
Source File: ClusterClientGetSettingsMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {

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

        Tags.DB_TYPE.set(span, DB_TYPE);
        SpanLayer.asDB(span);
    }
}
 
Example 18
Source File: ClusterClientPutSettingsMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    ClusterUpdateSettingsRequest updateSettingsRequest = (ClusterUpdateSettingsRequest) (allArguments[0]);

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

        Tags.DB_TYPE.set(span, DB_TYPE);
        if (TRACE_DSL) {
            StringBuilder sb = new StringBuilder("persistent:[");
            Settings persist = updateSettingsRequest.persistentSettings();
            if (persist != null) {
                sb.append(persist.toString());
            }
            sb.append("]---transient:[");
            Settings transi = updateSettingsRequest.transientSettings();
            if (transi != null) {
                sb.append(transi.toString());
            }
            sb.append("]");
            Tags.DB_STATEMENT.set(span, sb.toString());
        }
        SpanLayer.asDB(span);
    }
}
 
Example 19
Source File: ExecuteEventListener.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void handle(AbstractExecutionEvent event, String operation) {
    switch (event.getEventExecutionType()) {
        case BEFORE_EXECUTE:
            AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource());
            if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) {
                ContextManager.continued((ContextSnapshot) ExecutorDataMap.getDataMap()
                    .get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY));
            }
            Tags.DB_TYPE.set(span, "sql");
            Tags.DB_INSTANCE.set(span, event.getDataSource());
            Tags.DB_STATEMENT.set(span, event.getSql());
            if (!event.getParameters().isEmpty()) {
                String variables = event.getParameters()
                    .stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining(","));
                Tags.DB_BIND_VARIABLES.set(span, variables);
            }
            span.setComponent(ComponentsDefine.SHARDING_JDBC);
            SpanLayer.asDB(span);
            break;
        case EXECUTE_FAILURE:
            span = ContextManager.activeSpan();
            span.errorOccurred();
            if (event.getException().isPresent()) {
                span.log(event.getException().get());
            }
        case EXECUTE_SUCCESS:
            ContextManager.stopSpan();
    }
}
 
Example 20
Source File: MongoSpanHelper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public static void createExitSpan(String executeMethod, String remotePeer, Object operation) {
    AbstractSpan span = ContextManager.createExitSpan(MongoConstants.MONGO_DB_OP_PREFIX + executeMethod, new ContextCarrier(), remotePeer);
    span.setComponent(ComponentsDefine.MONGO_DRIVER);
    Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE);
    SpanLayer.asDB(span);

    if (Config.Plugin.MongoDB.TRACE_PARAM) {
        Tags.DB_STATEMENT.set(span, executeMethod + " " + MongoOperationHelper.getTraceParam(operation));
    }
}