Search in sources :

Example 66 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.

the class ResinV4Interceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    HttpServletResponse response = (HttpServletResponse) allArguments[1];
    AbstractSpan span = ContextManager.activeSpan();
    if (response.getStatus() >= 400) {
        Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
        span.errorOccurred();
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 67 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.

the class ResinV4Interceptor method handleMethodException.

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
    AbstractSpan activeSpan = ContextManager.activeSpan();
    activeSpan.log(t);
    activeSpan.errorOccurred();
}
Also used : AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 68 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.

the class KafkaConsumerInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Map<TopicPartition, List<ConsumerRecord<?, ?>>> records = (Map<TopicPartition, List<ConsumerRecord<?, ?>>>) ret;
    // 
    if (records.size() > 0) {
        ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField();
        AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopics() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(requiredInfo.getStartTime());
        activeSpan.setComponent(ComponentsDefine.KAFKA);
        SpanLayer.asMQ(activeSpan);
        Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers());
        Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics());
        for (List<ConsumerRecord<?, ?>> consumerRecords : records.values()) {
            for (ConsumerRecord<?, ?> record : consumerRecords) {
                ContextCarrier contextCarrier = new ContextCarrier();
                CarrierItem next = contextCarrier.items();
                while (next.hasNext()) {
                    next = next.next();
                    Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator();
                    if (iterator.hasNext()) {
                        next.setHeadValue(new String(iterator.next().value()));
                    }
                }
                ContextManager.extract(contextCarrier);
            }
        }
        ContextManager.stopSpan();
    }
    return ret;
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Header(org.apache.kafka.common.header.Header) TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) Map(java.util.Map)

Example 69 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.

the class PreparedStatementExecuteMethodsInterceptor method beforeMethod.

@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, cacheObject.getSql());
    span.setComponent(connectInfo.getComponent());
    SpanLayer.asDB(span);
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 70 with AbstractSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.

the class StatementExecuteMethodsInterceptor method beforeMethod.

@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();
    /**
     * To protected the code occur NullPointException. because mysql execute system sql when constructor method in
     * {@link com.mysql.jdbc.ConnectionImpl} class executed. but the interceptor set the connection Info after
     * the constructor method executed.
     *
     * @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());
        /**
         * The first argument of all intercept method in `com.mysql.jdbc.StatementImpl` class is SQL, except the
         * `executeBatch` method that the jdbc plugin need to trace, because of this method argument size is zero.
         */
        String sql = "";
        if (allArguments.length > 0) {
            sql = (String) allArguments[0];
        }
        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());
        SpanLayer.asDB(span);
    }
}
Also used : ConnectionInfo(org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo) StatementEnhanceInfos(org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)141 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)36 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)29 URI (java.net.URI)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 ConnectionInfo (org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 StatementEnhanceInfos (org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos)6 Invocation (io.servicecomb.core.Invocation)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Invocation (org.apache.servicecomb.core.Invocation)5 SQLException (java.sql.SQLException)4 Metadata (io.grpc.Metadata)3 Field (java.lang.reflect.Field)3 List (java.util.List)3 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)3 EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)3 Request (com.weibo.api.motan.rpc.Request)2 Response (com.weibo.api.motan.rpc.Response)2