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

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#tag() . 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: ConstructorWithSpanBuilderInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    SkywalkingSpanBuilder spanBuilder = (SkywalkingSpanBuilder) allArguments[0];

    AbstractSpan span;
    if (spanBuilder.isEntry()) {
        span = ContextManager.createEntrySpan(spanBuilder.getOperationName(), null);
    } else if (spanBuilder.isExit() && (!StringUtil.isEmpty(spanBuilder.getPeer()))) {
        span = ContextManager.createExitSpan(spanBuilder.getOperationName(), buildRemotePeer(spanBuilder));
    } else {
        span = ContextManager.createLocalSpan(spanBuilder.getOperationName());
    }

    for (Tag tag : spanBuilder.getTags()) {
        span.tag(Tags.ofKey(tag.getKey()), tag.getValue());
    }
    if (spanBuilder.isError()) {
        span.errorOccurred();
    }

    objInst.setSkyWalkingDynamicField(span);
}
 
Example 2
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 3
Source File: SolrClientInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    if (!ContextManager.isActive()) {
        return ret;
    }

    AbstractSpan span = ContextManager.activeSpan();
    if (ret != null) {
        NamedList<Object> result = (NamedList<Object>) ret;
        NamedList<Object> header = (NamedList<Object>) result.get("responseHeader");

        if (header != null) {
            span.tag(SolrjTags.TAG_Q_TIME, String.valueOf(header.get("QTime")));
        }
        SolrDocumentList list = (SolrDocumentList) result.get("response");
        if (list != null) {
            span.tag(SolrjTags.TAG_NUM_FOUND, String.valueOf(list.getNumFound()));
        }
    }

    ContextManager.stopSpan();
    return ret;
}
 
Example 4
Source File: AdapterActionFutureActionGetMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseSearchResponse(SearchResponse searchResponse, AbstractSpan span) {
    span.tag(Constants.ES_TOOK_MILLIS, Long.toString(searchResponse.getTook().getMillis()));
    span.tag(Constants.ES_TOTAL_HITS, Long.toString(searchResponse.getHits().getTotalHits()));
    if (TRACE_DSL) {
        String tagValue = searchResponse.toString();
        tagValue = ELASTICSEARCH_DSL_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, ELASTICSEARCH_DSL_LENGTH_THRESHOLD) : tagValue;
        Tags.DB_STATEMENT.set(span, tagValue);
    }
}
 
Example 5
Source File: NettySocketIOConnectionInterceptor.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 {
    SocketIOClient client = (SocketIOClient) allArguments[0];

    AbstractSpan span = ContextManager.createEntrySpan("SocketIO/" + method.getName(), new ContextCarrier());
    span.setComponent(ComponentsDefine.SOCKET_IO);
    SpanLayer.asHttp(span);

    // set client addr
    InetSocketAddress remoteAddress = (InetSocketAddress) client.getRemoteAddress();
    String clientAddress = remoteAddress.getAddress().getHostAddress() + ":" + remoteAddress.getPort();
    span.tag(Tags.ofKey("from"), clientAddress);
}
 
Example 6
Source File: CanalInterceptor.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 {
    CanalEnhanceInfo canalEnhanceInfo = (CanalEnhanceInfo) objInst.getSkyWalkingDynamicField();
    SimpleCanalConnector connector = (SimpleCanalConnector) objInst;

    String url = canalEnhanceInfo.getUrl();
    if (Objects.equals(url, "") || url == null) {
        InetSocketAddress address = (InetSocketAddress) connector.getNextAddress();
        String runningAddress = address.getAddress().toString() + ":" + address.getPort();
        runningAddress = runningAddress.replace('/', ' ');
        url = runningAddress;
        List<InetSocketAddress> socketAddressList = (List<InetSocketAddress>) ContextManager.getRuntimeContext()
                                                                                            .get("currentAddress");
        if (socketAddressList != null && socketAddressList.size() > 0) {
            for (InetSocketAddress socketAddress : socketAddressList) {
                String currentAddress = socketAddress.getAddress().toString() + ":" + socketAddress.getPort();
                currentAddress = currentAddress.replace('/', ' ');
                if (!currentAddress.equals(runningAddress)) {
                    url = url + "," + currentAddress;
                }
            }
        }
    }
    String batchSize = allArguments[0].toString();
    String destination = canalEnhanceInfo.getDestination();
    AbstractSpan activeSpan = ContextManager.createExitSpan("Canal/" + destination, url)
                                            .start(System.currentTimeMillis());
    activeSpan.setComponent(ComponentsDefine.CANAL);
    activeSpan.tag(Tags.ofKey("batchSize"), batchSize);
    activeSpan.tag(Tags.ofKey("destination"), destination);

}
 
Example 7
Source File: TransportActionNodeProxyExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseDeleteRequest(DeleteRequest deleteRequest, AbstractSpan span) {
    span.tag(Constants.ES_INDEX, deleteRequest.index());
    span.tag(Constants.ES_TYPE, deleteRequest.type());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, deleteRequest.toString());
    }
}
 
Example 8
Source File: TransportActionNodeProxyExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseUpdateRequest(UpdateRequest updateRequest, AbstractSpan span) {
    span.tag(Constants.ES_INDEX, updateRequest.index());
    span.tag(Constants.ES_TYPE, updateRequest.type());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, updateRequest.toString());
    }
}
 
Example 9
Source File: TransportActionNodeProxyExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseGetRequest(GetRequest getRequest, AbstractSpan span) {
    span.tag(Constants.ES_INDEX, getRequest.index());
    span.tag(Constants.ES_TYPE, getRequest.type());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, getRequest.toString());
    }
}
 
Example 10
Source File: TransportActionNodeProxyExecuteMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseSearchRequest(SearchRequest searchRequest, AbstractSpan span) {
    span.tag(Constants.ES_INDEX, StringUtil.join(',', searchRequest.indices()));
    span.tag(Constants.ES_TYPE, StringUtil.join(',', searchRequest.types()));
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, searchRequest.toString());
    }
}
 
Example 11
Source File: JobExecutorInterceptor.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 {
    ShardingContexts shardingContexts = (ShardingContexts) allArguments[0];
    Integer item = (Integer) allArguments[1];
    ShardingContext shardingContext = new ShardingContext(shardingContexts, item);
    String operateName = shardingContext.getJobName();
    if (!Strings.isNullOrEmpty(shardingContext.getShardingParameter())) {
        operateName += "-" + shardingContext.getShardingParameter();
    }
    AbstractSpan span = ContextManager.createLocalSpan(operateName);
    span.setComponent(ComponentsDefine.ELASTIC_JOB);
    span.tag(Tags.ofKey("sharding_context"), shardingContext.toString());
}
 
Example 12
Source File: AdapterActionFutureActionGetMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void parseBulkResponse(BulkResponse bulkResponse, AbstractSpan span) {
    span.tag(Constants.ES_TOOK_MILLIS, Long.toString(bulkResponse.getTook().getMillis()));
    span.tag(Constants.ES_INGEST_TOOK_MILLIS, Long.toString(bulkResponse.getIngestTookInMillis()));
    if (TRACE_DSL) {
        String tagValue = bulkResponse.toString();
        tagValue = ELASTICSEARCH_DSL_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, ELASTICSEARCH_DSL_LENGTH_THRESHOLD) : tagValue;
        Tags.DB_STATEMENT.set(span, tagValue);
    }
}
 
Example 13
Source File: SolrClientInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        AbstractSpan span = ContextManager.activeSpan();
        int code = 500;
        if (t instanceof SolrException) {
            code = ((SolrException) t).code();
        }
        span.tag(SolrjTags.TAG_STATUS, String.valueOf(code));
        span.errorOccurred().log(t);
    }
}
 
Example 14
Source File: ActiveSpanTagInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
    MethodInterceptResult result) {
    try {
        AbstractSpan activeSpan = ContextManager.activeSpan();
        activeSpan.tag(Tags.ofKey(String.valueOf(allArguments[0])), String.valueOf(allArguments[1]));
    } catch (NullPointerException ignored) {
    }
}
 
Example 15
Source File: SpanSetTagInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                          Object ret) throws Throwable {
    AbstractSpan activeSpan = ContextManager.activeSpan();
    String tagKey = String.valueOf(allArguments[0]);
    String tagValue = String.valueOf(allArguments[1]);
    if (Tags.PEER_SERVICE.getKey().equals(tagKey)) {
        activeSpan.setOperationName(tagValue);
    } else if (Tags.ERROR.getKey().equals(tagKey) && "true".equals(tagValue)) {
        activeSpan.errorOccurred();
    } else {
        activeSpan.tag(org.apache.skywalking.apm.agent.core.context.tag.Tags.ofKey(tagKey), tagValue);
    }
    return ret;
}
 
Example 16
Source File: GsonToJsonInterceptor.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("Gson/ToJson");
    span.setComponent(ComponentsDefine.GSON);
    int length = allArguments[0].toString().length();
    span.tag(Tags.ofKey("length"), Integer.toString(length));

}
 
Example 17
Source File: GsonFromJsonInterceptor.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("Gson/FromJson");
    span.setComponent(ComponentsDefine.GSON);
    int length = allArguments[0].toString().length();
    span.tag(Tags.ofKey("length"), Integer.toString(length));

}
 
Example 18
Source File: EndTransactionMethodInterceptor.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.OPERATION_NAME_SPRING_TRANSACTION_PREFIX + method.getName());
    TransactionStatus status = (TransactionStatus) allArguments[0];
    span.tag(Constants.TAG_SPRING_TRANSACTION_IS_NEW_TRANSACTION, String.valueOf(status.isNewTransaction()));
    span.tag(Constants.TAG_SPRING_TRANSACTION_HAS_SAVEPOINT, String.valueOf(status.hasSavepoint()));
    span.tag(Constants.TAG_SPRING_TRANSACTION_ROLLBACK_ONLY, String.valueOf(status.isRollbackOnly()));
    span.tag(Constants.TAG_SPRING_TRANSACTION_IS_COMPLETED, String.valueOf(status.isCompleted()));
    span.setComponent(ComponentsDefine.SPRING_TX);
}
 
Example 19
Source File: StringTag.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public void set(AbstractSpan span, String tagValue) {
    span.tag(this, tagValue);
}
 
Example 20
Source File: ZooOpt.java    From skywalking with Apache License 2.0 2 votes vote down vote up
/**
 * Add the necessary tags for the WatchedEvent
 *
 * @param span  SkyWalking AbstractSpan.class
 * @param event Zookeeper WatchedEvent.class
 */
static void setTags(AbstractSpan span, WatchedEvent event) {
    span.tag(PATH, event.getPath());
    span.tag(KEEPER_STATE, event.getState().name());
}