otaodev / opentelemetrytracer
A basic use for the opentelemetry tracer in php applications
Installs: 1 277
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.2
- ext-grpc: *
- ext-opentelemetry: *
- open-telemetry/api: ^1.0
- open-telemetry/exporter-otlp: ^1.0
- open-telemetry/sdk: ^1.0
- open-telemetry/sem-conv: ^1.24
- open-telemetry/transport-grpc: ^1.0
- symfony/http-kernel: ^6.0
Requires (Dev)
- phpro/grumphp: ^2.5
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.9
README
A basic use for the opentelemetry tracer in php applications based in symfony framework
Instalation
composer require otaodev/opentelemetrytracer
Add the snippet to your app/config/services.yaml
services: Otaodev\Opentelemetrytracer\EventListener\TraceRouteListener: public: true autowire: true autoconfigure: true
Add the environments variables to your .env file
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"
Utilization
use the php8 attribute #[TraceRoute()] in your desired route, for example:
<?php 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; } }
NOTE
If you not pass a name, the TraceRouter will assume the method name.