Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TraceState.php

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

TraceState

Namespace

OpenTelemetry\API\Trace

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal