Skip to content

Commit

Permalink
change spanId toolkit api type (apache#6216)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanLjp authored Jan 16, 2021
1 parent cbfe7ee commit 020a995
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ public static String segmentId() {
}

/**
* 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface AbstractTracerContext {
*
* @return the string represents the id.
*/
String getSpanId();
int getSpanId();

/**
* Create an entry span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ private static AbstractTracerContext get() {
}

/**
* @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();
return Objects.nonNull(context) ? context.getReadablePrimaryTraceId() : EMPTY_TRACE_CONTEXT_ID;
}

/**
* @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();
return Objects.nonNull(context) ? context.getSegmentId() : EMPTY_TRACE_CONTEXT_ID;
}

/**
* @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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public String getSegmentId() {
}

@Override
public String getSpanId() {
return IGNORE_TRACE;
public int getSpanId() {
return -1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ public String getSegmentId() {
}

@Override
public String getSpanId() {
return String.valueOf(activeSpan().getSpanId());
public int getSpanId() {
return activeSpan().getSpanId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ public static String segmentId() {
}

/**
* 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public String toolKitCase() {
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;
Expand Down

0 comments on commit 020a995

Please sign in to comment.