Search in sources :

Example 81 with AbstractSpan

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

the class TomcatInvokeInterceptor method beforeMethod.

/**
 * * The {@link TraceSegment#refs} of current trace segment will reference to the
 * trace segment id of the previous level if the serialized context is not null.
 *
 * @param objInst
 * @param method
 * @param allArguments
 * @param argumentsTypes
 * @param result change this result, if you want to truncate the method.
 * @throws Throwable
 */
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    HttpServletRequest request = (HttpServletRequest) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.TOMCAT);
    SpanLayer.asHttp(span);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 82 with AbstractSpan

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

the class TomcatInvokeInterceptor 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) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
    }
    ContextManager.stopSpan();
    return ret;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 83 with AbstractSpan

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

the class FutureGetInterceptor method handleMethodException.

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

Example 84 with AbstractSpan

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

the class RestExecuteInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    final URI requestURL = (URI) allArguments[0];
    final HttpMethod httpMethod = (HttpMethod) allArguments[1];
    final ContextCarrier contextCarrier = new ContextCarrier();
    String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL.getScheme()) ? 443 : 80);
    AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);
    Object[] cacheValues = new Object[3];
    cacheValues[0] = requestURL;
    cacheValues[1] = contextCarrier;
    objInst.setSkyWalkingDynamicField(cacheValues);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 85 with AbstractSpan

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

the class RestExecuteInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    final URI requestURL = (URI) allArguments[0];
    final HttpMethod httpMethod = (HttpMethod) allArguments[1];
    final ContextCarrier contextCarrier = new ContextCarrier();
    String remotePeer = requestURL.getHost() + ":" + (requestURL.getPort() > 0 ? requestURL.getPort() : "https".equalsIgnoreCase(requestURL.getScheme()) ? 443 : 80);
    AbstractSpan span = ContextManager.createExitSpan(requestURL.getPath(), contextCarrier, remotePeer);
    span.setComponent(ComponentsDefine.SPRING_REST_TEMPLATE);
    Tags.URL.set(span, requestURL.getScheme() + "://" + requestURL.getHost() + ":" + requestURL.getPort() + requestURL.getPath());
    Tags.HTTP.METHOD.set(span, httpMethod.toString());
    SpanLayer.asHttp(span);
    objInst.setSkyWalkingDynamicField(contextCarrier);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) 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