function TraceState::toString
Overrides TraceStateInterface::toString
1 call to TraceState::toString()
- TraceState::__toString in vendor/
open-telemetry/ api/ Trace/ TraceState.php - Returns a string representation of this TraceSate
File
-
vendor/
open-telemetry/ api/ Trace/ TraceState.php, line 77
Class
Namespace
OpenTelemetry\API\TraceCode
public function toString(?int $limit = null) : string {
$traceState = $this->traceState;
if ($limit !== null) {
$length = 0;
foreach ($traceState as $key => $value) {
$length && ($length += 1);
$length += strlen($key) + 1 + strlen($value);
}
if ($length > $limit) {
// Entries larger than 128 characters long SHOULD be removed first.
foreach ([
128,
0,
] as $threshold) {
// Then entries SHOULD be removed starting from the end of tracestate.
for ($value = end($traceState); $key = key($traceState);) {
$entry = strlen($key) + 1 + strlen($value);
$value = prev($traceState);
if ($entry <= $threshold) {
continue;
}
unset($traceState[$key]);
if (($length -= $entry + 1) <= $limit) {
break 2;
}
}
}
}
}
$s = '';
foreach ($traceState as $key => $value) {
$s && ($s .= ',');
$s .= $key;
$s .= '=';
$s .= $value;
}
return $s;
}