Search in sources :

Example 21 with CarrierItem

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

the class MessageSendInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Message message = (Message) allArguments[2];
    ContextCarrier contextCarrier = new ContextCarrier();
    String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress);
    span.setComponent(ComponentsDefine.ROCKET_MQ);
    Tags.MQ_BROKER.set(span, (String) allArguments[0]);
    Tags.MQ_TOPIC.set(span, message.getTopic());
    SpanLayer.asMQ(span);
    SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3];
    StringBuilder properties = new StringBuilder(requestHeader.getProperties());
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        if (!StringUtil.isEmpty(next.getHeadValue())) {
            properties.append(next.getHeadKey());
            properties.append(NAME_VALUE_SEPARATOR);
            properties.append(next.getHeadValue());
            properties.append(PROPERTY_SEPARATOR);
        }
    }
    requestHeader.setProperties(properties.toString());
    if (allArguments[6] != null) {
        ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager.capture()));
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Message(org.apache.rocketmq.common.message.Message) SendMessageRequestHeader(org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 22 with CarrierItem

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

the class SkywalkingTracerInjectInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    Format format = (Format) allArguments[1];
    if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
        TextMap carrier = (TextMap) allArguments[2];
        ContextCarrier contextCarrier = new ContextCarrier();
        ContextManager.inject(contextCarrier);
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            carrier.put(next.getHeadKey(), next.getHeadValue());
        }
    } else {
    // Don't support other format yet.
    }
    return null;
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Format(io.opentracing.propagation.Format) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) TextMap(io.opentracing.propagation.TextMap)

Example 23 with CarrierItem

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

the class RestRequestInterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    ClientHttpRequest clientHttpRequest = (ClientHttpRequest) ret;
    if (clientHttpRequest instanceof AbstractClientHttpRequest) {
        AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest) clientHttpRequest;
        ContextCarrier contextCarrier = (ContextCarrier) objInst.getSkyWalkingDynamicField();
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue());
        }
    }
    return ret;
}
Also used : AbstractClientHttpRequest(org.springframework.http.client.AbstractClientHttpRequest) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) AbstractClientHttpRequest(org.springframework.http.client.AbstractClientHttpRequest)

Example 24 with CarrierItem

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

the class BlockingCallClientInterceptor method start.

@Override
public void start(Listener responseListener, Metadata headers) {
    final AbstractSpan span = ContextManager.createExitSpan(serviceName, remotePeer);
    span.setComponent(ComponentsDefine.GRPC);
    SpanLayer.asRPCFramework(span);
    final ContextCarrier contextCarrier = new ContextCarrier();
    ContextManager.inject(contextCarrier);
    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), headers);
}
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 25 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(io.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)

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