提交 fde3c60a 编写于 作者: wu-sheng's avatar wu-sheng

Add get method to all ‘Tag’ classes. Begin to add test case.

上级 a3953405
......@@ -140,6 +140,16 @@ public class Span {
return Collections.unmodifiableMap(tags);
}
/**
* Get tag value of the given key.
*
* @param key the given tag key.
* @return tag value.
*/
public Object getTag(String key){
return tags.get(key);
}
/**
* This method is from opentracing-java.
* {@see https://github.com/opentracing/opentracing-java/blob/release-0.20.9/opentracing-api/src/main/java/io/opentracing/Span.java#L91}
......
package com.a.eye.skywalking.trace;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
......@@ -100,4 +101,24 @@ public class TraceSegment {
public String getTraceSegmentId() {
return traceSegmentId;
}
public long getStartTime() {
return startTime;
}
public long getEndTime() {
return endTime;
}
public TraceSegmentRef getPrimaryRef() {
return primaryRef;
}
public List<TraceSegmentRef> getRefs() {
return Collections.unmodifiableList(refs);
}
public List<Span> getSpans() {
return Collections.unmodifiableList(spans);
}
}
package com.a.eye.skywalking.trace;
/**
* {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment}.
* {@link TraceSegmentRef} is like a pointer, which ref to another {@link TraceSegment},
* use {@link #spanId} point to the exact span of the ref {@link TraceSegment}.
*
* Created by wusheng on 2017/2/17.
*/
......
......@@ -8,7 +8,7 @@ import com.a.eye.skywalking.trace.Span;
* which provide an easy way to
* {@link Span#setTag(String, String)} ,
* {@link Span#setTag(String, Number)} ,
* {@link Span#setTag(String, boolean)}
* {@link Span#setTag(String, boolean)} ,
*
* Created by wusheng on 2017/2/17.
*/
......@@ -27,4 +27,6 @@ public abstract class AbstractTag<T> {
}
protected abstract void set(Span span, T tagValue);
public abstract T get(Span span);
}
......@@ -16,4 +16,8 @@ public class BooleanTag extends AbstractTag<Boolean>{
public void set(Span span, Boolean tagValue) {
span.setTag(key, tagValue);
}
@Override public Boolean get(Span span) {
return (Boolean)span.getTag(super.key);
}
}
package com.a.eye.skywalking.trace.tag;
import com.a.eye.skywalking.trace.Span;
/**
* Do the same thing as {@link StringTag}, just with a {@link Integer} value.
*
* Created by wusheng on 2017/2/18.
*/
public class IntTag extends AbstractTag<Integer> {
public IntTag(String key) {
super(key);
}
@Override
public void set(Span span, Integer tagValue) {
span.setTag(super.key, tagValue);
}
@Override public Integer get(Span span) {
return (Integer)span.getTag(super.key);
}
}
......@@ -16,4 +16,8 @@ public class ShortTag extends AbstractTag<Short> {
public void set(Span span, Short tagValue) {
span.setTag(super.key, tagValue);
}
@Override public Short get(Span span) {
return (Short)span.getTag(super.key);
}
}
......@@ -17,4 +17,8 @@ public class StringTag extends AbstractTag<String> {
protected void set(Span span, String tagValue) {
span.setTag(key, tagValue);
}
@Override public String get(Span span) {
return (String)span.getTag(super.key);
}
}
......@@ -10,11 +10,21 @@ public final class Tags {
private Tags() {
}
/**
* HTTP_URL records the url of the incoming request.
*/
public static final StringTag HTTP_URL = new StringTag("http.url");
/**
* HTTP_STATUS records the http status code of the response.
*/
public static final IntTag HTTP_STATUS = new IntTag("http.status_code");
/**
* SPAN_KIND hints at the relationship between spans.
* e.g. cl = client; se = server.
*/
public static StringTag SPAN_KIND = new StringTag("span.kind");
public static final StringTag SPAN_KIND = new StringTag("span.kind");
/**
* COMPONENT is a low-cardinality identifier of the module, library, or package that is instrumented.
......@@ -26,4 +36,19 @@ public final class Tags {
* ERROR indicates whether a Span ended in an error state.
*/
public static final BooleanTag ERROR = new BooleanTag("error");
/**
* PEER_HOST_IPV4 records IPv4 host address of the peer.
*/
public static final IntTag PEER_HOST_IPV4 = new IntTag("peer.ipv4");
/**
* DB_URL records the url of the database access.
*/
public static final StringTag DB_URL = new StringTag("db.url");
/**
* DB_SQL records the sql of the database access.
*/
public static final StringTag DB_SQL = new StringTag("db.sql");
}
package com.a.eye.skywalking.trace;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by wusheng on 2017/2/18.
*/
public class TraceSegmentTestCase {
@Test
public void testConstructor(){
TraceSegment segment = new TraceSegment("trace_1");
Assert.assertEquals("trace_1", segment.getTraceSegmentId());
Assert.assertTrue(segment.getStartTime() > 0);
}
@Test
public void testRef(){
TraceSegment segment = new TraceSegment("trace_3");
TraceSegmentRef ref1 = new TraceSegmentRef();
ref1.setTraceSegmentId("parent_trace_0");
ref1.setSpanId(1);
segment.ref(ref1);
TraceSegmentRef ref2 = new TraceSegmentRef();
ref2.setTraceSegmentId("parent_trace_1");
ref2.setSpanId(5);
segment.ref(ref2);
TraceSegmentRef ref3 = new TraceSegmentRef();
ref3.setTraceSegmentId("parent_trace_1");
ref3.setSpanId(5);
segment.ref(ref3);
Assert.assertEquals(ref1, segment.getPrimaryRef());
Assert.assertEquals(ref2, segment.getRefs().get(0));
Assert.assertEquals(ref3, segment.getRefs().get(1));
}
@Test
public void testArchiveSpan(){
TraceSegment segment = new TraceSegment("trace_1");
Span span1 = new Span(1, "/serviceA");
segment.archive(span1);
Span span2 = new Span(2, "/db/sql");
segment.archive(span2);
Assert.assertEquals(span1, segment.getSpans().get(0));
Assert.assertEquals(span2, segment.getSpans().get(1));
}
@Test
public void testFinish(){
TraceSegment segment = new TraceSegment("trace_1");
Assert.assertTrue(segment.getEndTime() == 0);
segment.finish();
Assert.assertTrue(segment.getEndTime() > 0);
}
}
......@@ -19,19 +19,6 @@ public class Config {
public static int BUFFER_SIZE = 1024 * 4;
}
public static class BuriedPoint {
// 是否打印埋点信息
public static boolean PRINTF = false;
public static int MAX_EXCEPTION_STACK_LENGTH = 4000;
// Business Key 最大长度
public static int BUSINESSKEY_MAX_LENGTH = 300;
// 使用逗号分离
public static String EXCLUSIVE_EXCEPTIONS = "";
}
public static class Logging {
// log文件名
......
package com.a.eye.skywalking.context;
import com.a.eye.skywalking.queue.TraceSegmentProcessQueue;
import com.a.eye.skywalking.trace.Span;
import com.a.eye.skywalking.trace.TraceSegment;
/**
......@@ -10,6 +11,8 @@ import com.a.eye.skywalking.trace.TraceSegment;
*
* What is 'ChildOf'? {@see https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans}
*
* Also, {@link ContextManager} delegates to all {@link TracerContext}'s major methods: {@link
* TracerContext#createSpan(String)}, {@link TracerContext#activeSpan()}, {@link TracerContext#stopSpan(Span)}
*
* Created by wusheng on 2017/2/17.
*/
......@@ -35,4 +38,20 @@ public enum ContextManager implements TracerContextListener {
}
return segment;
}
public Span createSpan(String operationName) {
return get().createSpan(operationName);
}
public Span activeSpan() {
return get().activeSpan();
}
public void stopSpan(Span span) {
get().stopSpan(span);
}
public void stopSpan() {
stopSpan(activeSpan());
}
}
......@@ -11,6 +11,10 @@ import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.util.DaemonThreadFactory;
/**
* {@link TraceSegmentProcessQueue} is a proxy of {@link Disruptor}, High Performance Inter-Thread MQ.
*
* {@see https://github.com/LMAX-Exchange/disruptor}
*
* Created by wusheng on 2017/2/17.
*/
public enum TraceSegmentProcessQueue implements TracerContextListener {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册