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

Refactor code.

上级 6ac4b2d9
......@@ -23,51 +23,56 @@ public final class Tags {
public static final IntTag HTTP_STATUS = new IntTag("http.status_code");
/**
* SPAN_KIND represents the kind of span.
*
*/
public static final StringTag SPAN_KIND = new StringTag("span.kind");
/**
* SPAN_LAYER represents the kind of span.
* e.g. db=database, rpc=Remote Procedure Call, nosql=something like redis/memcache
*/
public static final class SPAN_KIND{
private static StringTag SPAN_KIND_TAG = new StringTag("span.kind");
public static final class SPAN_LAYER {
private static StringTag SPAN_LAYER_TAG = new StringTag("span.layer");
private static final String DB_KIND = "db";
private static final String RPC_KIND = "rpc";
private static final String NOSQL_KIND = "nosql";
private static final String HTTP_KIND = "http";
private static final String DB_LAYER = "db";
private static final String RPC_LAYER = "rpc";
private static final String NOSQL_LAYER = "nosql";
private static final String HTTP_LAYER = "http";
public static void asDBAccess(Span span){
SPAN_KIND_TAG.set(span, DB_KIND);
SPAN_LAYER_TAG.set(span, DB_LAYER);
}
public static void asRPC(Span span){
SPAN_KIND_TAG.set(span, RPC_KIND);
SPAN_LAYER_TAG.set(span, RPC_LAYER);
}
public static void asNoSQL(Span span){
SPAN_KIND_TAG.set(span, NOSQL_KIND);
SPAN_LAYER_TAG.set(span, NOSQL_LAYER);
}
public static void asHttp(Span span){
SPAN_KIND_TAG.set(span, HTTP_KIND);
SPAN_LAYER_TAG.set(span, HTTP_LAYER);
}
public static String get(Span span){
return SPAN_KIND_TAG.get(span);
return SPAN_LAYER_TAG.get(span);
}
public static boolean isDBAccess(Span span){
return DB_KIND.equals(get(span));
return DB_LAYER.equals(get(span));
}
public static boolean isRPC(Span span){
return RPC_KIND.equals(get(span));
return RPC_LAYER.equals(get(span));
}
public static boolean isNoSQL(Span span){
return NOSQL_KIND.equals(get(span));
return NOSQL_LAYER.equals(get(span));
}
public static boolean isHttp(Span span){
return HTTP_KIND.equals(get(span));
return HTTP_LAYER.equals(get(span));
}
}
......@@ -83,9 +88,9 @@ public final class Tags {
public static final BooleanTag ERROR = new BooleanTag("error");
/**
* PEER_HOST_IPV4 records IPv4 host address of the peer.
* PEER_HOST records host address of the peer, maybe IPV4, IPV6 or hostname.
*/
public static final IntTag PEER_HOST_IPV4 = new IntTag("peer.ipv4");
public static final StringTag PEER_HOST = new StringTag("peer.host");
/**
* DB_URL records the url of the database access.
......
package com.a.eye.skywalking.trace;
import com.a.eye.skywalking.trace.tag.Tags;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
......@@ -38,9 +37,9 @@ public class SpanTestCase {
@Test
public void testSetTag() {
Span span1 = new Span(0, "serviceA");
Tags.SPAN_KIND.asHttp(span1);
Tags.SPAN_LAYER.asHttp(span1);
Tags.COMPONENT.set(span1, "Spring");
Tags.PEER_HOST_IPV4.set(span1, ipToInt("127.0.0.1"));
Tags.PEER_HOST.set(span1, ipToInt("127.0.0.1"));
Tags.ERROR.set(span1, true);
Tags.HTTP_STATUS.set(span1, 302);
Tags.HTTP_URL.set(span1, "http://127.0.0.1/serviceA");
......@@ -49,8 +48,8 @@ public class SpanTestCase {
Map<String, Object> tags = span1.getTags();
Assert.assertEquals(8, tags.size());
Assert.assertTrue(Tags.SPAN_KIND.isHttp(span1));
Assert.assertEquals("127.0.0.1", intToIp(Tags.PEER_HOST_IPV4.get(span1)));
Assert.assertTrue(Tags.SPAN_LAYER.isHttp(span1));
Assert.assertEquals("127.0.0.1", intToIp(Tags.PEER_HOST.get(span1)));
Assert.assertTrue(Tags.ERROR.get(span1));
}
......
......@@ -3,6 +3,7 @@ package com.a.eye.skywalking.context;
import com.a.eye.skywalking.trace.Span;
import com.a.eye.skywalking.trace.TraceSegment;
import com.a.eye.skywalking.trace.tag.Tags;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
......@@ -24,4 +25,9 @@ public class ContextManagerTestCase {
Assert.assertEquals(span, segment.getSpans().get(0));
}
@After
public void reset(){
TracerContext.ListenerManager.remove(TestTracerContextListener.INSTANCE);
}
}
......@@ -17,7 +17,7 @@ public class PreparedStatementTracing {
throws SQLException {
Span span = ContextManager.INSTANCE.createSpan("JDBC/PreparedStatement/" + method);
try {
Tags.SPAN_KIND.asDBAccess(span);
Tags.SPAN_LAYER.asDBAccess(span);
Tags.DB_URL.set(span, connectInfo);
Tags.DB_SQL.set(span, sql);
return exec.exe(realStatement, sql);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册