Alter SPAN_KIND. Add test case to span.
This commit is contained in:
parent
a31ff52b3e
commit
7e640311ce
|
|
@ -1,5 +1,6 @@
|
|||
package com.a.eye.skywalking.trace;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -21,6 +22,6 @@ public class LogData {
|
|||
}
|
||||
|
||||
public Map<String, ?> getFields() {
|
||||
return fields;
|
||||
return Collections.unmodifiableMap(fields);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,19 +12,8 @@ import java.util.Map;
|
|||
* Span is a concept from OpenTracing Spec, also from Google Dapper Paper.
|
||||
* Traces in OpenTracing are defined implicitly by their Spans.
|
||||
*
|
||||
* [Span A] ←←←(the root span)
|
||||
* |
|
||||
* +------+------+
|
||||
* | |
|
||||
* [Span B] [Span C] ←←←(Span C is a `ChildOf` Span A)
|
||||
* | |
|
||||
* [Span D] +---+-------+
|
||||
* | |
|
||||
* [Span E] [Span F] >>> [Span G] >>> [Span H]
|
||||
* ↑
|
||||
* ↑
|
||||
* ↑
|
||||
* (Span G `FollowsFrom` Span F)
|
||||
* Know more things about span concept:
|
||||
* {@see https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model}
|
||||
*
|
||||
* Created by wusheng on 2017/2/17.
|
||||
*/
|
||||
|
|
@ -192,9 +181,7 @@ public class Span {
|
|||
exceptionFields.put("message", t.getMessage());
|
||||
exceptionFields.put("stack", ThrowableTransformer.INSTANCE.convert2String(t, 4000));
|
||||
|
||||
logs.add(new LogData(System.currentTimeMillis(), exceptionFields));
|
||||
|
||||
return this;
|
||||
return log(exceptionFields);
|
||||
}
|
||||
|
||||
private enum ThrowableTransformer {
|
||||
|
|
|
|||
|
|
@ -29,20 +29,45 @@ public final class Tags {
|
|||
public static final class SPAN_KIND{
|
||||
private static StringTag SPAN_KIND_TAG = new StringTag("span.kind");
|
||||
|
||||
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";
|
||||
|
||||
public static void asDBAccess(Span span){
|
||||
SPAN_KIND_TAG.set(span, "db");
|
||||
SPAN_KIND_TAG.set(span, DB_KIND);
|
||||
}
|
||||
|
||||
public static void asRPC(Span span){
|
||||
SPAN_KIND_TAG.set(span, "rpc");
|
||||
SPAN_KIND_TAG.set(span, RPC_KIND);
|
||||
}
|
||||
|
||||
public static void asNoSQL(Span span){
|
||||
SPAN_KIND_TAG.set(span, "nosql");
|
||||
SPAN_KIND_TAG.set(span, NOSQL_KIND);
|
||||
}
|
||||
|
||||
public static void asHttp(Span span){
|
||||
SPAN_KIND_TAG.set(span, "http");
|
||||
SPAN_KIND_TAG.set(span, HTTP_KIND);
|
||||
}
|
||||
|
||||
public static String get(Span span){
|
||||
return SPAN_KIND_TAG.get(span);
|
||||
}
|
||||
|
||||
public static boolean isDBAccess(Span span){
|
||||
return DB_KIND.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isRPC(Span span){
|
||||
return RPC_KIND.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isNoSQL(Span span){
|
||||
return NOSQL_KIND.equals(get(span));
|
||||
}
|
||||
|
||||
public static boolean isHttp(Span span){
|
||||
return HTTP_KIND.equals(get(span));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ 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;
|
||||
import org.junit.Test;
|
||||
|
|
@ -37,7 +38,7 @@ public class SpanTestCase {
|
|||
@Test
|
||||
public void testSetTag() {
|
||||
Span span1 = new Span(0, "serviceA");
|
||||
Tags.SPAN_KIND.set(span1, "client");
|
||||
Tags.SPAN_KIND.asHttp(span1);
|
||||
Tags.COMPONENT.set(span1, "Spring");
|
||||
Tags.PEER_HOST_IPV4.set(span1, ipToInt("127.0.0.1"));
|
||||
Tags.ERROR.set(span1, true);
|
||||
|
|
@ -48,7 +49,7 @@ public class SpanTestCase {
|
|||
|
||||
Map<String, Object> tags = span1.getTags();
|
||||
Assert.assertEquals(8, tags.size());
|
||||
Assert.assertEquals("client", Tags.SPAN_KIND.get(span1));
|
||||
Assert.assertTrue(Tags.SPAN_KIND.isHttp(span1));
|
||||
Assert.assertEquals("127.0.0.1", intToIp(Tags.PEER_HOST_IPV4.get(span1)));
|
||||
Assert.assertTrue(Tags.ERROR.get(span1));
|
||||
}
|
||||
|
|
@ -82,4 +83,16 @@ public class SpanTestCase {
|
|||
sb.append(String.valueOf((longIp & 0x000000FF)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogException(){
|
||||
Span span1 = new Span(0, "serviceA");
|
||||
Exception exp = new Exception("exception msg");
|
||||
span1.log(exp);
|
||||
List<LogData> logs = span1.getLogs();
|
||||
|
||||
Assert.assertEquals("java.lang.Exception", logs.get(0).getFields().get("error.kind"));
|
||||
Assert.assertEquals("exception msg", logs.get(0).getFields().get("message"));
|
||||
Assert.assertNotNull(logs.get(0).getFields().get("stack"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue