vendor/sentry/sentry-symfony/src/Tracing/Doctrine/DBAL/TracingDriverConnectionFactory.php line 51

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 TracingDriverConnectionFactory implements TracingDriverConnectionFactoryInterface
  18. {
  19.     /**
  20.      * @var HubInterface The current hub
  21.      */
  22.     private $hub;
  23.     /**
  24.      * Constructor.
  25.      *
  26.      * @param HubInterface $hub The current hub
  27.      */
  28.     public function __construct(HubInterface $hub)
  29.     {
  30.         $this->hub $hub;
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function create(Connection $connectionAbstractPlatform $databasePlatform, array $params): TracingDriverConnectionInterface
  36.     {
  37.         $tracingDriverConnection = new TracingDriverConnection(
  38.             $this->hub,
  39.             $connection,
  40.             $this->getDatabasePlatform($databasePlatform),
  41.             $params
  42.         );
  43.         if ($connection instanceof ServerInfoAwareConnection) {
  44.             $tracingDriverConnection = new TracingServerInfoAwareDriverConnection($tracingDriverConnection);
  45.         }
  46.         return $tracingDriverConnection;
  47.     }
  48.     private function getDatabasePlatform(AbstractPlatform $databasePlatform): string
  49.     {
  50.         // https://github.com/open-telemetry/opentelemetry-specification/blob/33113489fb5a1b6da563abb4ffa541447b87f515/specification/trace/semantic_conventions/database.md#connection-level-attributes
  51.         switch (true) {
  52.             case $databasePlatform instanceof AbstractMySQLPlatform:
  53.                 return 'mysql';
  54.             case $databasePlatform instanceof DB2Platform:
  55.                 return 'db2';
  56.             case $databasePlatform instanceof OraclePlatform:
  57.                 return 'oracle';
  58.             case $databasePlatform instanceof PostgreSQLPlatform:
  59.                 return 'postgresql';
  60.             case $databasePlatform instanceof SqlitePlatform:
  61.                 return 'sqlite';
  62.             case $databasePlatform instanceof SQLServerPlatform:
  63.                 return 'mssql';
  64.             default:
  65.                 return 'other_sql';
  66.         }
  67.     }
  68. }