{"id":13684214,"url":"https://github.com/lordsimal/cakephp-sentry","last_synced_at":"2025-03-17T05:32:06.645Z","repository":{"id":61822997,"uuid":"555414023","full_name":"LordSimal/cakephp-sentry","owner":"LordSimal","description":"CakePHP 4.4+/5+ plugin integration for Sentry","archived":false,"fork":false,"pushed_at":"2025-01-11T10:48:50.000Z","size":360,"stargazers_count":10,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"3.x","last_synced_at":"2025-03-12T06:11:13.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LordSimal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-21T14:28:52.000Z","updated_at":"2025-01-11T10:48:55.000Z","dependencies_parsed_at":"2023-11-07T01:50:54.965Z","dependency_job_id":"34ab40c2-c3f4-4da0-bb65-f1e85d4d6f56","html_url":"https://github.com/LordSimal/cakephp-sentry","commit_stats":{"total_commits":73,"total_committers":5,"mean_commits":14.6,"dds":0.1643835616438356,"last_synced_commit":"54eacef8b1808ef15e68446f4c810f917fa02905"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordSimal%2Fcakephp-sentry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordSimal%2Fcakephp-sentry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordSimal%2Fcakephp-sentry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordSimal%2Fcakephp-sentry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LordSimal","download_url":"https://codeload.github.com/LordSimal/cakephp-sentry/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243846976,"owners_count":20357294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T14:00:31.034Z","updated_at":"2025-03-17T05:32:06.219Z","avatar_url":"https://github.com/LordSimal.png","language":"PHP","funding_links":[],"categories":["Debugging"],"sub_categories":[],"readme":"# CakePHP Sentry Plugin\n\n[![Latest Stable Version](https://poser.pugx.org/lordsimal/cakephp-sentry/v)](https://packagist.org/packages/lordsimal/cakephp-sentry) [![Total Downloads](https://poser.pugx.org/lordsimal/cakephp-sentry/downloads)](https://packagist.org/packages/lordsimal/cakephp-sentry) [![Latest Unstable Version](https://poser.pugx.org/lordsimal/cakephp-sentry/v/unstable)](https://packagist.org/packages/lordsimal/cakephp-sentry) [![License](https://poser.pugx.org/lordsimal/cakephp-sentry/license)](https://packagist.org/packages/lordsimal/cakephp-sentry) [![PHP Version Require](https://poser.pugx.org/lordsimal/cakephp-sentry/require/php)](https://packagist.org/packages/lordsimal/cakephp-sentry)\n[![codecov](https://codecov.io/gh/LordSimal/cakephp-sentry/branch/main/graph/badge.svg?token=99W08MNO6S)](https://codecov.io/gh/LordSimal/cakephp-sentry)\n\nCakePHP integration for Sentry.\n\nℹ️ This is a refactored version of https://github.com/Connehito/cake-sentry to remove deprecation warnings introduced in CakePHP 4.4\n\nℹ️ If you are using CakePHP 4.4+ please use the 1.x version of this plugin\n\nℹ️ If you are using CakePHP 3.x or 4.0 - 4.3 please use the plugin from Connehito linked above\n\n## Requirements\n- PHP 8.1+\n- CakePHP 5+\n- and a [Sentry](https://sentry.io) account\n  - if you use self-hosted sentry make sure you are on at least version `\u003e= v20.6.0`\n\n## Version table\n|     | PHP              | CakePHP | self-hosted Sentry |\n|-----|------------------|---------|--------------------|\n| 1.x | `^7.4 \\|\\| ^8.0` | `^4.4`  | 🤷🏻               |\n| 2.x | `^8.1`           | `^5.0`  | 🤷🏻               |\n| 3.x | `^8.1`           | `^5.0`  | `\u003e= v20.6.0`       |\n\n## Installation\n```\ncomposer require lordsimal/cakephp-sentry\n```\n\n## Usage\n\n### Set config files\n```php\n// in `config/app.php`\nreturn [\n    'Sentry' =\u003e [\n        'dsn' =\u003e '\u003csentry-dsn-url\u003e',\n        'environment' =\u003e 'production',\n    ]\n];\n```\n\n### Loading plugin\nIn Application.php\n\n```php\npublic function bootstrap()\n{\n    parent::bootstrap();\n\n    $this-\u003eaddPlugin(\\CakeSentry\\CakeSentryPlugin::class);\n}\n```\n\nOr use the cake CLI.\n```\nbin/cake plugin load CakeSentry\n```\n\nThat's all! 🎉\n\n⚠️️ If events (error/exception) are not captured in Sentry try changing the order in which the plugins are loaded.\n\n### Advanced Usage\n\n#### Ignore specific exceptions\nYou can filter out noisy exceptions which should not be debugged further.\n\n```php\n// in `config/app.php`\n'Error' =\u003e [\n    'skipLog' =\u003e [\n        NotFoundException::class,\n        MissingRouteException::class,\n        MissingControllerException::class,\n    ],\n]\n```\n\nAlso see [CakePHP Cookbook](https://book.cakephp.org/4/en/development/errors.html#error-exception-configuration)\n\n### Set Options\nEverything inside the `'Sentry'` configuration key will be passed to `\\Sentry\\init()`.\nPlease 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).\n\nCakeSentry also provides custom event hooks to set dynamic values.\n\n| Event Name                        | Description                                          |\n|-----------------------------------|------------------------------------------------------|\n| `CakeSentry.Client.afterSetup`    | General config for e.g. a release info               |\n| `CakeSentry.Client.beforeCapture` | Before an error or exception is being sent to sentry |\n| `CakeSentry.Client.afterCapture`  | After an error or exception has been sent to sentry  |\n\n### Example for `CakeSentry.Client.afterSetup`\n\n```php\nuse Cake\\Event\\Event;\nuse Cake\\Event\\EventListenerInterface;\n\nclass SentryOptionsContext implements EventListenerInterface\n{\n    public function implementedEvents(): array\n    {\n        return [\n            'CakeSentry.Client.afterSetup' =\u003e 'setServerContext',\n        ];\n    }\n\n    public function setServerContext(Event $event): void\n    {\n        /** @var \\CakeSentry\\Http\\SentryClient $subject */\n        $subject = $event-\u003egetSubject();\n        $options = $subject-\u003egetHub()-\u003egetClient()-\u003egetOptions();\n\n        $options-\u003esetEnvironment('test_app');\n        $options-\u003esetRelease('3.0.0@dev');\n    }\n}\n```\n\nAnd in `config/bootstrap.php`\n```php\n\\Cake\\Event\\EventManager::instance()-\u003eon(new SentryOptionsContext());\n```\n\n### Example for `CakeSentry.Client.beforeCapture`\n\n```php\nuse Cake\\Event\\Event;\nuse Cake\\Event\\EventListenerInterface;\nuse Sentry\\State\\Scope;\n\nuse function Sentry\\configureScope as sentryConfigureScope;\n\nclass SentryErrorContext implements EventListenerInterface\n{\n    public function implementedEvents(): array\n    {\n        return [\n            'CakeSentry.Client.beforeCapture' =\u003e 'setContext',\n        ];\n    }\n\n    public function setContext(Event $event): void\n    {\n        if (PHP_SAPI !== 'cli') {\n            sentryConfigureScope(function (Scope $scope) use ($event) {\n                $request = \\Cake\\Routing\\Router::getRequest();\n                $scope-\u003esetTag('app_version',  $request-\u003egetHeaderLine('App-Version') ?: 1.0);\n                $exception = $event-\u003egetData('exception');\n                if ($exception) {\n                    assert($exception instanceof \\Exception);\n                    $scope-\u003esetTag('status', $exception-\u003egetCode());\n                }\n                $scope-\u003esetUser(['ip_address' =\u003e $request-\u003eclientIp()]);\n                $scope-\u003esetExtras([\n                    'foo' =\u003e 'bar',\n                    'request attributes' =\u003e $request-\u003egetAttributes(),\n                ]);\n            });\n        }\n    }\n}\n```\n\nAnd in `config/bootstrap.php`\n```php\n\\Cake\\Event\\EventManager::instance()-\u003eon(new SentryErrorContext());\n```\n\n### Example for `CakeSentry.Client.afterCapture`\n\n```php\nuse Cake\\Event\\Event;\n\nclass SentryErrorContext implements EventListenerInterface\n{\n    public function implementedEvents(): array\n    {\n        return [\n            'CakeSentry.Client.afterCapture' =\u003e 'callbackAfterCapture',\n        ];\n    }\n\n    public function callbackAfterCapture(Event $event): void\n    {\n        $lastEventId = $event-\u003egetData('lastEventId');\n    }\n}\n```\n\n### Query logging (optional)\n\nIf you want sentry events to also have query logging enabled you can do this via your config:\n\n```php\n'CakeSentry' =\u003e [\n    'enableQueryLogging' =\u003e true\n]\n```\n\nIf you want queries related to schema reflection also inside your events then you can enable that via\n\n```php\n'CakeSentry' =\u003e [\n    'includeSchemaReflection' =\u003e true\n]\n```\n\n### Performance monitoring (optional)\n\nIf you want to use the performance monitoring feature of sentry you have to enable these 2 settings\n\n```php\n'CakeSentry' =\u003e [\n    'enableQueryLogging' =\u003e true,\n    'enablePerformanceMonitoring' =\u003e true\n]\n```\n\nas well as set the corresponding [Sentry SDK options](https://docs.sentry.io/platforms/php/performance/#configure)\n\n```php\n'Sentry' =\u003e [\n    'dsn' =\u003e '\u003csentry-dsn-url\u003e',\n    'traces_sample_rate' =\u003e 1,\n]\n```\n\nto see SQL query execution and duration inside the performance monitoring section of sentry make sure to enable logging for your desired datasource like so:\n```\n'Datasources' =\u003e [\n    'default' =\u003e [\n        'sentryLog' =\u003e true\n    ]\n]\n```\n\n## Upgrade from 2 to 3\n\nThere are a few major changes from 2.0 to 3.0\n\n- The Sentry PHP SDK was upgraded from `^3.3` to [^4.0](https://github.com/getsentry/sentry-php/releases/tag/4.0.0)\n- `CakeSentryMiddleware` has been renamed to `CakeSentryQueryMiddleware`\n- Properties are not prefixed `_` anymore\n- The `CakeSentryPerformanceMiddleware` has been added to add support for the [Performance Monitoring Feature](https://docs.sentry.io/product/performance/)\n\n## License\nThe plugin is available as open source under the terms of the [MIT License](https://github.com/lordsimal/cakephp-sentry/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordsimal%2Fcakephp-sentry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flordsimal%2Fcakephp-sentry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flordsimal%2Fcakephp-sentry/lists"}