change spanId toolkit api type (#6216)

This commit is contained in:
Evan 2021-01-16 15:40:48 +08:00 committed by GitHub
parent cbfe7ee87c
commit 020a995301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 17 deletions

View File

@ -46,12 +46,13 @@ public class TraceContext {
}
/**
* Try to get the spanId of current trace context.
* Try to get the spanId of current trace context. The spanId is a negative number when the trace context is
* missing.
*
* @return spanId, if it exists, or empty {@link String}.
*/
public static String spanId() {
return "";
public static int spanId() {
return -1;
}
/**

View File

@ -74,7 +74,7 @@ public interface AbstractTracerContext {
*
* @return the string represents the id.
*/
String getSpanId();
int getSpanId();
/**
* Create an entry span

View File

@ -70,7 +70,7 @@ public class ContextManager implements BootService {
}
/**
* @return the first global trace id if needEnhance. Otherwise, "N/A".
* @return the first global trace id when tracing. Otherwise, "N/A".
*/
public static String getGlobalTraceId() {
AbstractTracerContext context = CONTEXT.get();
@ -78,7 +78,7 @@ public class ContextManager implements BootService {
}
/**
* @return the current segment id if needEnhance. Otherwise, "N/A".
* @return the current segment id when tracing. Otherwise, "N/A".
*/
public static String getSegmentId() {
AbstractTracerContext context = CONTEXT.get();
@ -86,11 +86,11 @@ public class ContextManager implements BootService {
}
/**
* @return the current span id if needEnhance. Otherwise, "N/A".
* @return the current span id when tracing. Otherwise, the value is -1.
*/
public static String getSpanId() {
public static int getSpanId() {
AbstractTracerContext context = CONTEXT.get();
return Objects.nonNull(context) ? context.getSpanId() : EMPTY_TRACE_CONTEXT_ID;
return Objects.nonNull(context) ? context.getSpanId() : -1;
}
public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) {

View File

@ -75,8 +75,8 @@ public class IgnoredTracerContext implements AbstractTracerContext {
}
@Override
public String getSpanId() {
return IGNORE_TRACE;
public int getSpanId() {
return -1;
}
@Override

View File

@ -249,8 +249,8 @@ public class TracingContext implements AbstractTracerContext {
}
@Override
public String getSpanId() {
return String.valueOf(activeSpan().getSpanId());
public int getSpanId() {
return activeSpan().getSpanId();
}
/**

View File

@ -46,12 +46,13 @@ public class TraceContext {
}
/**
* Try to get the spanId of current trace context.
* Try to get the spanId of current trace context. The spanId is a negative number when the trace context is
* missing.
*
* @return spanId, if it exists, or empty {@link String}.
*/
public static String spanId() {
return "";
public static int spanId() {
return -1;
}
/**

View File

@ -61,7 +61,9 @@ public class TestController {
TraceContext.putCorrelation(CORRELATION_CONTEXT_KEY, CORRELATION_CONTEXT_VALUE);
ActiveSpan.tag("traceID", TraceContext.traceId());
ActiveSpan.tag("segmentID", TraceContext.segmentId());
ActiveSpan.tag("spanID", TraceContext.spanId());
if (TraceContext.spanId() > -1) {
ActiveSpan.tag("spanID", String.valueOf(TraceContext.spanId()));
}
testService.asyncCallable(() -> {
visit("http://localhost:8080/apm-toolkit-trace-scenario/case/asyncVisit/callable");
return true;