* Otel-php:632 Move stack trace formatting out of Span class * added function usages * fix linting errors * Added documentation for adding Span Attributes * removing TracingUtl class * Refactor TraceState's __toString method
This commit is contained in:
parent
b2a7b62b2a
commit
06d74a737e
|
|
@ -50,7 +50,8 @@ interface SpanInterface extends ImplicitContextKeyedInterface
|
|||
|
||||
/**
|
||||
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-attributes
|
||||
*
|
||||
* Adding attributes at span creation is preferred to calling SetAttribute later, as samplers can only consider information
|
||||
* already present during span creation
|
||||
* @param non-empty-string $key
|
||||
* @param bool|int|float|string|array|null $value Note: the array MUST be homogeneous, i.e. it MUST NOT contain values of different types.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ declare(strict_types=1);
|
|||
namespace OpenTelemetry\API\Trace;
|
||||
|
||||
use function array_reverse;
|
||||
use function array_walk;
|
||||
use function implode;
|
||||
use function strlen;
|
||||
|
||||
class TraceState implements TraceStateInterface
|
||||
|
|
@ -97,23 +95,15 @@ class TraceState implements TraceStateInterface
|
|||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
if (!empty($this->traceState)) {
|
||||
$clonedTracestate = clone $this;
|
||||
|
||||
// Reverse the order back to the original to ensure new entries are at the beginning.
|
||||
$clonedTracestate->traceState = array_reverse($clonedTracestate->traceState);
|
||||
|
||||
array_walk(
|
||||
$clonedTracestate->traceState,
|
||||
static function (&$v, $k) {
|
||||
$v = $k . self::LIST_MEMBER_KEY_VALUE_SPLITTER . $v;
|
||||
}
|
||||
);
|
||||
|
||||
return implode(self::LIST_MEMBERS_SEPARATOR, $clonedTracestate->traceState);
|
||||
if (empty($this->traceState)) {
|
||||
return '';
|
||||
}
|
||||
$traceStateString='';
|
||||
foreach (array_reverse($this->traceState) as $k => $v) {
|
||||
$traceStateString .=$k . self::LIST_MEMBER_KEY_VALUE_SPLITTER . $v . self::LIST_MEMBERS_SEPARATOR;
|
||||
}
|
||||
|
||||
return '';
|
||||
return rtrim($traceStateString, ',');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue