vendor/sentry/sentry-symfony/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactoryForV2V3.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\Tracing\Doctrine\DBAL;
  4. use Doctrine\DBAL\Driver\Connection;
  5. use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
  6. use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
  7. use Doctrine\DBAL\Platforms\AbstractPlatform;
  8. use Doctrine\DBAL\Platforms\DB2Platform;
  9. use Doctrine\DBAL\Platforms\OraclePlatform;
  10. use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
  11. use Doctrine\DBAL\Platforms\SqlitePlatform;
  12. use Doctrine\DBAL\Platforms\SQLServerPlatform;
  13. use Sentry\State\HubInterface;
  14. /**
  15.  * @internal
  16.  */
  17. final class TracingDriverConnectionFactoryForV2V3 implements TracingDriverConnectionFactoryInterface
  18. {
  19.     /**
  20.      * @var HubInterface The current hub
  21.      */
  22.     private $hub;
  23.     /**
  24.      * @var bool Whether prepare spans should be ignored
  25.      */
  26.     private $ignorePrepareSpans;
  27.     /**
  28.      * Constructor.
  29.      *
  30.      * @param HubInterface $hub                The current hub
  31.      * @param bool         $ignorePrepareSpans Whether prepare spans should be ignored
  32.      */
  33.     public function __construct(HubInterface $hubbool $ignorePrepareSpans false)
  34.     {
  35.         $this->hub $hub;
  36.         $this->ignorePrepareSpans $ignorePrepareSpans;
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function create(Connection $connectionAbstractPlatform $databasePlatform, array $params): TracingDriverConnectionInterface
  42.     {
  43.         $tracingDriverConnection = new TracingDriverConnection(
  44.             $this->hub,
  45.             $connection,
  46.             $this->getDatabasePlatform($databasePlatform),
  47.             $params,
  48.             $this->ignorePrepareSpans
  49.         );
  50.         if ($connection instanceof ServerInfoAwareConnection) {
  51.             $tracingDriverConnection = new TracingServerInfoAwareDriverConnection($tracingDriverConnection);
  52.         }
  53.         return $tracingDriverConnection;
  54.     }
  55.     private function getDatabasePlatform(AbstractPlatform $databasePlatform): string
  56.     {
  57.         // https://github.com/open-telemetry/opentelemetry-specification/blob/33113489fb5a1b6da563abb4ffa541447b87f515/specification/trace/semantic_conventions/database.md#connection-level-attributes
  58.         switch (true) {
  59.             case $databasePlatform instanceof AbstractMySQLPlatform:
  60.                 return 'mysql';
  61.             case $databasePlatform instanceof DB2Platform:
  62.                 return 'db2';
  63.             case $databasePlatform instanceof OraclePlatform:
  64.                 return 'oracle';
  65.             case $databasePlatform instanceof PostgreSQLPlatform:
  66.                 return 'postgresql';
  67.             case $databasePlatform instanceof SqlitePlatform:
  68.                 return 'sqlite';
  69.             case $databasePlatform instanceof SQLServerPlatform:
  70.                 return 'mssql';
  71.             default:
  72.                 return 'other_sql';
  73.         }
  74.     }
  75. }