in agent/php/ElasticApm/Impl/AutoInstrument/Util/DbConnectionStringParser.php [55:144]
public function parse(string $dbConnectionString, ?string &$dbType, ?string &$dbName): void
{
$localLogger = $this->logger->inherit()->addContext(
'dbConnectionString',
$this->logger->possiblySecuritySensitive($dbConnectionString)
);
$dbType = null;
$dbName = null;
$dbTypePrefix = '';
$posAfterDbTypePrefix = 0;
$isDbTypePrefixFound = self::extractDbTypePrefix(
$dbConnectionString,
/* ref */ $dbTypePrefix,
/* ref */ $posAfterDbTypePrefix,
$localLogger
);
if (!$isDbTypePrefixFound) {
($loggerProxy = $localLogger->ifWarningLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log('DB type prefix not found in connection string');
return;
}
$localLogger = $localLogger->addContext(
'dbTypePrefix',
$this->logger->possiblySecuritySensitive($dbTypePrefix)
);
$dbNameKey = 'dbname';
/** @var ?string $dsnKey */
$dsnKey = null;
switch ($dbTypePrefix) {
case 'cubrid':
$dbType = Constants::SPAN_SUBTYPE_CUBRID;
break;
case 'dblib':
case 'mssql':
$dbType = Constants::SPAN_SUBTYPE_MSSQL;
break;
case 'firebird':
$dbType = Constants::SPAN_SUBTYPE_FIREBIRD;
break;
case 'ibm':
$dbType = Constants::SPAN_SUBTYPE_IBM_DB2;
$dbNameKey = 'database';
$dsnKey = 'DSN';
break;
case 'informix':
$dbType = Constants::SPAN_SUBTYPE_INFORMIX;
$dbNameKey = 'database';
$dsnKey = 'DSN';
break;
case 'mysql':
$dbType = Constants::SPAN_SUBTYPE_MYSQL;
break;
case 'oci':
$dbType = Constants::SPAN_SUBTYPE_ORACLE;
break;
case 'odbc':
$dbType = Constants::SPAN_SUBTYPE_ODBC;
self::extractDbNameODBC($dbConnectionString, $posAfterDbTypePrefix, /* ref */ $dbName);
return;
case 'pgsql':
$dbType = Constants::SPAN_SUBTYPE_POSTGRESQL;
break;
case 'sqlite':
$dbType = Constants::SPAN_SUBTYPE_SQLITE;
self::extractDbNameSQLite($dbConnectionString, $posAfterDbTypePrefix, /* ref */ $dbName);
return;
case 'sqlsrv':
$dbType = Constants::SPAN_SUBTYPE_MSSQL;
$dbNameKey = 'database';
break;
default:
($loggerProxy = $localLogger->ifWarningLevelEnabled(__LINE__, __FUNCTION__))
&& $loggerProxy->log(
'Unknown DB type in connection string prefix',
['dbTypePrefix' => $dbTypePrefix]
);
return;
}
$localLogger->addContext('dbType', $dbType);
self::extractDbName(
$dbConnectionString,
$posAfterDbTypePrefix,
$dbNameKey,
$dsnKey,
$dbName /* <- ref */,
$localLogger
);
}