masterarrow/raven-php
Composer 安装命令:
composer require masterarrow/raven-php
包简介
A PHP client for Sentry (http://getsentry.com)
README 文档
README
// Instantiate a new client with a compatible DSN $client = new Raven_Client('http://public:secret@example.com/1'); // Capture a message $event_id = $client->getIdent($client->captureMessage('my log message')); if ($client->getLastError() !== null) { printf('There was an error sending the event to Sentry: %s', $client->getLastError()); } // Capture an exception $event_id = $client->getIdent($client->captureException($ex)); // Provide some additional data with an exception $event_id = $client->getIdent($client->captureException($ex, array( 'extra' => array( 'php_version' => phpversion() ), ))); // Give the user feedback echo "Sorry, there was an error!"; echo "Your reference ID is " . $event_id; // Install error handlers and shutdown function to catch fatal errors $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction();
Installation
Install with Composer
If you're using Composer to manage dependencies, you can add Raven with it.
$ composer require masterarrow/raven-php
Composer will take care of the autoloading for you, so if you require the
vendor/autoload.php, you're good to go.
Testing Your Connection
The PHP client includes a simple helper script to test your connection and credentials with the Sentry master server:
$ bin/raven test https://public:secret@app.getsentry.com/1 Client configuration: -> server: [https://sentry.example.com/api/store/] -> project: 1 -> public_key: public -> secret_key: secret Sending a test event: -> event ID: f1765c9aed4f4ceebe5a93df9eb2d34f Done!
Note
The CLI enforces the synchronous option on HTTP requests whereas the default configuration is asyncrhonous.
Configuration
Several options exist that allow you to configure the behavior of the Raven_Client. These are passed as the
second parameter of the constructor, and is expected to be an array of key value pairs:
$client = new Raven_Client($dsn, array( 'option_name' => 'value', ));
name
A string to override the default value for the server's hostname.
Defaults to Raven_Compat::gethostname().
tags
An array of tags to apply to events in this context.
'tags' => array( 'php_version' => phpversion(), )
curl_method
Defaults to 'sync'.
Available methods:
- sync (default): send requests immediately when they're made
- async: uses a curl_multi handler for best-effort asynchronous submissions
- exec: asynchronously send events by forking a curl process for each item
curl_path
Defaults to 'curl'.
Specify the path to the curl binary to be used with the 'exec' curl method.
trace
Set this to false to disable reflection tracing (function calling arguments) in stacktraces.
logger
Adjust the default logger name for messages.
Defaults to php.
ca_cert
The path to the CA certificate bundle.
Defaults to the common bundle which includes getsentry.com: ./data/cacert.pem
Caveats:
- The CA bundle is ignored unless curl throws an error suggesting it needs a cert.
- The option is only currently used within the synchronous curl transport.
curl_ssl_version
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
message_limit
Defaults to 1024 characters.
This value is used to truncate message and frame variables. However it is not guarantee that length of whole message will be restricted by this value.
processors
An array of classes to use to process data before it is sent to Sentry. By default, Raven_SanitizeDataProcessor is used
processorOptions
Options that will be passed on to a setProcessorOptions() function in a Raven_Processor sub-class before that Processor is added to the list of processors used by Raven_Client
An example of overriding the regular expressions in Raven_SanitizeDataProcessor is below:
'processorOptions' => array( 'Raven_SanitizeDataProcessor' => array( 'fields_re' => '/(user_password|user_token|user_secret)/i', 'values_re' => '/^(?:\d[ -]*?){15,16}$/' ) )
Providing Request Context
Most of the time you're not actually calling out to Raven directly, but you still want to provide some additional context. This lifecycle generally constists of something like the following:
- Set some context via a middleware (e.g. the logged in user)
- Send all given context with any events during the request lifecycle
- Cleanup context
There are three primary methods for providing request context:
// bind the logged in user $client->user_context(array('email' => 'foo@example.com')); // tag the request with something interesting $client->tags_context(array('interesting' => 'yes')); // provide a bit of additional context $client->extra_context(array('happiness' => 'very'));
If you're performing additional requests during the lifecycle, you'll also need to ensure you cleanup the context (to reset its state):
$client->context->clear();
Contributing
First, make sure you can run the test suite. Install development dependencies :
$ composer install
You may now use phpunit :
$ vendor/bin/phpunit
Resources
- Bug Tracker
- Code
- Mailing List
- IRC (irc.freenode.net, #sentry)
masterarrow/raven-php 适用场景与选型建议
masterarrow/raven-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 masterarrow/raven-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 masterarrow/raven-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 masterarrow/raven-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Pacote simplificado para persistência de logs
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-01-02