save the already known state of SpanContext validity (#2769)
This commit is contained in:
parent
0bd4ddc9a0
commit
8898e4c441
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.api.trace;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.auto.value.extension.memoized.Memoized;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
|
|
@ -19,12 +18,18 @@ abstract class ImmutableSpanContext implements SpanContext {
|
|||
SpanId.getInvalid(),
|
||||
TraceFlags.getDefault(),
|
||||
TraceState.getDefault(),
|
||||
/* remote= */ false);
|
||||
/* remote= */ false,
|
||||
/* valid= */ false);
|
||||
|
||||
private static AutoValue_ImmutableSpanContext createInternal(
|
||||
String traceId, String spanId, TraceFlags traceFlags, TraceState traceState, boolean remote) {
|
||||
String traceId,
|
||||
String spanId,
|
||||
TraceFlags traceFlags,
|
||||
TraceState traceState,
|
||||
boolean remote,
|
||||
boolean valid) {
|
||||
return new AutoValue_ImmutableSpanContext(
|
||||
traceId, spanId, traceFlags, traceState, /* remote$= */ remote);
|
||||
traceId, spanId, traceFlags, traceState, remote, valid);
|
||||
}
|
||||
|
||||
static SpanContext create(
|
||||
|
|
@ -34,15 +39,18 @@ abstract class ImmutableSpanContext implements SpanContext {
|
|||
TraceState traceState,
|
||||
boolean remote) {
|
||||
if (SpanId.isValid(spanIdHex) && TraceId.isValid(traceIdHex)) {
|
||||
return createInternal(traceIdHex, spanIdHex, traceFlags, traceState, remote);
|
||||
return createInternal(
|
||||
traceIdHex, spanIdHex, traceFlags, traceState, remote, /* valid= */ true);
|
||||
}
|
||||
return createInternal(
|
||||
TraceId.getInvalid(), SpanId.getInvalid(), traceFlags, traceState, remote);
|
||||
TraceId.getInvalid(),
|
||||
SpanId.getInvalid(),
|
||||
traceFlags,
|
||||
traceState,
|
||||
remote,
|
||||
/* valid= */ false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Memoized
|
||||
public boolean isValid() {
|
||||
return SpanContext.super.isValid();
|
||||
}
|
||||
public abstract boolean isValid();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -906,12 +906,12 @@ class SdkSpanBuilderTest {
|
|||
+ "traceId=[0-9a-f]{32}, "
|
||||
+ "spanId=[0-9a-f]{16}, "
|
||||
+ "traceFlags=01, "
|
||||
+ "traceState=ArrayBasedTraceState\\{entries=\\[]}, remote=false}, "
|
||||
+ "traceState=ArrayBasedTraceState\\{entries=\\[]}, remote=false, valid=true}, "
|
||||
+ "parentSpanContext=ImmutableSpanContext\\{"
|
||||
+ "traceId=00000000000000000000000000000000, "
|
||||
+ "spanId=0000000000000000, "
|
||||
+ "traceFlags=00, "
|
||||
+ "traceState=ArrayBasedTraceState\\{entries=\\[]}, remote=false}, "
|
||||
+ "traceState=ArrayBasedTraceState\\{entries=\\[]}, remote=false, valid=false}, "
|
||||
+ "resource=Resource\\{attributes=\\{service.name=\"unknown_service:java\", "
|
||||
+ "telemetry.sdk.language=\"java\", telemetry.sdk.name=\"opentelemetry\", "
|
||||
+ "telemetry.sdk.version=\"\\d+.\\d+.\\d+(-SNAPSHOT)?\"}}, "
|
||||
|
|
|
|||
Loading…
Reference in New Issue