Search in sources :

Example 6 with AbstractSpan

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

the class HttpHostInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    HttpHost producer = (HttpHost) allArguments[0];
    String uri = producer.toURI();
    AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/" + method.getName());
    span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT).setLayer(SpanLayer.HTTP);
    Tags.HTTP.METHOD.set(span, ((HttpRequest) allArguments[1]).getRequestLine().getMethod());
    Tags.URL.set(span, uri);
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpHost(org.apache.http.HttpHost) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 7 with AbstractSpan

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

the class ContextManagerTest method createMultipleExitSpan.

@Test
public void createMultipleExitSpan() {
    AbstractSpan entrySpan = ContextManager.createEntrySpan("/testEntrySpan", null);
    entrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(entrySpan, "GET");
    Tags.URL.set(entrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(entrySpan);
    ContextCarrier firstExitSpanContextCarrier = new ContextCarrier();
    AbstractSpan firstExitSpan = ContextManager.createExitSpan("/testFirstExit", firstExitSpanContextCarrier, "127.0.0.1:8080");
    firstExitSpan.setComponent(ComponentsDefine.DUBBO);
    Tags.URL.set(firstExitSpan, "dubbo://127.0.0.1:8080");
    SpanLayer.asRPCFramework(firstExitSpan);
    ContextCarrier secondExitSpanContextCarrier = new ContextCarrier();
    AbstractSpan secondExitSpan = ContextManager.createExitSpan("/testSecondExit", secondExitSpanContextCarrier, "127.0.0.1:9080");
    secondExitSpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(secondExitSpan, "GET");
    Tags.URL.set(secondExitSpan, "127.0.0.1:8080");
    SpanLayer.asHttp(secondExitSpan);
    secondExitSpan.setOperationName("/testSecondExit-setOperationName");
    ContextManager.stopSpan();
    ContextManager.stopSpan();
    ContextManager.stopSpan();
    assertThat(tracingData.getTraceSegments().size(), is(1));
    TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
    assertNull(actualSegment.getRefs());
    List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
    assertThat(spanList.size(), is(2));
    AbstractTracingSpan actualFirstExitSpan = spanList.get(0);
    assertThat(actualFirstExitSpan.getOperationName(), is("/testFirstExit"));
    assertThat(actualFirstExitSpan.getSpanId(), is(1));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualFirstExitSpan), is(0));
    assertThat(SpanHelper.getComponentId(actualFirstExitSpan), is(ComponentsDefine.DUBBO.getId()));
    assertThat(SpanHelper.getLayer(actualFirstExitSpan), is(SpanLayer.RPC_FRAMEWORK));
    AbstractTracingSpan actualEntrySpan = spanList.get(1);
    assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan"));
    assertThat(actualEntrySpan.getSpanId(), is(0));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
    assertThat(firstExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
    assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));
    assertThat(firstExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
    assertThat(secondExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
    assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));
    assertThat(secondExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
}
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)

Example 8 with AbstractSpan

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

the class StatementTracing method execute.

public static <R> R execute(java.sql.Statement realStatement, ConnectionInfo connectInfo, String method, String sql, Executable<R> exec) throws SQLException {
    try {
        AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        Tags.DB_STATEMENT.set(span, sql);
        span.setComponent(connectInfo.getComponent());
        SpanLayer.asDB(span);
        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)

Example 9 with AbstractSpan

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

the class JedisMethodInterceptor method handleMethodException.

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

Example 10 with AbstractSpan

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

the class JedisMethodInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan("Jedis/" + method.getName(), peer);
    span.setComponent(ComponentsDefine.REDIS);
    Tags.DB_TYPE.set(span, "Redis");
    SpanLayer.asCache(span);
    if (allArguments.length > 0 && allArguments[0] instanceof String) {
        Tags.DB_STATEMENT.set(span, method.getName() + " " + allArguments[0]);
    }
}
Also used : 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