Generate SpanId only for sampled spans
This commit is contained in:
parent
c90ae9a69d
commit
5b51eaed88
|
@ -196,7 +196,6 @@ final class SpanBuilderSdk implements Span.Builder {
|
||||||
public Span startSpan() {
|
public Span startSpan() {
|
||||||
SpanContext parentContext = parent(parentType, parent, remoteParent);
|
SpanContext parentContext = parent(parentType, parent, remoteParent);
|
||||||
TraceId traceId;
|
TraceId traceId;
|
||||||
SpanId spanId = idsGenerator.generateSpanId();
|
|
||||||
TraceState traceState = TraceState.getDefault();
|
TraceState traceState = TraceState.getDefault();
|
||||||
if (parentContext == null || !parentContext.isValid()) {
|
if (parentContext == null || !parentContext.isValid()) {
|
||||||
// New root span.
|
// New root span.
|
||||||
|
@ -225,12 +224,13 @@ final class SpanBuilderSdk implements Span.Builder {
|
||||||
.shouldSample(
|
.shouldSample(
|
||||||
parentContext, traceId, spanName, spanKind, immutableAttributes, immutableLinks);
|
parentContext, traceId, spanName, spanKind, immutableAttributes, immutableLinks);
|
||||||
|
|
||||||
SpanContext spanContext =
|
SpanId spanId = SpanId.getInvalid();
|
||||||
SpanContext.create(
|
TraceFlags traceFlags = TRACE_OPTIONS_NOT_SAMPLED;
|
||||||
traceId,
|
if (samplingDecision.isSampled()) {
|
||||||
spanId,
|
spanId = idsGenerator.generateSpanId();
|
||||||
samplingDecision.isSampled() ? TRACE_OPTIONS_SAMPLED : TRACE_OPTIONS_NOT_SAMPLED,
|
traceFlags = TRACE_OPTIONS_SAMPLED;
|
||||||
traceState);
|
}
|
||||||
|
SpanContext spanContext = SpanContext.create(traceId, spanId, traceFlags, traceState);
|
||||||
|
|
||||||
if (!samplingDecision.isSampled()) {
|
if (!samplingDecision.isSampled()) {
|
||||||
return DefaultSpan.create(spanContext);
|
return DefaultSpan.create(spanContext);
|
||||||
|
|
Loading…
Reference in New Issue