Search in sources :

Example 1 with AbstractSpan

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

the class StreamCallClientInterceptor method start.

@Override
public void start(Listener responseListener, Metadata headers) {
    final ContextCarrier contextCarrier = new ContextCarrier();
    final AbstractSpan span = ContextManager.createExitSpan(serviceName, contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.GRPC);
    SpanLayer.asRPCFramework(span);
    CarrierItem contextItem = contextCarrier.items();
    while (contextItem.hasNext()) {
        contextItem = contextItem.next();
        Metadata.Key<String> headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER);
        headers.put(headerKey, contextItem.getHeadValue());
    }
    delegate().start(new CallListener(responseListener, ContextManager.capture()), headers);
    ContextManager.stopSpan();
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ForwardingClientCallListener(io.grpc.ForwardingClientCallListener) Metadata(io.grpc.Metadata) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 2 with AbstractSpan

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

the class HttpClientExecuteInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    if (allArguments[0] == null || allArguments[1] == null) {
        return ret;
    }
    HttpResponse response = (HttpResponse) ret;
    StatusLine responseStatusLine = response.getStatusLine();
    if (responseStatusLine != null) {
        int statusCode = responseStatusLine.getStatusCode();
        AbstractSpan span = ContextManager.activeSpan();
        if (statusCode >= 400) {
            span.errorOccurred();
            Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
        }
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : StatusLine(org.apache.http.StatusLine) HttpResponse(org.apache.http.HttpResponse) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 3 with AbstractSpan

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

the class HttpClientExecuteInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    if (allArguments[0] == null || allArguments[1] == null) {
        // illegal args, can't trace. ignore.
        return;
    }
    final HttpHost httpHost = (HttpHost) allArguments[0];
    HttpRequest httpRequest = (HttpRequest) allArguments[1];
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = null;
    String remotePeer = httpHost.getHostName() + ":" + (httpHost.getPort() > 0 ? httpHost.getPort() : "https".equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80);
    try {
        URL url = new URL(httpRequest.getRequestLine().getUri());
        span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer);
    } catch (MalformedURLException e) {
        throw e;
    }
    span.setComponent(ComponentsDefine.HTTPCLIENT);
    Tags.URL.set(span, httpRequest.getRequestLine().getUri());
    Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod());
    SpanLayer.asHttp(span);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        httpRequest.setHeader(next.getHeadKey(), next.getHeadValue());
    }
}
Also used : HttpRequest(org.apache.http.HttpRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) MalformedURLException(java.net.MalformedURLException) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) HttpHost(org.apache.http.HttpHost) URL(java.net.URL) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 4 with AbstractSpan

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

the class HttpClientExecuteInterceptor 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 5 with AbstractSpan

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

the class DefaultConnectingIOReactorIterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Object[] cacheValue = (Object[]) objInst.getSkyWalkingDynamicField();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan("httpasyncclient/" + method.getName(), contextCarrier, cacheValue[1].toString());
    ContextManager.continued((ContextSnapshot) cacheValue[0]);
    span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT).setLayer(SpanLayer.HTTP);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) 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