use of io.opencensus.implcore.internal.TimestampConverter in project instrumentation-java by census-instrumentation.
the class SpanBuilderImpl method startSpanInternal.
private Span startSpanInternal(@Nullable SpanContext parentContext, @Nullable Boolean hasRemoteParent, String name, @Nullable Sampler sampler, List<Span> parentLinks, @Nullable Boolean recordEvents, @Nullable Kind kind, @Nullable Span parentSpan) {
TraceParams activeTraceParams = options.traceConfig.getActiveTraceParams();
Random random = options.randomHandler.current();
TraceId traceId;
SpanId spanId = SpanId.generateRandomId(random);
SpanId parentSpanId = null;
// TODO(bdrutu): Handle tracestate correctly not just propagate.
Tracestate tracestate = TRACESTATE_DEFAULT;
if (parentContext == null || !parentContext.isValid()) {
// New root span.
traceId = TraceId.generateRandomId(random);
// This is a root span so no remote or local parent.
hasRemoteParent = null;
} else {
// New child span.
traceId = parentContext.getTraceId();
parentSpanId = parentContext.getSpanId();
tracestate = parentContext.getTracestate();
}
TraceOptions traceOptions = makeSamplingDecision(parentContext, hasRemoteParent, name, sampler, parentLinks, traceId, spanId, activeTraceParams) ? SAMPLED_TRACE_OPTIONS : NOT_SAMPLED_TRACE_OPTIONS;
if (traceOptions.isSampled() || Boolean.TRUE.equals(recordEvents)) {
// Pass the timestamp converter from the parent to ensure that the recorded events are in
// the right order. Implementation uses System.nanoTime() which is monotonically increasing.
TimestampConverter timestampConverter = null;
if (parentSpan instanceof RecordEventsSpanImpl) {
RecordEventsSpanImpl parentRecordEventsSpan = (RecordEventsSpanImpl) parentSpan;
timestampConverter = parentRecordEventsSpan.getTimestampConverter();
parentRecordEventsSpan.addChild();
}
Span span = RecordEventsSpanImpl.startSpan(SpanContext.create(traceId, spanId, traceOptions, tracestate), name, kind, parentSpanId, hasRemoteParent, activeTraceParams, options.startEndHandler, timestampConverter, options.clock);
linkSpans(span, parentLinks);
return span;
} else {
return NoRecordEventsSpanImpl.create(SpanContext.create(traceId, spanId, traceOptions, tracestate));
}
}
Aggregations