in agent/php/ElasticApm/Impl/HttpDistributedTracing.php [122:174]
public function parseHeadersImpl(
array $traceParentHeaderValues,
array $traceStateHeaderValues,
bool &$isTraceParentValid,
?bool &$isTraceStateValid
): ?DistributedTracingDataInternal {
$localLogger = $this->logger->inherit()->addAllContext(
[
'traceParentHeaderValues' => $traceParentHeaderValues,
'traceStateHeaderValues' => $traceStateHeaderValues
]
);
if (count($traceParentHeaderValues) === 0) {
($loggerProxy = $localLogger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log(
'Found no ' . self::TRACE_PARENT_HEADER_NAME . ' HTTP header so there is nothing to parse'
);
$isTraceParentValid = false;
$isTraceStateValid = null;
return null;
}
if (count($traceParentHeaderValues) > 1) {
($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log(
'Found more than one ' . self::TRACE_PARENT_HEADER_NAME . ' HTTP header which is invalid'
);
$isTraceParentValid = false;
$isTraceStateValid = null;
return null;
}
/**
* @link https://www.w3.org/TR/trace-context/#tracestate-header
*
* If the vendor failed to parse traceparent, it MUST NOT attempt to parse tracestate.
* Note that the opposite is not true: failure to parse tracestate MUST NOT affect the parsing of traceparent.
*/
$isTraceParentValid = ($result = $this->parseTraceParentHeader($traceParentHeaderValues[0])) !== null;
if (!$isTraceParentValid) {
$isTraceStateValid = null;
return null;
}
/** @var DistributedTracingDataInternal $result */
if (ArrayUtil::isEmpty($traceStateHeaderValues)) {
$isTraceStateValid = null;
} else {
$isTraceStateValid = $this->parseTraceStateHeaders($traceStateHeaderValues, $result);
}
return $result;
}