function SpanBuilder::startSpan
@inheritDoc
File
-
vendor/
open-telemetry/ sdk/ Trace/ SpanBuilder.php, line 115
Class
Namespace
OpenTelemetry\SDK\TraceCode
public function startSpan() : API\SpanInterface {
$parentContext = Context::resolve($this->parentContext);
$parentSpan = Span::fromContext($parentContext);
$parentSpanContext = $parentSpan->getContext();
$spanId = $this->tracerSharedState
->getIdGenerator()
->generateSpanId();
if (!$parentSpanContext->isValid()) {
$traceId = $this->tracerSharedState
->getIdGenerator()
->generateTraceId();
}
else {
$traceId = $parentSpanContext->getTraceId();
}
$samplingResult = $this->tracerSharedState
->getSampler()
->shouldSample($parentContext, $traceId, $this->spanName, $this->spanKind, $this->attributesBuilder
->build(), $this->links);
$samplingDecision = $samplingResult->getDecision();
$samplingResultTraceState = $samplingResult->getTraceState();
$spanContext = API\SpanContext::create($traceId, $spanId, SamplingResult::RECORD_AND_SAMPLE === $samplingDecision ? API\TraceFlags::SAMPLED : API\TraceFlags::DEFAULT, $samplingResultTraceState);
if (!in_array($samplingDecision, [
SamplingResult::RECORD_AND_SAMPLE,
SamplingResult::RECORD_ONLY,
], true)) {
return Span::wrap($spanContext);
}
$attributesBuilder = clone $this->attributesBuilder;
foreach ($samplingResult->getAttributes() as $key => $value) {
$attributesBuilder[$key] = $value;
}
return Span::startSpan($this->spanName, $spanContext, $this->instrumentationScope, $this->spanKind, $parentSpan, $parentContext, $this->tracerSharedState
->getSpanLimits(), $this->tracerSharedState
->getSpanProcessor(), $this->tracerSharedState
->getResource(), $attributesBuilder, $this->links, $this->totalNumberOfLinksAdded, $this->startEpochNanos);
}