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

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan#setComponent() . 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: Armeria085ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
                         final Class<?>[] argumentsTypes, final MethodInterceptResult result) {

    DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
    HttpHeaders headers = httpRequest.headers();

    ContextCarrier carrier = new ContextCarrier();
    for (CarrierItem item = carrier.items(); item.hasNext(); ) {
        item = item.next();
        item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey())));
    }

    AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier);
    entrySpan.setComponent(ComponentsDefine.ARMERIA);
    entrySpan.setLayer(SpanLayer.HTTP);
    entrySpan.setPeer(httpRequest.authority());
    Tags.URL.set(entrySpan, httpRequest.path());
    Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name());
}
 
Example 2
Source File: TracingRunnable.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    if (ContextManager.isActive() && snapshot.isFromCurrent()) {
        // Thread not switched, skip restore snapshot.
        delegate.run();
        return;
    }

    // Create local coroutine span
    AbstractSpan span = ContextManager.createLocalSpan(COROUTINE);
    span.setComponent(ComponentsDefine.KT_COROUTINE);

    // Recover with snapshot
    ContextManager.continued(snapshot);

    try {
        delegate.run();
    } finally {
        ContextManager.stopSpan(span);
    }
}
 
Example 3
Source File: ServerInterceptor.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 {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    if (request.getKvAttachment() == null) {
        request.setKvAttachment(new HashMap<>());
    }
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue((String) request.getKvAttachment().get(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(generateOperationName(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.BRPC_JAVA);
}
 
Example 4
Source File: HttpClientWriteRequestInterceptor.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 {
    HttpURLConnection connection = (HttpURLConnection) objInst.getSkyWalkingDynamicField();
    MessageHeader headers = (MessageHeader) allArguments[0];
    URL url = connection.getURL();
    ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(getPath(url), contextCarrier, getPeer(url));
    span.setComponent(ComponentsDefine.JDK_HTTP);
    Tags.HTTP.METHOD.set(span, connection.getRequestMethod());
    Tags.URL.set(span, url.toString());
    SpanLayer.asHttp(span);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        headers.add(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example 5
Source File: EhcacheLockInterceptor.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 {
    EhcacheEnhanceInfo enhanceInfo = (EhcacheEnhanceInfo) objInst.getSkyWalkingDynamicField();

    String operateName = method.getName()
                               .substring(0, method.getName().length() - LOCK_ENHANCE_METHOD_SUFFIX.length());

    AbstractSpan span = ContextManager.createLocalSpan("Ehcache/" + operateName + "/" + enhanceInfo.getCacheName());
    span.setComponent(ComponentsDefine.EHCACHE);
    SpanLayer.asCache(span);

    Object element = allArguments[0];
    if (element != null) {
        Tags.DB_STATEMENT.set(span, element.toString());
    }
}
 
Example 6
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 7
Source File: SyncHttpRequestSendInterceptor.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 {
    HttpRequest request = (HttpRequest) objInst;
    ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(request.getURI()
                                                             .getPath(), contextCarrier, request.getHost() + ":" + request
        .getPort());
    span.setComponent(ComponentsDefine.JETTY_CLIENT);

    Tags.HTTP.METHOD.set(span, getHttpMethod(request));
    Tags.URL.set(span, request.getURI().toString());
    SpanLayer.asHttp(span);

    CarrierItem next = contextCarrier.items();
    HttpFields field = request.getHeaders();
    while (next.hasNext()) {
        next = next.next();
        field.add(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example 8
Source File: SynchronousDispatcherInterceptor.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 {
    HttpRequest request = (HttpRequest) allArguments[0];

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHttpHeaders().getHeaderString(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(request.getUri().getPath(), contextCarrier);
    Tags.URL.set(span, toPath(request.getUri().getRequestUri().toString()));
    Tags.HTTP.METHOD.set(span, request.getHttpMethod());
    span.setComponent(ComponentsDefine.RESTEASY);
    SpanLayer.asHttp(span);
}
 
Example 9
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 10
Source File: TraceSegmentServiceClientTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendTraceSegmentWithoutException() throws InvalidProtocolBufferException {
    grpcServerRule.getServiceRegistry().addService(serviceImplBase);

    AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null);
    firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
    Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(firstEntrySpan);
    ContextManager.stopSpan();

    serviceClient.consume(storage.getTraceSegments());

    assertThat(upstreamSegments.size(), is(1));
    SegmentObject traceSegmentObject = upstreamSegments.get(0);
    assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0));
    assertThat(traceSegmentObject.getSpansCount(), is(1));

    SpanObject spanObject = traceSegmentObject.getSpans(0);
    assertThat(spanObject.getSpanType(), is(SpanType.Entry));
    assertThat(spanObject.getSpanId(), is(0));
    assertThat(spanObject.getParentSpanId(), is(-1));
}
 
Example 11
Source File: SyncHttpRequestSendInterceptor.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 {
    HttpRequest request = (HttpRequest) objInst;
    ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(request.getURI()
                                                             .getPath(), contextCarrier, request.getHost() + ":" + request
        .getPort());
    span.setComponent(ComponentsDefine.JETTY_CLIENT);

    Tags.HTTP.METHOD.set(span, getHttpMethod(request));
    Tags.URL.set(span, request.getURI().toString());
    SpanLayer.asHttp(span);

    CarrierItem next = contextCarrier.items();
    HttpFields field = request.getHeaders();
    while (next.hasNext()) {
        next = next.next();
        field.add(next.getHeadKey(), next.getHeadValue());
    }
}
 
Example 12
Source File: SofaRpcProviderInterceptor.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 {
    SofaRequest sofaRequest = (SofaRequest) allArguments[0];

    AbstractSpan span = null;

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        final String headKey = next.getHeadKey();
        final Object attachment = sofaRequest.getRequestProp(SKYWALKING_PREFIX + headKey);
        if (attachment != null) {
            next.setHeadValue(attachment.toString());
        } else {
            next.setHeadValue("");
        }
    }
    span = ContextManager.createEntrySpan(generateViewPoint(sofaRequest), contextCarrier);

    span.setComponent(ComponentsDefine.SOFARPC);
    SpanLayer.asRPCFramework(span);
}
 
Example 13
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 14
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 15
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 16
Source File: AdapterActionFutureActionGetMethodsInterceptor.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 {

    if (!isTrace(objInst)) {
        return;
    }

    AbstractSpan span = ContextManager.createLocalSpan(Constants.DB_TYPE + "/" + Constants.BASE_FUTURE_METHOD);
    span.setComponent(ComponentsDefine.TRANSPORT_CLIENT);
    Tags.DB_TYPE.set(span, Constants.DB_TYPE);
}
 
Example 17
Source File: MessageSendInterceptor.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 {
    Message message = (Message) allArguments[2];
    ContextCarrier contextCarrier = new ContextCarrier();
    String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress);
    span.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    Tags.MQ_BROKER.set(span, (String) allArguments[0]);
    Tags.MQ_TOPIC.set(span, message.getTopic());
    SpanLayer.asMQ(span);

    SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3];
    StringBuilder properties = new StringBuilder(requestHeader.getProperties());
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        if (!StringUtil.isEmpty(next.getHeadValue())) {
            properties.append(next.getHeadKey());
            properties.append(NAME_VALUE_SEPARATOR);
            properties.append(next.getHeadValue());
            properties.append(PROPERTY_SEPARATOR);
        }
    }
    requestHeader.setProperties(properties.toString());

    if (allArguments[6] != null) {
        ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager
            .capture()));
    }
}
 
Example 18
Source File: SWBiConsumer.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(T t, U u) {
    AbstractSpan span = ContextManager.createLocalSpan(operationName + "/accept");
    span.setComponent(ComponentsDefine.LETTUCE);
    Tags.DB_TYPE.set(span, "Redis");
    SpanLayer.asCache(span);
    try {
        ContextManager.continued(snapshot);
        biConsumer.accept(t, u);
    } catch (Throwable th) {
        ContextManager.activeSpan().errorOccurred().log(th);
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example 19
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));
    }
}
 
Example 20
Source File: RabbitMQProducerInterceptor.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    ContextCarrier contextCarrier = new ContextCarrier();
    AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[4];
    AMQP.BasicProperties.Builder propertiesBuilder;

    Map<String, Object> headers = new HashMap<String, Object>();
    if (properties != null) {
        propertiesBuilder = properties.builder()
                                      .appId(properties.getAppId())
                                      .clusterId(properties.getClusterId())
                                      .contentEncoding(properties.getContentEncoding())
                                      .contentType(properties.getContentType())
                                      .correlationId(properties.getCorrelationId())
                                      .deliveryMode(properties.getDeliveryMode())
                                      .expiration(properties.getExpiration())
                                      .messageId(properties.getMessageId())
                                      .priority(properties.getPriority())
                                      .replyTo(properties.getReplyTo())
                                      .timestamp(properties.getTimestamp())
                                      .type(properties.getType())
                                      .userId(properties.getUserId());

        // copy origin headers
        if (properties.getHeaders() != null) {
            headers.putAll(properties.getHeaders());
        }
    } else {
        propertiesBuilder = new AMQP.BasicProperties.Builder();
    }

    String exChangeName = (String) allArguments[0];
    String queueName = (String) allArguments[1];
    String url = (String) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + "Topic/" + exChangeName + "Queue/" + queueName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, url);
    Tags.MQ_BROKER.set(activeSpan, url);
    Tags.MQ_QUEUE.set(activeSpan, queueName);
    Tags.MQ_TOPIC.set(activeSpan, exChangeName);
    SpanLayer.asMQ(activeSpan);
    activeSpan.setComponent(ComponentsDefine.RABBITMQ_PRODUCER);
    CarrierItem next = contextCarrier.items();

    while (next.hasNext()) {
        next = next.next();
        headers.put(next.getHeadKey(), next.getHeadValue());
    }

    allArguments[4] = propertiesBuilder.headers(headers).build();
}