commit
4581fde070
|
|
@ -54,7 +54,7 @@ public class Span {
|
|||
private final List<LogData> logs;
|
||||
|
||||
/**
|
||||
* Create a new span, by given span id and parent span id.
|
||||
* Create a new span, by given span id, parent span id and operationName.
|
||||
* This span must belong a {@link TraceSegment}, also is a part of Distributed Trace.
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
|
|
@ -63,9 +63,23 @@ public class Span {
|
|||
* @param operationName {@link #operationName}
|
||||
*/
|
||||
private Span(int spanId, int parentSpanId, String operationName) {
|
||||
this(spanId, parentSpanId, operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
*Create a new span, by given span id, parent span id, operationName and startTime.
|
||||
* This span must belong a {@link TraceSegment}, also is a part of Distributed Trace.
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
* @param parentSpanId given by the creator, and must be an existed span id in the {@link TraceSegment}. Value -1
|
||||
* means no parent span if this {@link TraceSegment}.
|
||||
* @param operationName {@link #operationName}
|
||||
* @param startTime given start timestamp.
|
||||
*/
|
||||
private Span(int spanId, int parentSpanId, String operationName, long startTime){
|
||||
this.spanId = spanId;
|
||||
this.parentSpanId = parentSpanId;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.startTime = startTime;
|
||||
this.operationName = operationName;
|
||||
this.tags = new HashMap<String, Object>();
|
||||
this.logs = new ArrayList<LogData>();
|
||||
|
|
@ -82,6 +96,19 @@ public class Span {
|
|||
this(spanId, -1, operationName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Create a new span, by given span id and give startTime but no parent span id,
|
||||
* No parent span id means that, this Span is the first span of the {@link TraceSegment}
|
||||
*
|
||||
* @param spanId given by the creator, and must be unique id in the {@link TraceSegment}
|
||||
* @param operationName {@link #operationName}
|
||||
* @param startTime given start time of span
|
||||
*/
|
||||
public Span(int spanId, String operationName, long startTime) {
|
||||
this(spanId, -1, operationName, startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new span, by given span id and given parent {@link Span}.
|
||||
*
|
||||
|
|
@ -90,7 +117,18 @@ public class Span {
|
|||
* @param operationName {@link #operationName}
|
||||
*/
|
||||
public Span(int spanId, Span parentSpan, String operationName) {
|
||||
this(spanId, parentSpan.spanId, operationName);
|
||||
this(spanId, parentSpan.spanId, operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param spanId
|
||||
* @param parentSpan
|
||||
* @param operationName
|
||||
* @param startTime
|
||||
*/
|
||||
public Span(int spanId, Span parentSpan, String operationName, long startTime) {
|
||||
this(spanId, parentSpan.spanId, operationName, startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,12 +138,36 @@ public class Span {
|
|||
* @param owner of the Span.
|
||||
*/
|
||||
public void finish(TraceSegment owner) {
|
||||
this.endTime = System.currentTimeMillis();
|
||||
this.finish(owner, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the active Span.
|
||||
* When it is finished, it will be archived by the given {@link TraceSegment}, which owners it.
|
||||
* At the same out, set the {@link #endTime} as the given endTime
|
||||
*
|
||||
* @param owner of the Span.
|
||||
* @param endTime of the Span.
|
||||
*/
|
||||
public void finish(TraceSegment owner, long endTime){
|
||||
this.endTime = endTime;
|
||||
owner.archive(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string name for the logical operation this span represents.
|
||||
*
|
||||
* @return this Span instance, for chaining
|
||||
*/
|
||||
public Span setOperationName(String operationName){
|
||||
this.operationName = operationName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key:value tag on the Span.
|
||||
*
|
||||
* @return this Span instance, for chaining
|
||||
*/
|
||||
public final Span setTag(String key, String value) {
|
||||
tags.put(key, value);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class SpanTestCase {
|
|||
Span span1 = new Span(0, "serviceA");
|
||||
Tags.SPAN_LAYER.asHttp(span1);
|
||||
Tags.COMPONENT.set(span1, "Spring");
|
||||
Tags.PEER_HOST.set(span1, ipToInt("127.0.0.1"));
|
||||
Tags.PEER_HOST.set(span1, "127.0.0.1");
|
||||
Tags.ERROR.set(span1, true);
|
||||
Tags.STATUS_CODE.set(span1, 302);
|
||||
Tags.URL.set(span1, "http://127.0.0.1/serviceA");
|
||||
|
|
@ -49,40 +49,10 @@ public class SpanTestCase {
|
|||
Map<String, Object> tags = span1.getTags();
|
||||
Assert.assertEquals(8, tags.size());
|
||||
Assert.assertTrue(Tags.SPAN_LAYER.isHttp(span1));
|
||||
Assert.assertEquals("127.0.0.1", intToIp(Tags.PEER_HOST.get(span1)));
|
||||
Assert.assertEquals("127.0.0.1", Tags.PEER_HOST.get(span1));
|
||||
Assert.assertTrue(Tags.ERROR.get(span1));
|
||||
}
|
||||
|
||||
private int ipToInt(String ipAddress) {
|
||||
int result = 0;
|
||||
String[] ipAddressInArray = ipAddress.split("\\.");
|
||||
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
|
||||
int ip = Integer.parseInt(ipAddressInArray[3 - i]);
|
||||
|
||||
//left shifting 24,16,8,0 and bitwise OR
|
||||
//1. 192 << 24
|
||||
//1. 168 << 16
|
||||
//1. 1 << 8
|
||||
//1. 2 << 0
|
||||
result |= ip << (i * 8);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String intToIp(int longIp) {
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
sb.append(String.valueOf((longIp >>> 24)));
|
||||
sb.append(".");
|
||||
sb.append(String.valueOf((longIp & 0x00FFFFFF) >>> 16));
|
||||
sb.append(".");
|
||||
sb.append(String.valueOf((longIp & 0x0000FFFF) >>> 8));
|
||||
sb.append(".");
|
||||
sb.append(String.valueOf((longIp & 0x000000FF)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogException(){
|
||||
Span span1 = new Span(0, "serviceA");
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
<module>skywalking-api</module>
|
||||
<module>skywalking-sdk-plugin</module>
|
||||
<module>skywalking-toolkit-activation</module>
|
||||
<module>skywalking-sniffer-mock</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -46,31 +46,6 @@
|
|||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies section -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ public enum ContextManager implements TracerContextListener {
|
|||
return get().createSpan(operationName);
|
||||
}
|
||||
|
||||
public Span createSpan(String operationName, long startTime) {
|
||||
return get().createSpan(operationName);
|
||||
}
|
||||
|
||||
public Span activeSpan() {
|
||||
return get().activeSpan();
|
||||
}
|
||||
|
|
@ -65,6 +69,10 @@ public enum ContextManager implements TracerContextListener {
|
|||
get().stopSpan(span);
|
||||
}
|
||||
|
||||
public void stopSpan(Long endTime) {
|
||||
get().stopSpan(activeSpan(), endTime);
|
||||
}
|
||||
|
||||
public void stopSpan() {
|
||||
stopSpan(activeSpan());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,12 +40,23 @@ public final class TracerContext {
|
|||
* @return the new active span.
|
||||
*/
|
||||
public Span createSpan(String operationName) {
|
||||
return this.createSpan(operationName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new span, as an active span, by the given operationName and startTime;
|
||||
*
|
||||
* @param operationName {@link Span#operationName}
|
||||
* @param startTime {@link Span#startTime}
|
||||
* @return
|
||||
*/
|
||||
public Span createSpan(String operationName, long startTime){
|
||||
Span parentSpan = peek();
|
||||
Span span;
|
||||
if (parentSpan == null) {
|
||||
span = new Span(spanIdGenerator++, operationName);
|
||||
span = new Span(spanIdGenerator++, operationName, startTime);
|
||||
} else {
|
||||
span = new Span(spanIdGenerator++, parentSpan, operationName);
|
||||
span = new Span(spanIdGenerator++, parentSpan, operationName, startTime);
|
||||
}
|
||||
push(span);
|
||||
return span;
|
||||
|
|
@ -68,9 +79,13 @@ public final class TracerContext {
|
|||
* @param span to finish. It must the the top element of {@link #activeSpanStack}.
|
||||
*/
|
||||
public void stopSpan(Span span) {
|
||||
stopSpan(span, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void stopSpan(Span span, Long endTime){
|
||||
Span lastSpan = peek();
|
||||
if (lastSpan == span) {
|
||||
segment.archive(pop());
|
||||
pop().finish(segment, endTime);
|
||||
} else {
|
||||
throw new IllegalStateException("Stopping the unexpected span = " + span);
|
||||
}
|
||||
|
|
@ -171,7 +186,7 @@ public final class TracerContext {
|
|||
/**
|
||||
* Clear the given {@link TracerContextListener}
|
||||
*/
|
||||
static synchronized void remove(TracerContextListener listener){
|
||||
public static synchronized void remove(TracerContextListener listener){
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ package com.a.eye.skywalking.api.logging;
|
|||
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.util.LoggingUtil;
|
||||
|
||||
import com.a.eye.skywalking.api.util.LoggingUtil;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.a.eye.skywalking.logging.LogLevel.*;
|
||||
import static com.a.eye.skywalking.api.logging.LogLevel.*;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.util.LoggingUtil;
|
||||
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.util.LoggingUtil;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.a.eye.skywalking.api.logging;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
|
||||
public class WriterFactory {
|
||||
private WriterFactory(){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import com.a.eye.skywalking.api.plugin.PluginException;
|
||||
|
||||
public class EnhanceException extends PluginException {
|
||||
private static final long serialVersionUID = -2234782755784217255L;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.assist;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InterceptorException;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InterceptorException;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
|||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import com.a.eye.skywalking.api.plugin.PluginException;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhanceException;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.util.StringUtil;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
|
||||
/**
|
||||
* Plugins, which only need enhance class static methods.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
|
||||
/**
|
||||
* Plugins, which only need enhance class static methods.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.a.eye.skywalking.api.queue;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.context.TracerContextListener;
|
||||
import com.a.eye.skywalking.api.context.TracerContextListener;
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
|
@ -36,7 +36,7 @@ public enum TraceSegmentProcessQueue implements TracerContextListener {
|
|||
RingBuffer<TraceSegmentHolder> buffer;
|
||||
|
||||
TraceSegmentProcessQueue() {
|
||||
disruptor = new Disruptor<>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
disruptor = new Disruptor<TraceSegmentHolder>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
buffer = disruptor.getRingBuffer();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.a.eye.skywalking.api.util;
|
||||
|
||||
import com.a.eye.skywalking.conf.Constants;
|
||||
import com.a.eye.skywalking.api.conf.Constants;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class TraceIdGenerator {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
|||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.api.plugin;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.StaticMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking-sniffer</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>skywalking-sniffer-mock</artifactId>
|
||||
<description>This is a sniffer mock module, test for test-dependency, only.</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- direct dependency junit, based on this is a mock module. -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.context;
|
||||
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.api.context.TracerContextListener;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* This is mock tracer context listener, which should be added by calling {@link TracerContext.ListenerManager#add(TracerContextListener)}.
|
||||
* This mock listener will hold all finished trace, which all are generated by {@link TracerContext#finish()}.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public class MockTracerContextListener implements TracerContextListener {
|
||||
private List<TraceSegment> finishedTraceSegments = Collections.synchronizedList(new ArrayList<TraceSegment>());
|
||||
|
||||
@Override public void afterFinished(TraceSegment traceSegment) {
|
||||
finishedTraceSegments.add(traceSegment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert all finished {@link #finishedTraceSegments} match the given size.
|
||||
*
|
||||
* @param size the give size.
|
||||
*/
|
||||
public void assertSize(int size){
|
||||
Assert.assertEquals(size, finishedTraceSegments.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the given index is a valid index of {@link #finishedTraceSegments}
|
||||
*
|
||||
* @param index the given index.
|
||||
*/
|
||||
public void assertValidIndex(int index){
|
||||
Assert.assertTrue(index < finishedTraceSegments.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the {@link TraceSegment} at the given index of {@link #finishedTraceSegments},
|
||||
* and run the given {@link SegmentAssert#call(TraceSegment)} to assert.
|
||||
*
|
||||
* @param index the given index.
|
||||
* @param segmentAssert the given assert.
|
||||
*/
|
||||
public void assertTraceSegment(int index, SegmentAssert segmentAssert){
|
||||
assertValidIndex(index);
|
||||
segmentAssert.call(finishedTraceSegments.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all hold data.
|
||||
*/
|
||||
public void clear(){
|
||||
finishedTraceSegments.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link TraceSegment} of the given index.
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public TraceSegment getFinished(int index){
|
||||
assertSize(index + 1);
|
||||
return finishedTraceSegments.get(index);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.context;
|
||||
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* The <code>SegmentAssert</code> interface should be implemented by any
|
||||
* class whose instances are intended to assert a trace segment data.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public interface SegmentAssert{
|
||||
void call(TraceSegment finishedSegment);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace;
|
||||
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public interface TraceSegmentBuilder {
|
||||
TraceSegment build(MockTracerContextListener listener);
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace;
|
||||
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.trace.SingleTomcat200TraceBuilder;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.trace.SingleTomcat404TraceBuilder;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.trace.SingleTomcat500TraceBuilder;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* The <code>TraceSegmentBuilderFactory</code> contains all {@link TraceSegmentBuilder} implementations.
|
||||
* All the implementations can build a true {@link TraceSegment} object, and contain all necessary spans, with all tags/events, all refs.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum TraceSegmentBuilderFactory {
|
||||
INSTANCE;
|
||||
|
||||
/**
|
||||
* @see {@link SingleTomcat200TraceBuilder}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TraceSegment singleTomcat200Trace(){
|
||||
return this.build(SingleTomcat200TraceBuilder.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link SingleTomcat404TraceBuilder}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TraceSegment singleTomcat404Trace(){
|
||||
return this.build(SingleTomcat404TraceBuilder.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link SingleTomcat500TraceBuilder}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TraceSegment singleTomcat500Trace(){
|
||||
return this.build(SingleTomcat500TraceBuilder.INSTANCE);
|
||||
}
|
||||
|
||||
private TraceSegment build(TraceSegmentBuilder builder){
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
try{
|
||||
TracerContext.ListenerManager.add(listener);
|
||||
return builder.build(listener);
|
||||
}finally{
|
||||
TracerContext.ListenerManager.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace.builders.span;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import com.a.eye.skywalking.trace.tag.Tags;
|
||||
|
||||
/**
|
||||
* The <code>TomcatSpanGenerator</code> generate all possible spans, by tracing Tomcat.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum TomcatSpanGenerator {
|
||||
INSTANCE;
|
||||
|
||||
/**
|
||||
* When tomcat response 200.
|
||||
*/
|
||||
public void on200(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/serviceA");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/serviceA");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 200);
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
}
|
||||
|
||||
/**
|
||||
* When tomcat response 404.
|
||||
*/
|
||||
public void on404(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/service/unknown");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/unknown");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 404);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
}
|
||||
|
||||
/**
|
||||
* When tomcat response 500.
|
||||
*/
|
||||
public void on500(){
|
||||
Span webSpan = ContextManager.INSTANCE.createSpan("/web/error/service");
|
||||
Tags.COMPONENT.set(webSpan, "tomcat");
|
||||
Tags.URL.set(webSpan, "http://10.21.9.35/web/error/service");
|
||||
Tags.SPAN_KIND.set(webSpan, Tags.SPAN_KIND_SERVER);
|
||||
Tags.STATUS_CODE.set(webSpan, 500);
|
||||
Tags.ERROR.set(webSpan,true);
|
||||
webSpan.log(new NumberFormatException("Can't convert 'abc' to int."));
|
||||
ContextManager.INSTANCE.stopSpan(webSpan);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace.builders.trace;
|
||||
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilder;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.span.TomcatSpanGenerator;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* A Trace contains only one span, which represent a tomcat server side span.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum SingleTomcat200TraceBuilder implements TraceSegmentBuilder {
|
||||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on200();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace.builders.trace;
|
||||
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilder;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.span.TomcatSpanGenerator;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* A Trace contains only one span, which represent a tomcat server side span.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum SingleTomcat404TraceBuilder implements TraceSegmentBuilder {
|
||||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on404();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.a.eye.skywalking.sniffer.mock.trace.builders.trace;
|
||||
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilder;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.builders.span.TomcatSpanGenerator;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* A Trace contains only one span, which represent a tomcat server side span.
|
||||
*
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
public enum SingleTomcat500TraceBuilder implements TraceSegmentBuilder {
|
||||
INSTANCE;
|
||||
|
||||
@Override public TraceSegment build(MockTracerContextListener listener) {
|
||||
TomcatSpanGenerator.INSTANCE.on500();
|
||||
return listener.getFinished(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.a.eye.skywalking.sniffer.mock;
|
||||
|
||||
import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener;
|
||||
import com.a.eye.skywalking.sniffer.mock.context.SegmentAssert;
|
||||
import com.a.eye.skywalking.sniffer.mock.trace.TraceSegmentBuilderFactory;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/21.
|
||||
*/
|
||||
public class MockTracerContextListenerTestCase {
|
||||
@Test
|
||||
public void testAfterFinished(){
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat200Trace());
|
||||
|
||||
Assert.assertNotNull(listener.getFinished(0));
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testAssertSize(){
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());
|
||||
|
||||
listener.assertSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertTraceSegment(){
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat500Trace());
|
||||
|
||||
listener.assertTraceSegment(0, new SegmentAssert() {
|
||||
@Override public void call(TraceSegment finishedSegment) {
|
||||
Assert.assertNotNull(finishedSegment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testClear(){
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());
|
||||
listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat500Trace());
|
||||
|
||||
listener.clear();
|
||||
listener.assertValidIndex(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log.log4j.v1.x;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
|
|
@ -25,7 +26,9 @@ public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor
|
|||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return "TID:" + Tracing.getTraceId();
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(carrier);
|
||||
return "TID:" + carrier.getTraceSegmentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log.log4j.v2.x;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log.log4j.v2.x;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.StaticMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/12/7.
|
||||
|
|
@ -14,7 +19,9 @@ public class PrintTraceIdInterceptor implements StaticMethodsAroundInterceptor {
|
|||
*/
|
||||
@Override
|
||||
public void beforeMethod(StaticMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
((StringBuilder) interceptorContext.allArguments()[0]).append("TID:" + Tracing.getTraceId());
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(carrier);
|
||||
((StringBuilder) interceptorContext.allArguments()[0]).append("TID:" + carrier.getTraceSegmentId());
|
||||
|
||||
//make sure origin method do not invoke.
|
||||
result.defineReturnValue(null);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log.logback.v1.x;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.log.logback.v1.x;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
|
|
@ -25,7 +26,9 @@ public class PrintTraceIdInterceptor implements InstanceMethodsAroundInterceptor
|
|||
*/
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return "TID:" + Tracing.getTraceId();
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(carrier);
|
||||
return "TID:" + carrier.getTraceSegmentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.noneOf;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,36 +1,32 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.invoke.monitor.LocalMethodInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.Map;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept these following methods:
|
||||
* {@link SkyWalkingSpan#finish()}
|
||||
* {@link SkyWalkingSpan#finish(long)}
|
||||
*/
|
||||
public class SpanFinishInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
Span currentSpan = Tracing.getCurrentSpan();
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
|
||||
Map<String, String> tags = (Map<String, String>) context.get("tags");
|
||||
if (tags != null) {
|
||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||
Tracing.tag(currentSpan, entry.getKey(), entry.getValue());
|
||||
}
|
||||
if(allArguments.length == 1) {
|
||||
ContextManager.INSTANCE.stopSpan(((Long)allArguments[0]));
|
||||
}else{
|
||||
ContextManager.INSTANCE.stopSpan();
|
||||
}
|
||||
|
||||
new LocalMethodInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,28 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
import com.a.eye.skywalking.trace.Span;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingSpan} constructor.
|
||||
*/
|
||||
public class SpanNewInstanceInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
private static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
Object[] allArguments = interceptorContext.allArguments();
|
||||
String operationName = ((String)allArguments[0]);
|
||||
long startTime = ((Long)allArguments[1]);
|
||||
Map<String, String> tags = ((Map<String, String>)allArguments[2]);
|
||||
Span span = ContextManager.INSTANCE.createSpan(operationName, startTime);
|
||||
|
||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||
span.setTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept {@link SkyWalkingSpan#setOperationName(String)}
|
||||
*/
|
||||
public class SpanSetOperationNameInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
String operationName = (String)interceptorContext.allArguments()[0];
|
||||
ContextManager.INSTANCE.activeSpan().setOperationName(operationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,39 +1,42 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.span.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpan;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
* Intercept these following methods:
|
||||
* {@link SkyWalkingSpan#setTag(String, boolean)}
|
||||
* {@link SkyWalkingSpan#setTag(String, Number)}
|
||||
* {@link SkyWalkingSpan#setTag(String, String)}
|
||||
*/
|
||||
public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Map<String, String> contextTags = (Map<String, String>) context.get(TAGS);
|
||||
if (!context.isContain(TAGS)){
|
||||
contextTags = new HashMap<String, String>();
|
||||
context.set(TAGS, contextTags);
|
||||
}
|
||||
|
||||
contextTags.put((String) interceptorContext.allArguments()[0], String.valueOf(interceptorContext
|
||||
.allArguments()[1]));
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
String key = (String)interceptorContext.allArguments()[0];
|
||||
Object value = interceptorContext.allArguments()[1];
|
||||
if (value instanceof String)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (String)value);
|
||||
else if (value instanceof Boolean)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (Boolean)value);
|
||||
else if (value instanceof Number)
|
||||
ContextManager.INSTANCE.activeSpan().setTag(key, (Number)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
*/
|
||||
public enum OpenTracingLocalBuriedPointType implements IBuriedPointType {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "OT";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.LOCAL;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SkyWalkingSpanBuilderActivation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
return "com.a.eye.skywalking.toolkit.opentracing.SkyWalkingSpanBuilder";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[]{
|
||||
new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return takesArguments(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderNewInstanceInterceptor";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("withTag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderWithTagInterceptor";
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("withStartTimestamp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderWithStartTimeInterceptor";
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("start");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor.SpanBuilderStartInterceptor";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
|
||||
public class SpanBuilderNewInstanceInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
public static final String OPERATION_NAME = "operationName";
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
context.set(OPERATION_NAME, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.invoke.monitor.LocalMethodInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.OpenTracingLocalBuriedPointType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
*/
|
||||
public class SpanBuilderStartInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String START_TIME = "startTimestamp";
|
||||
public static final String OPERATION_NAME = "operationName";
|
||||
public static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
|
||||
Long startTime = fetchStartTime(context);
|
||||
String operationName = (String) context.get(OPERATION_NAME);
|
||||
Identification.IdentificationBuilder builder = Identification.newBuilder().viewPoint(operationName)
|
||||
.spanType(OpenTracingLocalBuriedPointType.INSTANCE);
|
||||
|
||||
if (startTime != null){
|
||||
builder.startTime(startTime);
|
||||
}
|
||||
|
||||
Map<String, String> tags = (Map<String, String>) context.get(TAGS);
|
||||
if (tags != null) {
|
||||
for (Map.Entry<String, String> tag : tags.entrySet()) {
|
||||
builder.tag(tag.getKey(), tag.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
new LocalMethodInvokeMonitor().beforeInvoke(builder.build());
|
||||
}
|
||||
|
||||
private Long fetchStartTime(EnhancedClassInstanceContext context) {
|
||||
Object startTime = context.get(START_TIME);
|
||||
if (startTime != null){
|
||||
return (Long) startTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SpanBuilderWithStartTimeInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String START_TIME = "startTimestamp";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
context.set(START_TIME, interceptorContext.allArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by xin on 2017/1/16.
|
||||
*/
|
||||
public class SpanBuilderWithTagInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
public static final String TAGS = "tags";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Map<String, String> contextTags = (Map<String, String>) context.get(TAGS);
|
||||
if (!context.isContain(TAGS)){
|
||||
contextTags = new HashMap<String, String>();
|
||||
context.set(TAGS, contextTags);
|
||||
}
|
||||
|
||||
contextTags.put((String) interceptorContext.allArguments()[0], String.valueOf(interceptorContext
|
||||
.allArguments()[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer;
|
||||
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static com.a.eye.skywalking.api.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.RefContext;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#extractCrossProcessPropagationContextData(TextMap)}
|
||||
*/
|
||||
public class TracerExtractCrossProcessByteBufferContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -24,7 +25,11 @@ public class TracerExtractCrossProcessByteBufferContextInterceptor implements In
|
|||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
ByteBuffer byteBuffer = (ByteBuffer) interceptorContext.allArguments()[0];
|
||||
String contextDataStr = new String(byteBuffer.array(), Charset.forName("UTF-8"));
|
||||
Tracing.initRefContext(new RefContext(contextDataStr));
|
||||
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
carrier.deserialize(contextDataStr);
|
||||
|
||||
ContextManager.INSTANCE.extract(carrier);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,49 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.RefContext;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
import io.opentracing.propagation.TextMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import io.opentracing.propagation.TextMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#extractCrossProcessPropagationContextData(TextMap)}
|
||||
*/
|
||||
public class TracerExtractCrossProcessTextMapContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
|
||||
public static final String SKY_WALKING_TRACING_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
TextMap textMap = (TextMap) interceptorContext.allArguments()[0];
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
TextMap textMap = (TextMap)interceptorContext.allArguments()[0];
|
||||
Iterator<Map.Entry<String, String>> iterator = textMap.iterator();
|
||||
while (iterator.hasNext()){
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (SKY_WALKING_TRACING_NAME.equals(entry.getKey())){
|
||||
try {
|
||||
Tracing.initRefContext(new RefContext(entry.getValue()));
|
||||
}catch (Throwable e){
|
||||
// do something
|
||||
}
|
||||
if (SKY_WALKING_TRACING_NAME.equals(entry.getKey())) {
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
carrier.deserialize(entry.getValue());
|
||||
|
||||
ContextManager.INSTANCE.extract(carrier);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package com.a.eye.skywalking.toolkit.activation.opentracing.tracer.interceptor;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.api.context.ContextCarrier;
|
||||
import com.a.eye.skywalking.api.context.ContextManager;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import com.a.eye.skywalking.toolkit.opentracing.SkyWalkingTracer;
|
||||
|
||||
/**
|
||||
* @author zhangxin
|
||||
* Intercept {@link SkyWalkingTracer#formatCrossProcessPropagationContextData()}
|
||||
*/
|
||||
public class TracerFormatCrossProcessContextInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
|
|
@ -19,23 +19,13 @@ public class TracerFormatCrossProcessContextInterceptor implements InstanceMetho
|
|||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
Span span = Tracing.getCurrentSpan();
|
||||
if (span != null) {
|
||||
return new ContextData(span.getTraceId(), generateSubParentLevelId(span), span.getRouteKey()).toString();
|
||||
}
|
||||
return ret;
|
||||
ContextCarrier carrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(carrier);
|
||||
return carrier.serialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) {
|
||||
|
||||
}
|
||||
|
||||
private String generateSubParentLevelId(Span spanData) {
|
||||
if (spanData.getParentLevel() == null || spanData.getParentLevel().length() == 0) {
|
||||
return spanData.getLevelId() + "";
|
||||
}
|
||||
|
||||
return spanData.getParentLevel() + "." + spanData.getLevelId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
com.a.eye.skywalking.toolkit.activation.opentracing.span.SkyWalkingSpanActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.spanbuilder.SkyWalkingSpanBuilderActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
|
||||
com.a.eye.skywalking.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
|
||||
|
|
|
|||
Loading…
Reference in New Issue