Skip to content

Commit

Permalink
Merge pull request #31 from LordSimal/3.x
Browse files Browse the repository at this point in the history
merge 3.x => 3.next
  • Loading branch information
LordSimal authored Dec 29, 2024
2 parents 72e10f3 + 707eb00 commit e42f30a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Code Coverage Report
if: success() && matrix.php-version == '8.1'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5

cs-stan:
name: Coding Standard & Static Analysis
Expand Down
9 changes: 7 additions & 2 deletions src/Http/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace CakeSentry\Http;

use Cake\Core\Configure;
use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use Cake\Error\PhpError;
use Cake\Event\Event;
Expand Down Expand Up @@ -53,13 +54,17 @@ protected function getQueryLoggers(): void
$includeSchemaReflection = (bool)Configure::read('CakeSentry.includeSchemaReflection');

foreach ($configs as $name) {
$logger = null;
$connection = ConnectionManager::get($name);
if ($connection->configName() === 'debug_kit') {
continue;
}
/** @var \Cake\Database\Driver $driver */
/** @var \Cake\Database\Driver|object $driver */
$driver = $connection->getDriver();
$logger = $driver->getLogger();

if ($driver instanceof Driver) {
$logger = $driver->getLogger();
}

if ($logger instanceof CakeSentryLog) {
$logger->setIncludeSchema($includeSchemaReflection);
Expand Down
15 changes: 9 additions & 6 deletions src/Middleware/CakeSentryPerformanceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
namespace CakeSentry\Middleware;

use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\Http\Server;
Expand Down Expand Up @@ -121,13 +122,15 @@ protected function addQueryData(): void
continue;
}
$logger = null;
/** @var \Cake\Database\Driver $driver */
/** @var \Cake\Database\Driver|object $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($logger instanceof CakeSentryLog) {
$logger->setPerformanceMonitoring(true);
if ($driver instanceof Driver) {
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($logger instanceof CakeSentryLog) {
$logger->setPerformanceMonitoring(true);
}
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/Middleware/CakeSentryQueryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CakeSentry\Middleware;

use Cake\Core\Configure;
use Cake\Database\Driver;
use Cake\Datasource\ConnectionManager;
use CakeSentry\Database\Log\CakeSentryLog;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -57,15 +58,19 @@ protected function enableQueryLogging(): void
continue;
}
$logger = null;
/** @var \Cake\Database\Driver $driver */
/** @var \Cake\Database\Driver|object $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
if ($driver instanceof Driver) {
$driverConfig = $driver->config();
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
}
}

$logger = new CakeSentryLog($logger, $name, $includeSchemaReflection);
$driver->setLogger($logger);
if (method_exists($driver, 'setLogger')) {
$driver->setLogger($logger);
}
}
}
}

0 comments on commit e42f30a

Please sign in to comment.