vendor/sentry/sentry-symfony/src/Tracing/Doctrine/DBAL/AbstractTracingStatement.php line 77

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\Tracing\Doctrine\DBAL;
  4. use Doctrine\DBAL\Driver\Statement;
  5. use Sentry\State\HubInterface;
  6. use Sentry\Tracing\Span;
  7. use Sentry\Tracing\SpanContext;
  8. abstract class AbstractTracingStatement
  9. {
  10.     /**
  11.      * @internal
  12.      */
  13.     public const SPAN_OP_STMT_EXECUTE 'db.sql.execute';
  14.     /**
  15.      * @var HubInterface The current hub
  16.      */
  17.     protected $hub;
  18.     /**
  19.      * @var Statement The decorated statement
  20.      */
  21.     protected $decoratedStatement;
  22.     /**
  23.      * @var string The SQL query executed by the decorated statement
  24.      */
  25.     protected $sqlQuery;
  26.     /**
  27.      * @var array<string, string> The span tags
  28.      */
  29.     protected $spanTags;
  30.     /**
  31.      * Constructor.
  32.      *
  33.      * @param HubInterface          $hub                The current hub
  34.      * @param Statement             $decoratedStatement The decorated statement
  35.      * @param string                $sqlQuery           The SQL query executed by the decorated statement
  36.      * @param array<string, string> $spanTags           The span tags
  37.      */
  38.     public function __construct(HubInterface $hubStatement $decoratedStatementstring $sqlQuery, array $spanTags)
  39.     {
  40.         $this->hub $hub;
  41.         $this->decoratedStatement $decoratedStatement;
  42.         $this->sqlQuery $sqlQuery;
  43.         $this->spanTags $spanTags;
  44.     }
  45.     /**
  46.      * Calls the given callback by passing to it the specified arguments and
  47.      * wrapping its execution into a child {@see Span} of the current one.
  48.      *
  49.      * @param callable $callback The function to call
  50.      * @param mixed    ...$args  The arguments to pass to the callback
  51.      *
  52.      * @phpstan-template T
  53.      *
  54.      * @phpstan-param callable(mixed...): T $callback
  55.      *
  56.      * @phpstan-return T
  57.      */
  58.     protected function traceFunction(SpanContext $spanContext, callable $callback, ...$args)
  59.     {
  60.         $span $this->hub->getSpan();
  61.         if (null !== $span) {
  62.             $span $span->startChild($spanContext);
  63.         }
  64.         try {
  65.             return $callback(...$args);
  66.         } finally {
  67.             if (null !== $span) {
  68.                 $span->finish();
  69.             }
  70.         }
  71.     }
  72. }