{"id":18767505,"url":"https://github.com/codekandis/sentry-client","last_synced_at":"2025-08-11T06:36:40.389Z","repository":{"id":56955193,"uuid":"227813622","full_name":"codekandis/sentry-client","owner":"codekandis","description":"This library represents a wrapper for the `Sentry SDK` with enhanced development features.","archived":false,"fork":false,"pushed_at":"2021-01-21T16:10:11.000Z","size":113,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T06:44:36.982Z","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/codekandis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-13T10:23:19.000Z","updated_at":"2021-01-21T08:26:45.000Z","dependencies_parsed_at":"2022-08-21T08:50:21.496Z","dependency_job_id":null,"html_url":"https://github.com/codekandis/sentry-client","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fsentry-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fsentry-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fsentry-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codekandis%2Fsentry-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codekandis","download_url":"https://codeload.github.com/codekandis/sentry-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239671225,"owners_count":19677870,"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-11-07T19:07:38.951Z","updated_at":"2025-02-19T13:46:27.625Z","avatar_url":"https://github.com/codekandis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# codekandis/sentry-client\n\n[![Version][xtlink-version-badge]][srclink-changelog]\n[![License][xtlink-license-badge]][srclink-license]\n[![Minimum PHP Version][xtlink-php-version-badge]][xtlink-php-net]\n![Code Coverage][xtlink-code-coverage-badge]\n\n`codekandis/sentry-client` is a wrapper library for the Sentry SDK package [`getsentry/sentry-php`][xtlink-github-getsentry-sentry-php], currently supporting the Sentry SDK version `2.x`. It provides the functionality of the wrapped package by an object-oriented API.\n\n## Index\n\n* [Installation](#installation)\n* [How to use](#how-to-use)\n  * [Create a configuration](#create-a-configuration)\n    * [Use the default configuration](#use-the-default-configuration)\n    * [Implement the configuration interface on your own](#implement-the-configuration-interface-on-your-own)\n  * [Instantiate the Sentry Client](#instantiate-the-sentry-client)\n  * [Capturing events](#capturing-events)\n    * [Manual capturing](#manual-capturing)\n      * [Messages](#messages)\n      * [Errors](#errors)\n      * [Exceptions](#exceptions)\n    * [Automatic Capturing](#automatic-capturing)\n    * [Using custom error and exception handlers](#using-custom-error-and-exception-handlers)\n  * [Testing](#testing)\n\n## Installation\n\nInstall the latest version with\n\n```bash\n$ composer require codekandis/sentry-client\n```\n\n## How to use\n\n### Create a configuration\n\nThere's two possibilites.\n\n#### Use the default configuration\n\nFor convenience the default configuration [`SentryClientConfiguration`][srclink-sentry-client-configuration] implements the fluent interface.\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\n\n$sentryClientConfiguration = ( new SentryClientConfiguration() )\n\t-\u003esetDsn( 'dsn' )\n\t-\u003esetErrorTypes( E_ALL )\n\t-\u003esetDisplayErrors( true );\n```\n\n#### Implement the configuration interface on your own\n\nThe [`SentryClient`][srclink-sentry-client] comes with the configuration interface [`SentryClientConfigurationInterface`][srclink-sentry-client-configuration-interface]. So you are enabled to implement a configuration on your own.\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfigurationInterface;\n\nclass SentryClientConfiguration implements SentryClientConfigurationInterface\n{\n\tpublic function getDsn(): string\n\t{\n\t\treturn 'dsn';\n\t}\n\t\n\t/**\n\t * ...\n\t */\n}\n\n$sentryClientConfiguration = new SentryClientConfiguration();\n```\n\n### Instantiate the Sentry Client\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\nuse const E_ALL;\n\n$sentryClient = new SentryClient(\n\t( new SentryClientConfiguration() )\n\t    -\u003esetDsn( 'dsn' )\n\t\t-\u003esetErrorTypes( E_ALL )\n\t\t-\u003esetDisplayErrors( true )\n);\n```\n\nAs soon as the [`SentryClient`][srclink-sentry-client] is instantiated the PHP directives [`error_reporting`][xtlink-php-net-error-reporting] and [`display_errors`][xtlink-php-net-display-errors] will be set immediately. Be aware that [`display_errors`][xtlink-php-net-display-errors], once set to `true`, will take effect in displaying all captured events. So besides errors and exceptions manually captured messages are displayed as well.\n\n### Capturing events\n\nThere are two methods of capturing messages, errors and exceptions - so-called events in terms of [Sentry][xtlink-sentry-io].\n\n#### Manual capturing\n\n##### Messages\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\nuse CodeKandis\\SentryClient\\Severities;\n\n( new SentryClient( new SentryClientConfiguration() ) )\n\t-\u003ecaptureMessage(\n\t\t'This is a message.',\n\t\tSeverities::INFO,\n\t\t[\n\t\t\t'some' =\u003e 'context'\n\t\t],\n\t\t[\n\t\t\t'some tag',\n\t\t\t'another tag'\n\t\t],\n\t\t[\n\t\t\t'id'         =\u003e 'some username',\n\t\t\t'ip_address' =\u003e '42.42.42.42'\n\t\t]\n\t);\n```\n\n##### Errors\n\nOnly the last occured error can be captured.\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\nuse CodeKandis\\SentryClient\\Severities;\n\n( new SentryClient( new SentryClientConfiguration() ) )\n\t-\u003ecaptureLastError(\n\t\tSeverities::ERROR,\n\t\t[\n\t\t\t'some' =\u003e 'context'\n\t\t],\n\t\t[\n\t\t\t'some tag',\n\t\t\t'another tag'\n\t\t],\n\t\t[\n\t\t\t'id'         =\u003e 'some username',\n\t\t\t'ip_address' =\u003e '42.42.42.42'\n\t\t]\n\t);\n```\n\n##### Exceptions\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\nuse CodeKandis\\SentryClient\\Severities;\nuse Exception;\n\n( new SentryClient( new SentryClientConfiguration() ) )\n\t-\u003ecaptureThrowable(\n\t\tnew Exception( 'This is an exception' ),\n\t\tSeverities::FATAL,\n\t\t[\n\t\t\t'some' =\u003e 'context'\n\t\t],\n\t\t[\n\t\t\t'some tag',\n\t\t\t'another tag'\n\t\t],\n\t\t[\n\t\t\t'id'         =\u003e 'some username',\n\t\t\t'ip_address' =\u003e '42.42.42.42'\n\t\t]\n\t);\n```\n\n#### Automatic Capturing\n\nThe [`SentryClient`][srclink-sentry-client] comes with built-in error and exception handlers. Once the automatic capturing of events is enabled the occured events will be captured by that handlers and sent to your configured Sentry instance.\n\nTo enable the automatic capturing you just have to call [`SentryClient::register()`][srclink-sentry-client].\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\n\n( new SentryClient( new SentryClientConfiguration() ) )\n\t-\u003eregister();\n```\n\n### Using custom error and exception handlers\n\nIn case you have already set your own error or exception handlers, registering the [`SentryClient`][srclink-sentry-client] for automatic capturing won't affect them being executed.\n\n```php\n\u003c?php declare( strict_types = 1 );\nnamespace Vendor\\Project;\n\nuse CodeKandis\\SentryClient\\Configurations\\SentryClientConfiguration;\nuse CodeKandis\\SentryClient\\SentryClient;\nuse Exception;\nuse Throwable;\nuse function set_error_handler;\nuse function set_exception_handler;\nuse function trigger_error;\n\nset_error_handler(\n\tfunction ( int $level, string $message )\n\t{\n\t\techo 'Error handler: ' . $message . \"\\n\";\n\t}\n);\n\nset_exception_handler(\n\tfunction ( Throwable $exception )\n\t{\n\t\techo 'Exception handler: ' . $exception-\u003egetMessage() . \"\\n\";\n\t}\n);\n\n( new SentryClient( new SentryClientConfiguration() ) )\n\t-\u003eregister();\n\ntrigger_error( 'An error occured.' );            // outputs `Error handler: An error occured.`\nthrow new Exception( 'An exception occured.' );  // outputs `Exception handler: An exception occured.`\n```\n\nThe Sentry Client pushes its own handlers on top of its internal managed stack of handlers. So the error and exception handlers are executed in the following order:\n\n1. the [`SentryClient`][srclink-sentry-client] handler\n2. the wrapped [Sentry SDK][xtlink-github-getsentry-sentry-php] handler\n3. your custom handler\n\nSo it's guaranteed all events will be sent to your Sentry instance and your handlers are executed as well.\n\n## Testing\n\nTo get the integration tests running some settings must be made in the [`TestConstants`][testlink-helpers-constants-test-constants]. All necessary information can be found in your Sentry instance.\n\nDepending on the workload of your Sentry instance your events may not be fetchable immediately by the API. So a proper [`TestConstants::EVENT_PROCESSING_THRESHOLD`][testlink-helpers-constants-test-constants] in seconds must be set.\n\nDue to the nature of the wrapped [Sentry SDK][xtlink-github-getsentry-sentry-php] executing all test cases at once causes some integration tests to fail. Some necessary test outputs mess up with the following tests. It's recommended to run all single tests in the test case [`SentryClientInterfaceTest`][testlink-integration-tests-sentry-client-interface] manually one by one.\n\n\n\n[xtlink-version-badge]: https://img.shields.io/badge/version-1.0.0-blue.svg\n[xtlink-license-badge]: https://img.shields.io/badge/license-MIT-yellow.svg\n[xtlink-php-version-badge]: https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg\n[xtlink-code-coverage-badge]: https://img.shields.io/badge/coverage-100%25-green.svg\n[xtlink-php-net]: https://php.net\n[xtlink-php-net-error-reporting]: https://www.php.net/manual/en/function.error-reporting.php\n[xtlink-php-net-display-errors]: https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors\n[xtlink-github-getsentry-sentry-php]: https://github.com/getsentry/sentry-php\n[xtlink-sentry-io]: https://sentry.io\n\n[srclink-changelog]: ./CHANGELOG.md\n[srclink-license]: ./LICENSE\n[srclink-sentry-client-configuration-interface]: ./src/Configurations/SentryClientConfigurationInterface.php\n[srclink-sentry-client-configuration]: ./src/Configurations/SentryClientConfiguration.php\n[srclink-sentry-client]: ./src/SentryClient.php\n[testlink-integration-tests-sentry-client-interface]: ./tests/IntegrationTests/SentryClientInterfaceTest.php\n[testlink-helpers-constants-test-constants]: ./tests/Helpers/Constants/TestConstants.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekandis%2Fsentry-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodekandis%2Fsentry-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodekandis%2Fsentry-client/lists"}