Search in sources :

Example 11 with CarrierItem

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

the class AbstractMessageConsumeInterceptor method getContextCarrierFromMessage.

private ContextCarrier getContextCarrierFromMessage(MessageExt message) {
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(message.getUserProperty(next.getHeadKey()));
    }
    return contextCarrier;
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem)

Example 12 with CarrierItem

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

the class RealCallInterceptor method beforeMethod.

/**
 * Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host,
 * port, kind, component, url from {@link okhttp3.Request}.
 * Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}.
 *
 * @param method
 * @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 {
    Request request = (Request) objInst.getSkyWalkingDynamicField();
    ContextCarrier contextCarrier = new ContextCarrier();
    HttpUrl requestUrl = request.url();
    AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri().getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl.port());
    span.setComponent(ComponentsDefine.OKHTTP);
    Tags.HTTP.METHOD.set(span, request.method());
    Tags.URL.set(span, requestUrl.uri().toString());
    SpanLayer.asHttp(span);
    Field headersField = Request.class.getDeclaredField("headers");
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL);
    headersField.setAccessible(true);
    Headers.Builder headerBuilder = request.headers().newBuilder();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        headerBuilder.add(next.getHeadKey(), next.getHeadValue());
    }
    headersField.set(request, headerBuilder.build());
}
Also used : Field(java.lang.reflect.Field) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Headers(okhttp3.Headers) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 13 with CarrierItem

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

the class AbstractMethodInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    String requestURL = pathMappingCache.findPathMapping(method);
    if (requestURL == null) {
        requestURL = getRequestURL(method);
        pathMappingCache.addPathMapping(method, requestURL);
        requestURL = pathMappingCache.findPathMapping(method);
    }
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION);
    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) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) EnhanceRequireObjectCache(org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 14 with CarrierItem

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

the class TransportClientHandlerInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Invocation invocation = (Invocation) allArguments[0];
    if (!checkRegisterStatus(invocation)) {
        return;
    }
    URI uri = new URI(invocation.getEndpoint().toString());
    String peer = uri.getHost() + ":" + uri.getPort();
    String operationName = invocation.getMicroserviceQualifiedName();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
    }
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Invocation(org.apache.servicecomb.core.Invocation) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) URI(java.net.URI) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 15 with CarrierItem

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

the class MotanProviderInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getAttachments().get(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.MOTAN);
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Request(com.weibo.api.motan.rpc.Request) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)35 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)35 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Metadata (io.grpc.Metadata)3 Field (java.lang.reflect.Field)3 URI (java.net.URI)3 URL (java.net.URL)3 EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)3 Request (com.weibo.api.motan.rpc.Request)2 ForwardingClientCallListener (io.grpc.ForwardingClientCallListener)2 Format (io.opentracing.propagation.Format)2 TextMap (io.opentracing.propagation.TextMap)2 Invocation (io.servicecomb.core.Invocation)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Headers (okhttp3.Headers)2 HttpUrl (okhttp3.HttpUrl)2 Request (okhttp3.Request)2 Invocation (org.apache.servicecomb.core.Invocation)2