Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x fixes #10

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.neon]
indent_style = tab
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Set the default behavior for all files.
* text=auto

.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CakePHP integration for Sentry.
- PHP 8.1+
- CakePHP 5+
- and a [Sentry](https://sentry.io) account
- if you use self hosted sentry make sure you are on at least version `>= v20.6.0`
- if you use self-hosted sentry make sure you are on at least version `>= v20.6.0`

## Version table
| | PHP | CakePHP | self-hosted Sentry |
Expand Down Expand Up @@ -82,7 +82,7 @@ You can filter out noisy exceptions which should not be debugged further.
Also see [CakePHP Cookbook](https://book.cakephp.org/4/en/development/errors.html#error-exception-configuration)

### Set Options
Everything inside the `'Sentry'` configuration key will be passed to `\Sentry\init()`.
Everything inside the `'Sentry'` configuration key will be passed to `\Sentry\init()`.
Please check Sentry's official documentation on [about configuration](https://docs.sentry.io/error-reporting/configuration/?platform=php) and [about php-sdk's configuraion](https://docs.sentry.io/platforms/php/#php-specific-options).

CakeSentry also provides custom event hooks to set dynamic values.
Expand All @@ -101,7 +101,7 @@ use Cake\Event\EventListenerInterface;

class SentryOptionsContext implements EventListenerInterface
{
public function implementedEvents(): array
public function implementedEvents(): array
{
return [
'CakeSentry.Client.afterSetup' => 'setServerContext',
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"scripts": {
"test": "phpunit",
"cs-check": "phpcs --colors -p src tests",
"cs-fix": "phpcbf --colors -p src tests",
"cs-check": "phpcs --colors -p src/ tests/",
"cs-fix": "phpcbf --colors -p src/ tests/",
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
Expand Down
12 changes: 6 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
paths:
- src
- tests/TestCase
level: 5
bootstrapFiles:
- tests/bootstrap.php
paths:
- src/
level: 5
checkMissingIterableValueType: false
bootstrapFiles:
- tests/bootstrap.php
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

<testsuites>
<testsuite name="cakephp">
<directory>./tests/TestCase/</directory>
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

<!-- Prevent coverage reports from looking in tests, vendors, config folders -->
<source>
<include>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
5 changes: 4 additions & 1 deletion src/Http/SentryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ protected function getQueryLoggers(): void
if ($connection->configName() === 'debug_kit') {
continue;
}
$logger = $connection->getDriver()->getLogger();
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$logger = $driver->getLogger();

if ($logger instanceof CakeSentryLog) {
$logger->setIncludeSchema($includeSchemaReflection);
Expand Down Expand Up @@ -161,6 +163,7 @@ public function captureError(

$client = $this->hub->getClient();
if ($client) {
/** @var array<int, array{function?: string, line?: int, file?: string, class?: class-string, type?: string, args?: array}> $trace */
$trace = $this->cleanedTrace($error->getTrace());
/** @psalm-suppress ArgumentTypeCoercion */
$stacktrace = $client->getStacktraceBuilder()
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/CakeSentryPerformanceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@
continue;
}
$logger = null;
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog']) {
if ($driverConfig['sentryLog'] ?? false) {

Check warning on line 116 in src/Middleware/CakeSentryPerformanceMiddleware.php

View check run for this annotation

Codecov / codecov/patch

src/Middleware/CakeSentryPerformanceMiddleware.php#L116

Added line #L116 was not covered by tests
$logger = $driver->getLogger();
if ($logger instanceof CakeSentryLog) {
$logger->setPerformanceMonitoring(true);
Expand Down
3 changes: 2 additions & 1 deletion src/Middleware/CakeSentryQueryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ protected function enableQueryLogging(): void
continue;
}
$logger = null;
/** @var \Cake\Database\Driver $driver */
$driver = $connection->getDriver();
$driverConfig = $driver->config();
if ($driverConfig['sentryLog']) {
if ($driverConfig['sentryLog'] ?? false) {
$logger = $driver->getLogger();
}

Expand Down
5 changes: 3 additions & 2 deletions src/QuerySpanTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
}

if ($connectionName) {
$connection = ConnectionManager::get($connectionName);
$dialect = $connection->getDriver()->schemaDialect();
/** @var \Cake\Database\Driver $driver */
$driver = ConnectionManager::get($connectionName)->getDriver();
$dialect = $driver->schemaDialect();

Check warning on line 65 in src/QuerySpanTrait.php

View check run for this annotation

Codecov / codecov/patch

src/QuerySpanTrait.php#L64-L65

Added lines #L64 - L65 were not covered by tests
$type = match (true) {
$dialect instanceof PostgresSchemaDialect => 'postgresql',
$dialect instanceof SqliteSchemaDialect => 'sqlite',
Expand Down
Loading