vendor/sentry/sentry-symfony/src/Twig/SentryExtension.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\Twig;
  4. use Sentry\State\HubInterface;
  5. use Twig\Extension\AbstractExtension;
  6. use Twig\TwigFunction;
  7. use function Sentry\getBaggage;
  8. use function Sentry\getTraceparent;
  9. final class SentryExtension extends AbstractExtension
  10. {
  11. /**
  12. * @param HubInterface $hub The current hub
  13. */
  14. public function __construct(HubInterface $hub = null)
  15. {
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getFunctions(): array
  21. {
  22. return [
  23. new TwigFunction('sentry_trace_meta', [$this, 'getTraceMeta'], ['is_safe' => ['html']]),
  24. new TwigFunction('sentry_baggage_meta', [$this, 'getBaggageMeta'], ['is_safe' => ['html']]),
  25. ];
  26. }
  27. /**
  28. * Returns an HTML meta tag named `sentry-trace`.
  29. */
  30. public function getTraceMeta(): string
  31. {
  32. return sprintf('<meta name="sentry-trace" content="%s" />', getTraceparent());
  33. }
  34. /**
  35. * Returns an HTML meta tag named `baggage`.
  36. */
  37. public function getBaggageMeta(): string
  38. {
  39. return sprintf('<meta name="baggage" content="%s" />', getBaggage());
  40. }
  41. }