Skip to content
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
61 changes: 61 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy Docs

on:
push:
branches: [3.x]
paths:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
cache-dependency-path: docs/package-lock.json

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Install dependencies
run: npm ci
working-directory: docs

- name: Build docs
run: npm run docs:build
working-directory: docs

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
197 changes: 2 additions & 195 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,202 +9,9 @@ CakePHP integration for Sentry.

ℹ️ If you are using CakePHP 3.x or 4.0 - 4.3 please use the plugin from Connehito linked above

## Requirements
- PHP 7.4+ / PHP 8.0+
- CakePHP 4.4+
- and a [Sentry](https://sentry.io) account
## Documentation

## Version table
| | PHP | CakePHP | self-hosted Sentry |
|-----|------------------|---------|--------------------|
| 1.x | `^7.4 \|\| ^8.0` | `^4.4` | 🤷🏻 |
| 2.x | `^8.1` | `^5.0` | 🤷🏻 |
| 3.x | `^8.1` | `^5.0` | `>= v20.6.0` |

## Installation
```
composer require lordsimal/cakephp-sentry
```

## Usage

### Set config files
```php
// in `config/app.php`
return [
'Sentry' => [
'dsn' => '<sentry-dsn-url>',
'environment' => 'production',
]
];
```

### Loading plugin
In Application.php

```php
public function bootstrap()
{
parent::bootstrap();

$this->addPlugin(\CakeSentry\CakeSentryPlugin::class);
}
```

Or use the cake CLI.
```
bin/cake plugin load CakeSentry
```

That's all! 🎉

⚠️️ If events (error/exception) are not captured in Sentry try changing the order in which the plugins are loaded.

### Advanced Usage

#### Ignore specific exceptions
You can filter out noisy exceptions which should not be debugged further.

```php
// in `config/app.php`
'Error' => [
'skipLog' => [
NotFoundException::class,
MissingRouteException::class,
MissingControllerException::class,
],
]
```

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()`.
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.

| Event Name | Description |
|-----------------------------------|------------------------------------------------------|
| `CakeSentry.Client.afterSetup` | General config for e.g. a release info |
| `CakeSentry.Client.beforeCapture` | Before an error or exception is being sent to sentry |
| `CakeSentry.Client.afterCapture` | After an error or exception has been sent to sentry |

### Example for `CakeSentry.Client.afterSetup`

```php
use Cake\Event\Event;
use Cake\Event\EventListenerInterface;

class SentryOptionsContext implements EventListenerInterface
{
public function implementedEvents(): array
{
return [
'CakeSentry.Client.afterSetup' => 'setServerContext',
];
}

public function setServerContext(Event $event): void
{
/** @var \CakeSentry\Http\SentryClient $subject */
$subject = $event->getSubject();
$options = $subject->getHub()->getClient()->getOptions();

$options->setEnvironment('test_app');
$options->setRelease('3.0.0@dev');
}
}
```

And in `config/bootstrap.php`
```php
\Cake\Event\EventManager::instance()->on(new SentryOptionsContext());
```

### Example for `CakeSentry.Client.beforeCapture`

```php
use Cake\Event\Event;
use Cake\Event\EventListenerInterface;
use Sentry\State\Scope;

use function Sentry\configureScope as sentryConfigureScope;

class SentryErrorContext implements EventListenerInterface
{
public function implementedEvents(): array
{
return [
'CakeSentry.Client.beforeCapture' => 'setContext',
];
}

public function setContext(Event $event): void
{
if (PHP_SAPI !== 'cli') {
sentryConfigureScope(function (Scope $scope) use ($event) {
$request = \Cake\Routing\Router::getRequest();
$scope->setTag('app_version', $request->getHeaderLine('App-Version') ?: 1.0);
$exception = $event->getData('exception');
if ($exception) {
assert($exception instanceof \Exception);
$scope->setTag('status', $exception->getCode());
}
$scope->setUser(['ip_address' => $request->clientIp()]);
$scope->setExtras([
'foo' => 'bar',
'request attributes' => $request->getAttributes(),
]);
});
}
}
}
```

And in `config/bootstrap.php`
```php
\Cake\Event\EventManager::instance()->on(new SentryErrorContext());
```

### Example for `CakeSentry.Client.afterCapture`

```php
use Cake\Event\Event;

class SentryErrorContext implements EventListenerInterface
{
public function implementedEvents(): array
{
return [
'CakeSentry.Client.afterCapture' => 'callbackAfterCapture',
];
}

public function callbackAfterCapture(Event $event): void
{
$lastEventId = $event->getData('lastEventId');
}
}
```

### Query logging (optional)

If you want sentry events to also have query logging enabled you can do this via your config:

```php
'CakeSentry' => [
'enableQueryLogging' => true
]
```

If you want queries related to schema reflection also inside your events then you can enable that via

```php
'CakeSentry' => [
'includeSchemaReflection' => true
]
```
See https://losimal.github.io/cakephp-sentry/

## License
The plugin is available as open source under the terms of the [MIT License](https://github.com/lordsimal/cakephp-sentry/blob/master/LICENSE).
3 changes: 3 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vitepress/cache/
.vitepress/dist/
48 changes: 48 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: 'CakePHP Sentry',
description: 'Documentation for the CakePHP Sentry plugin',

base: '/cakephp-sentry/', // Should be the same as the repo name

head: [
['meta', { name: 'theme-color', content: '#D33C43' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:title', content: 'CakePHP Sentry Plugin' }],
['meta', { property: 'og:description', content: 'A CakePHP Plugin for Sentry Integration' }],
],

themeConfig: {
nav: [
{ text: 'Home', link: '/' },
{ text: 'Getting Started', link: '/guide/getting-started' },
{ text: 'GitHub', link: 'https://github.com/lordsimal/cakephp-sentry' },
],

sidebar: [
{
text: 'Documentation',
items: [
{ text: 'Getting Started', link: '/guide/getting-started' },
{ text: 'Configuration', link: '/guide/configuration' },
{ text: 'Event Hooks', link: '/guide/event-hooks' },
{ text: 'Query Logging', link: '/guide/query-logging' },
{ text: 'Performance Monitoring', link: '/guide/performance-monitoring' },
{ text: 'Logging', link: '/guide/logging' },
{ text: 'Queue Integration', link: '/guide/queue-integration' },
{ text: 'Changelog', link: '/guide/changelog' },
],
},
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/lordsimal/cakephp-sentry' },
],

search: {
provider: 'local',
},
},
})
45 changes: 45 additions & 0 deletions docs/guide/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Changelog

## Version 3.5.0

Added the following features:

- [Queue Integration](https://losimal.github.io/cakephp-sentry/guide/queue-integration.html)
- [Cache Tracing](https://losimal.github.io/cakephp-sentry/guide/performance-monitoring.html#cache-tracing)

## Version 3.4.0

Sentry `>= v25.9.0` added Support for [Logging](https://docs.sentry.io/platforms/php/logs/). This has now been integrated into the [plugin](https://losimal.github.io/cakephp-sentry/guide/logging.html).

## Version 3.3.0

Added PHPUnit 12 support

## Version 3.2.0

HTTP requests being done by the CakePHP HTTP Client are now being traced if you have enabled [Performance Monitoring](https://losimal.github.io/cakephp-sentry/guide/performance-monitoring.html).

## Version 3.1.0

Leverage the new `Server.terminate` event to flush the Sentry queue before the server terminates.

## Version 3.0.0

Refactored Version with breaking changes.

- Sentry PHP SDK updated from `^3.3` to `^4.0`
- `CakeSentryMiddleware` has been renamed to `CakeSentryQueryMiddleware`
- Properties are not prefixed with `_` anymore

The `CakeSentryPerformanceMiddleware` has been added to add support for the [Performance Monitoring Feature](https://docs.sentry.io/product/sentry-basics/performance-monitoring/).
See the [Performance Monitoring documentation](https://losimal.github.io/cakephp-sentry/guide/performance-monitoring.html) for more details.


## Version 2.0.0

First CakePHP 5 compatible release with no new features


## Version 1.0.0

First stable release for CakePHP 4.4+ and Sentry SDK 3.x as CakePHP changed the way errors are handled in 4.4
Loading
Loading