解决跨域levelId的问题
This commit is contained in:
parent
b3827e7763
commit
ce5544228e
|
|
@ -2,22 +2,37 @@ package com.ai.cloud.skywalking.api;
|
|||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
public class Tracing {
|
||||
/**
|
||||
* 获取当前上下文中的TraceId
|
||||
* @return
|
||||
*/
|
||||
public static String getTraceId(){
|
||||
if (!AuthDesc.isAuth())
|
||||
/**
|
||||
* 获取当前上下文中的TraceId
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getTraceId() {
|
||||
if (!AuthDesc.isAuth())
|
||||
return "";
|
||||
|
||||
Span spanData = Context.getLastSpan();
|
||||
if (spanData == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
return spanData.getTraceId();
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateNextContextData(){
|
||||
if (!AuthDesc.isAuth())
|
||||
return null;
|
||||
|
||||
Span spanData = Context.getLastSpan();
|
||||
if (spanData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ContextData contextData = new ContextData(spanData);
|
||||
return contextData.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ public class Context {
|
|||
|
||||
static class SpanNode {
|
||||
private Span data;
|
||||
//
|
||||
private int nextSubSpanLevelId = 0;
|
||||
|
||||
public SpanNode(Span data) {
|
||||
this.data = data;
|
||||
this.data.setLevelId(nextSubSpanLevelId);
|
||||
}
|
||||
|
||||
public SpanNode(Span data, int levelId) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.ai.cloud.skywalking.protocol.Span;
|
|||
public class ContextData {
|
||||
private String traceId;
|
||||
private String parentLevel;
|
||||
private long levelId;
|
||||
private int levelId;
|
||||
private char spanType;
|
||||
|
||||
ContextData() {
|
||||
|
|
@ -19,14 +19,15 @@ public class ContextData {
|
|||
this.levelId = span.getLevelId();
|
||||
this.spanType = span.getSpanType();
|
||||
}
|
||||
|
||||
public ContextData(String contextDataStr){
|
||||
// 反序列化参数
|
||||
|
||||
public ContextData(String contextDataStr) {
|
||||
// 反序列化参数
|
||||
String[] value = contextDataStr.split("-");
|
||||
Span span = new Span(value[0]);
|
||||
span.setParentLevel(value[1]);
|
||||
span.setLevelId(Integer.valueOf(value[2]));
|
||||
span.setSpanType(value[3].charAt(0));
|
||||
this.traceId = value[0];
|
||||
this.parentLevel = value[1];
|
||||
this.levelId = Integer.valueOf(value[2]);
|
||||
this.spanType = value[3].charAt(0);
|
||||
|
||||
}
|
||||
|
||||
public String getTraceId() {
|
||||
|
|
@ -37,7 +38,7 @@ public class ContextData {
|
|||
return parentLevel;
|
||||
}
|
||||
|
||||
public long getLevelId() {
|
||||
public int getLevelId() {
|
||||
return levelId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,10 +34,9 @@ public final class ContextGenerator {
|
|||
spanData = new Span(TraceIdGenerator.generate(), Config.SkyWalking.APPLICATION_ID);
|
||||
} else {
|
||||
// 如果不为空,则将当前的Context存放到上下文
|
||||
// LevelId是由SpanNode类的nextSubSpanLevelId字段进行初始化的.
|
||||
// 所以在这里不需要初始化
|
||||
spanData = new Span(context.getTraceId(), Config.SkyWalking.APPLICATION_ID);
|
||||
spanData.setParentLevel(context.getParentLevel());
|
||||
spanData.setLevelId(context.getLevelId());
|
||||
}
|
||||
initNewSpanData(spanData, id);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue