Something went wrong. Try again.
Something went wrong. Try again.
1.5 kB · 47 lines
PHP
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<?php
namespace App\Controller;
use Beberlei\Metrics\Collector\CollectorInterface;use OpenTelemetry\API\Trace\TracerProviderInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController{ public function __construct( private readonly CollectorInterface $metrics, private readonly TracerProviderInterface $tracerProvider, ) { }
#[Route('/', name: 'home')] public function index(): Response { // Metric names are dot-separated and read broadest first: // <area>.<thing>.<event>. The collector's "namespace" setting is the // OpenTelemetry instrumentation scope, not a prefix, so the name // exported here is exactly this one. $this->metrics->increment('home.page.viewed');
// Span names are "<verb> <object>", lowercase verb, no punctuation. // The framework span for this request already exists; this one nests // inside it and should describe work worth seeing on its own. $span = $this->tracerProvider ->getTracer('app') ->spanBuilder('render homepage') ->startSpan() ;
try { return $this->render('home/index.html.twig'); } catch (\Throwable $e) { $span->recordException($e);
throw $e; } finally { $span->end(); } }}