PHP code example of open-telemetry / opentelemetry-propagation-server-timing

1. Go to this page and download the library: Download open-telemetry/opentelemetry-propagation-server-timing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

open-telemetry / opentelemetry-propagation-server-timing example snippets


// your framework probably provides a datastructure to model HTTP responses
// and allows you to hook into the end of a request / listen to a matching event.
$response = new Response();

// get the current scope, bail out if none
$scope = Context::storage()->scope();
if (null === $scope) {
    return;
}

// create a PropagationSetterInterface that knows how to inject response headers
$propagationSetter = new class implements OpenTelemetry\Context\Propagation\PropagationSetterInterface {
    public function set(&$carrier, string $key, string $value) : void {
        $carrier->headers->set($key, $value);
    }
};
$propagator = new ServerTimingPropagator();
$propagator->inject($response, $propagationSetter, $scope->context());