Search in sources :

Example 11 with AbstractSpan

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

the class KafkaProducerInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    ContextCarrier contextCarrier = new ContextCarrier();
    ProducerRecord record = (ProducerRecord) allArguments[0];
    String topicName = (String) ((EnhancedInstance) record).getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + topicName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, (String) objInst.getSkyWalkingDynamicField());
    Tags.MQ_BROKER.set(activeSpan, (String) objInst.getSkyWalkingDynamicField());
    Tags.MQ_TOPIC.set(activeSpan, topicName);
    SpanLayer.asMQ(activeSpan);
    activeSpan.setComponent(ComponentsDefine.KAFKA);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        record.headers().add(next.getHeadKey(), next.getHeadValue().getBytes());
    }
    EnhancedInstance callbackInstance = (EnhancedInstance) allArguments[1];
    if (callbackInstance != null) {
        callbackInstance.setSkyWalkingDynamicField(ContextManager.capture());
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 12 with AbstractSpan

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

the class StateInterceptor method handleMethodException.

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

Example 13 with AbstractSpan

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

the class StateInterceptorTest method testHttpClient.

@Test
public void testHttpClient() throws Throwable {
    AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
    stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    stateInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    processResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    processResponseInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertHttpSpan(spans.get(0));
    verify(request, times(1)).setHeader(anyString(), anyString());
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with AbstractSpan

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

the class HystrixCommandGetFallbackInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
    activeSpan.setComponent(ComponentsDefine.HYSTRIX);
    ContextManager.continued(snapshot);
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 15 with AbstractSpan

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

the class CallableStatementTracing method execute.

public static <R> R execute(java.sql.CallableStatement realStatement, ConnectionInfo connectInfo, String method, String sql, Executable<R> exec) throws SQLException {
    try {
        AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        SpanLayer.asDB(span);
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());
        return exec.exe(realStatement, sql);
    } catch (SQLException e) {
        AbstractSpan span = ContextManager.activeSpan();
        span.errorOccurred();
        span.log(e);
        throw e;
    } finally {
        ContextManager.stopSpan();
    }
}
Also used : SQLException(java.sql.SQLException) 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