Search in sources :

Example 6 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance 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(com.alibaba.rocketmq.common.message.Message) SendMessageRequestHeader(com.alibaba.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.v3.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 7 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class MessageSendInterceptorTest method setUp.

@Before
public void setUp() {
    messageSendInterceptor = new MessageSendInterceptor();
    enhancedInstance = new EnhancedInstance() {

        @Override
        public Object getSkyWalkingDynamicField() {
            return "127.0.0.1:6543";
        }

        @Override
        public void setSkyWalkingDynamicField(Object value) {
        }
    };
    arguments = new Object[] { "127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, callBack };
    argumentsWithoutCallback = new Object[] { "127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, null };
    when(messageRequestHeader.getProperties()).thenReturn("");
    when(message.getTags()).thenReturn("TagA");
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) Before(org.junit.Before)

Example 8 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class AsyncCallInterceptor method onConstruct.

@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    /**
     * The first argument of constructor is not the `real` parameter when the enhance class is an inner class. This
     * is the JDK compiler mechanism.
     */
    EnhancedInstance realCallInstance = (EnhancedInstance) allArguments[1];
    Object enhanceRequireInfo = realCallInstance.getSkyWalkingDynamicField();
    objInst.setSkyWalkingDynamicField(enhanceRequireInfo);
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)

Example 9 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance 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 10 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class ConnectIterceptor method afterMethod.

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
    ((EnhancedInstance) ret).setSkyWalkingDynamicField(ContextManager.capture());
    InetSocketAddress remoteAddress = (InetSocketAddress) allArguments[0];
    String peer = remoteAddress.toString().substring(1);
    Object[] cacheValue = new Object[3];
    cacheValue[0] = ContextManager.capture();
    cacheValue[1] = peer;
    objInst.setSkyWalkingDynamicField(cacheValue);
    return ret;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)

Aggregations

EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)12 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)4 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)3 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)3 Before (org.junit.Before)2 Message (com.alibaba.rocketmq.common.message.Message)1 SendMessageRequestHeader (com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader)1 InetSocketAddress (java.net.InetSocketAddress)1 Request (okhttp3.Request)1 SessionRequest (org.apache.http.nio.reactor.SessionRequest)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 Message (org.apache.rocketmq.common.message.Message)1 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)1 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo)1 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo)1