PHP code example of otaodev / opentelemetrytracer

1. Go to this page and download the library: Download otaodev/opentelemetrytracer 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/ */

    

otaodev / opentelemetrytracer example snippets




namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Otaodev\Opentelemetrytracer\Attribute\TraceRoute;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

#[Route('/', name: 'default_')]
class DefaultController extends AbstractController
{

    #[Route('/healthcheck', methods: ['GET'])]
    #[TraceRoute('any_route_name')]
    public function index(): Response
    {
        $return = $this->json('black tests is ON!');

        return $return;
    }
}
environment
OTEL_PHP_AUTOLOAD_ENABLED=true
OTEL_SERVICE_NAME=YourServiceAppName
OTEL_TRACES_EXPORTER=console
OTEL_METRICS_EXPORTER=none
OTEL_LOGS_EXPORTER=none

OTEL_PROPAGATORS=baggage,tracecontext
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
OTEL_EXPORTER_OTLP_ENDPOINT="http://the-collector-ip:4317"