Fix compile issues.
This commit is contained in:
parent
3e2e294d8a
commit
cc2163b7c2
|
|
@ -5,64 +5,26 @@ import io.opentracing.Span;
|
|||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.propagation.Format;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class SkywalkingTracer implements Tracer {
|
||||
private static String TRACE_HEAD_NAME = "sw3";
|
||||
|
||||
@NeedSnifferActivation("1. ContextManager#inject" +
|
||||
"2. ContextCarrier#serialize")
|
||||
private String inject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NeedSnifferActivation("1. ContextCarrier#deserialize" +
|
||||
"2. ContextManager#extract")
|
||||
private void extract(String carrier) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpanBuilder buildSpan(String operationName) {
|
||||
return new SkywalkingSpanBuilder(operationName);
|
||||
}
|
||||
|
||||
@NeedSnifferActivation
|
||||
@Override
|
||||
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
|
||||
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
|
||||
((TextMap)carrier).put(TRACE_HEAD_NAME, inject());
|
||||
} else if (Format.Builtin.BINARY.equals(format)) {
|
||||
byte[] key = TRACE_HEAD_NAME.getBytes(ByteBufferContext.CHARSET);
|
||||
byte[] value = inject().getBytes(ByteBufferContext.CHARSET);
|
||||
((ByteBuffer)carrier).put(key);
|
||||
((ByteBuffer)carrier).putInt(value.length);
|
||||
((ByteBuffer)carrier).put(value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported format: " + format);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NeedSnifferActivation
|
||||
@Override
|
||||
public <C> SpanContext extract(Format<C> format, C carrier) {
|
||||
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
|
||||
TextMap textMapCarrier = (TextMap)carrier;
|
||||
extract(fetchContextData(textMapCarrier));
|
||||
return new TextMapContext(textMapCarrier);
|
||||
} else if (Format.Builtin.BINARY.equals(format)) {
|
||||
ByteBuffer byteBufferCarrier = (ByteBuffer)carrier;
|
||||
extract(fetchContextData(byteBufferCarrier));
|
||||
return new ByteBufferContext((ByteBuffer)carrier);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported format: " + format);
|
||||
}
|
||||
return new TextMapContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,34 +40,4 @@ public class SkywalkingTracer implements Tracer {
|
|||
throw new IllegalArgumentException("span must be a type of SkywalkingSpan");
|
||||
}
|
||||
}
|
||||
|
||||
private String fetchContextData(TextMap textMap) {
|
||||
Iterator<Map.Entry<String, String>> iterator = textMap.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (TRACE_HEAD_NAME.equals(entry.getKey())) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String fetchContextData(ByteBuffer byteBuffer) {
|
||||
String contextDataStr = new String(byteBuffer.array(), Charset.forName("UTF-8"));
|
||||
int index = contextDataStr.indexOf(TRACE_HEAD_NAME);
|
||||
if (index == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
byteBuffer.position(index + TRACE_HEAD_NAME.getBytes().length);
|
||||
byte[] contextDataBytes = new byte[byteBuffer.getInt()];
|
||||
byteBuffer.get(contextDataBytes);
|
||||
return new String(contextDataBytes, Charset.forName("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package org.skywalking.apm.toolkit.opentracing;
|
||||
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -10,14 +8,11 @@ import java.util.Map;
|
|||
* Created by wusheng on 2016/12/21.
|
||||
*/
|
||||
public class TextMapContext implements SpanContext {
|
||||
private final TextMap textMap;
|
||||
|
||||
TextMapContext(TextMap textMap) {
|
||||
this.textMap = textMap;
|
||||
public TextMapContext() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Map.Entry<String, String>> baggageItems() {
|
||||
return new HashMap<String, String>().entrySet();
|
||||
return new HashMap<String, String>(0).entrySet();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package org.skywalking.apm.agent.core.context;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
public class CarrierItemHead extends CarrierItem {
|
||||
public CarrierItemHead(CarrierItem next) {
|
||||
super("", "", next);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,8 @@ public class ContextCarrier implements Serializable {
|
|||
|
||||
public CarrierItem items() {
|
||||
SW3CarrierItem carrierItem = new SW3CarrierItem(this, null);
|
||||
return carrierItem;
|
||||
CarrierItemHead head = new CarrierItemHead(carrierItem);
|
||||
return head;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,6 +120,7 @@ public class ContextCarrier implements Serializable {
|
|||
*/
|
||||
public boolean isValid() {
|
||||
return traceSegmentId != null
|
||||
&& traceSegmentId.isValid()
|
||||
&& getSpanId() > -1
|
||||
&& parentApplicationInstanceId != DictionaryUtil.nullValue()
|
||||
&& entryApplicationInstanceId != DictionaryUtil.nullValue()
|
||||
|
|
|
|||
|
|
@ -10,24 +10,31 @@ public class ID {
|
|||
private long part2;
|
||||
private long part3;
|
||||
private String encoding;
|
||||
private boolean isValid;
|
||||
|
||||
public ID(long part1, long part2, long part3) {
|
||||
this.part1 = part1;
|
||||
this.part2 = part2;
|
||||
this.part3 = part3;
|
||||
this.encoding = null;
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
public ID(String encodingString) {
|
||||
String[] idParts = encodingString.split(".", 3);
|
||||
int index = 0;
|
||||
String[] idParts = encodingString.split("\\.", 3);
|
||||
this.isValid = true;
|
||||
for (int part = 0; part < 3; part++) {
|
||||
if (part == 0) {
|
||||
part1 = Long.parseLong(idParts[part]);
|
||||
} else if (part == 1) {
|
||||
part2 = Long.parseLong(idParts[part]);
|
||||
} else {
|
||||
part3 = Long.parseLong(idParts[part]);
|
||||
try {
|
||||
if (part == 0) {
|
||||
part1 = Long.parseLong(idParts[part]);
|
||||
} else if (part == 1) {
|
||||
part2 = Long.parseLong(idParts[part]);
|
||||
} else {
|
||||
part3 = Long.parseLong(idParts[part]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,6 +73,10 @@ public class ID {
|
|||
return result;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
public UniqueId transform() {
|
||||
return UniqueId.newBuilder().addIdParts(part1).addIdParts(part2).addIdParts(part3).build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class ContextManagerTest {
|
|||
|
||||
@Test
|
||||
public void createMultipleEntrySpan() {
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|1|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.2343.234234234|1|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
assertTrue(contextCarrier.isValid());
|
||||
|
||||
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
|
||||
|
|
@ -202,7 +202,7 @@ public class ContextManagerTest {
|
|||
|
||||
@Test
|
||||
public void testTransform() throws InvalidProtocolBufferException {
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.234.1983829|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
assertTrue(contextCarrier.isValid());
|
||||
|
||||
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", contextCarrier);
|
||||
|
|
|
|||
|
|
@ -50,16 +50,16 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
span = ContextManager.createExitSpan(generateOperationName(requestURL, invocation), contextCarrier, host + ":" + port);
|
||||
//invocation.getAttachments().put("contextData", contextDataStr);
|
||||
//@see https://github.com/alibaba/dubbo/blob/dubbo-2.5.3/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java#L154-L161
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
rpcContext.getAttachments().put(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
} else {
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(rpcContext.getAttachment(next.getHeadKey()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,9 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
|
||||
import org.skywalking.apm.agent.core.context.trace.LogDataEntity;
|
||||
import org.skywalking.apm.agent.core.context.trace.SpanLayer;
|
||||
|
|
@ -26,7 +24,6 @@ import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef;
|
|||
import org.skywalking.apm.agent.core.context.util.KeyValuePair;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.skywalking.apm.agent.test.helper.FieldSetter;
|
||||
import org.skywalking.apm.agent.test.helper.SegmentHelper;
|
||||
import org.skywalking.apm.agent.test.helper.SegmentRefHelper;
|
||||
import org.skywalking.apm.agent.test.helper.SpanHelper;
|
||||
|
|
@ -34,7 +31,6 @@ import org.skywalking.apm.agent.test.tools.AgentServiceRule;
|
|||
import org.skywalking.apm.agent.test.tools.SegmentStorage;
|
||||
import org.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||
import org.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||
import org.skywalking.apm.plugin.dubbox.BugFixActive;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
|
@ -44,7 +40,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
|||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
@PrepareForTest({RpcContext.class, BugFixActive.class})
|
||||
public class DubboInterceptorTest {
|
||||
|
||||
@SegmentStoragePoint
|
||||
|
|
@ -58,7 +53,6 @@ public class DubboInterceptorTest {
|
|||
|
||||
private DubboInterceptor dubboInterceptor;
|
||||
|
||||
private RequestParamForTestBelow283 testParam;
|
||||
@Mock
|
||||
private RpcContext rpcContext;
|
||||
@Mock
|
||||
|
|
@ -76,39 +70,20 @@ public class DubboInterceptorTest {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dubboInterceptor = new DubboInterceptor();
|
||||
testParam = new RequestParamForTestBelow283();
|
||||
|
||||
PowerMockito.mockStatic(RpcContext.class);
|
||||
|
||||
when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.skywalking.apm.test.TestDubboService"));
|
||||
when(invocation.getMethodName()).thenReturn("test");
|
||||
when(invocation.getParameterTypes()).thenReturn(new Class[] {String.class});
|
||||
when(invocation.getArguments()).thenReturn(new Object[] {testParam});
|
||||
when(invocation.getArguments()).thenReturn(new Object[] {"abc"});
|
||||
PowerMockito.when(RpcContext.getContext()).thenReturn(rpcContext);
|
||||
when(rpcContext.isConsumerSide()).thenReturn(true);
|
||||
allArguments = new Object[] {invoker, invocation};
|
||||
argumentTypes = new Class[] {invoker.getClass(), invocation.getClass()};
|
||||
Config.Agent.APPLICATION_CODE = "DubboTestCases-APP";
|
||||
FieldSetter.setStaticValue(BugFixActive.class, "ACTIVE", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumerBelow283() throws Throwable {
|
||||
BugFixActive.active();
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
||||
assertThat(SegmentHelper.getSpans(traceSegment).size(), is(1));
|
||||
assertConsumerSpan(SegmentHelper.getSpans(traceSegment).get(0));
|
||||
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
contextCarrier.deserialize(testParam.getTraceContext());
|
||||
assertTrue(contextCarrier.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumerWithAttachment() throws Throwable {
|
||||
|
|
@ -147,25 +122,13 @@ public class DubboInterceptorTest {
|
|||
@Test
|
||||
public void testProviderWithAttachment() throws Throwable {
|
||||
when(rpcContext.isConsumerSide()).thenReturn(false);
|
||||
when(rpcContext.getAttachment(Config.Plugin.Propagation.HEADER_NAME)).thenReturn("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
when(rpcContext.getAttachment("sw3")).thenReturn("1.323.4433|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
assertProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProviderBelow283() throws Throwable {
|
||||
when(rpcContext.isConsumerSide()).thenReturn(false);
|
||||
FieldSetter.setStaticValue(BugFixActive.class, "ACTIVE", true);
|
||||
|
||||
testParam.setTraceContext("#AQA*#AQA*4WcWe0tQNQA*|3|1|1|#192.168.1.8 :18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
|
||||
|
||||
dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
|
||||
dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
|
||||
|
||||
assertProvider();
|
||||
}
|
||||
|
||||
private void assertConsumerTraceSegmentInErrorCase(
|
||||
TraceSegment traceSegment) {
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package org.skywalking.apm.plugin.dubbo;
|
||||
|
||||
import org.skywalking.apm.plugin.dubbox.SWBaseBean;
|
||||
|
||||
/**
|
||||
* {@link RequestParamForTestBelow283} store context data for test.
|
||||
*/
|
||||
public class RequestParamForTestBelow283 extends SWBaseBean {
|
||||
|
||||
}
|
||||
|
|
@ -61,9 +61,9 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
|
|||
|
||||
headersField.setAccessible(true);
|
||||
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
List<String> contextCollection = new LinkedList<String>();
|
||||
contextCollection.add(next.getHeadValue());
|
||||
headers.put(next.getHeadKey(), contextCollection);
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
|||
Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod());
|
||||
SpanLayer.asHttp(span);
|
||||
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
httpRequest.setHeader(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ public class MotanConsumerInterceptor implements InstanceConstructorInterceptor,
|
|||
span.setComponent(ComponentsDefine.MOTAN);
|
||||
Tags.URL.set(span, url.getIdentity());
|
||||
SpanLayer.asRPCFramework(span);
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
request.setAttachment(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ public class MotanProviderInterceptor implements InstanceMethodsAroundIntercepto
|
|||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Request request = (Request)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(request.getAttachments().get(next.getHeadKey()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,9 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
|
|||
|
||||
headersField.setAccessible(true);
|
||||
Headers.Builder headerBuilder = request.headers().newBuilder();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
headerBuilder.add(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
headersField.set(request, headerBuilder.build());
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public class ResinV3Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
CauchoRequest request = (CauchoRequest)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(request.getHeader(next.getHeadKey()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ public class ResinV4Interceptor implements InstanceMethodsAroundInterceptor {
|
|||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
CauchoRequest request = (CauchoRequest)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(request.getHeader(next.getHeadKey()));
|
||||
}
|
||||
AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package org.skywalking.apm.plugin.spring.mvc;
|
|||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.context.tag.Tags;
|
||||
|
|
@ -19,8 +19,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|||
|
||||
/**
|
||||
* The <code>ControllerServiceMethodInterceptor</code> only use the first mapping value.
|
||||
*
|
||||
* @See {@link ControllerConstructorInterceptor} to explain why we are doing this.
|
||||
*/
|
||||
public class ControllerServiceMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -40,8 +38,14 @@ public class ControllerServiceMethodInterceptor implements InstanceMethodsAround
|
|||
}
|
||||
|
||||
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
String tracingHeaderValue = request.getHeader(Config.Plugin.Propagation.HEADER_NAME);
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize(tracingHeaderValue);
|
||||
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor
|
|||
SpanLayer.asHttp(span);
|
||||
Object[] cacheValues = new Object[3];
|
||||
cacheValues[0] = requestURL;
|
||||
cacheValues[1] = contextCarrier.serialize();
|
||||
cacheValues[1] = contextCarrier;
|
||||
objInst.setSkyWalkingDynamicField(cacheValues);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class RestExecuteInterceptor implements InstanceMethodsAroundInterceptor
|
|||
Tags.HTTP.METHOD.set(span, httpMethod.toString());
|
||||
SpanLayer.asHttp(span);
|
||||
|
||||
objInst.setSkyWalkingDynamicField(contextCarrier.serialize());
|
||||
objInst.setSkyWalkingDynamicField(contextCarrier);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package org.skywalking.apm.plugin.spring.resttemplate.sync;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -22,7 +23,12 @@ public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor
|
|||
ClientHttpRequest clientHttpRequest = (ClientHttpRequest)ret;
|
||||
if (clientHttpRequest instanceof AbstractClientHttpRequest) {
|
||||
AbstractClientHttpRequest httpRequest = (AbstractClientHttpRequest)clientHttpRequest;
|
||||
httpRequest.getHeaders().set(Config.Plugin.Propagation.HEADER_NAME, String.valueOf(objInst.getSkyWalkingDynamicField()));
|
||||
ContextCarrier contextCarrier = (ContextCarrier)objInst.getSkyWalkingDynamicField();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
httpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package org.springframework.http.client;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -19,7 +20,13 @@ public class RestRequestInterceptor implements InstanceMethodsAroundInterceptor
|
|||
Object ret) throws Throwable {
|
||||
AbstractAsyncClientHttpRequest clientHttpRequest = (AbstractAsyncClientHttpRequest)ret;
|
||||
if (ret != null) {
|
||||
clientHttpRequest.getHeaders().set(Config.Plugin.Propagation.HEADER_NAME, String.valueOf(((Object[])objInst.getSkyWalkingDynamicField())[1]));
|
||||
Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
|
||||
ContextCarrier contextCarrier = (ContextCarrier)cacheValues[1];
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
clientHttpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor
|
|||
HttpServletRequest request = (HttpServletRequest)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
|
||||
CarrierItem items = contextCarrier.items();
|
||||
while (items.hasNext()) {
|
||||
CarrierItem next = items.next();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(request.getHeader(next.getHeadKey()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import io.opentracing.propagation.Format;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.skywalking.apm.toolkit.opentracing.TextMapContext;
|
||||
|
||||
public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -17,10 +22,26 @@ public class SkywalkingTracerExtractInterceptor implements InstanceMethodsAround
|
|||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
String carrier = (String)allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier().deserialize(carrier);
|
||||
ContextManager.extract(contextCarrier);
|
||||
return ret;
|
||||
Format format = (Format)allArguments[0];
|
||||
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
|
||||
TextMap textMapCarrier = (TextMap)allArguments[1];
|
||||
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
Iterator<Map.Entry<String, String>> iterator = textMapCarrier.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (next.getHeadKey().equals(entry.getKey())) {
|
||||
next.setHeadValue(entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return new TextMapContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package org.skywalking.apm.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import io.opentracing.propagation.Format;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.lang.reflect.Method;
|
||||
import org.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.ContextManager;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
|
|
@ -17,9 +20,21 @@ public class SkywalkingTracerInjectInterceptor implements InstanceMethodsAroundI
|
|||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
ContextManager.inject(contextCarrier);
|
||||
return contextCarrier.serialize();
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue