PHP code example of affordablemobiles / open-telemetry-operations-php
1. Go to this page and download the library: Download affordablemobiles/open-telemetry-operations-php 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/ */
affordablemobiles / open-telemetry-operations-php example snippets
use AffordableMobiles\GServerlessSupportLaravel\Trace\Propagator\CloudTracePropagator;
use AffordableMobiles\OpenTelemetry\CloudTrace\SpanExporterFactory;
use OpenTelemetry\SDK\Sdk;
use OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler;
use OpenTelemetry\SDK\Trace\Sampler\ParentBased;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProviderBuilder;
$propagator = CloudTracePropagator::getInstance();
$spanProcessor = new SimpleSpanProcessor(
(new SpanExporterFactory())->create(),
);
$sampler = new ParentBased(
new AlwaysOnSampler(),
);
$tracerProvider = (new TracerProviderBuilder())
->addSpanProcessor($spanProcessor)
->setSampler($sampler)
->build()
;
Sdk::builder()
->setTracerProvider($tracerProvider)
->setPropagator($propagator)
->setAutoShutdown(true)
->buildAndRegisterGlobal()
;