dziki/monolog-sentry-bundle
最新稳定版本:v1.1.0
Composer 安装命令:
composer require dziki/monolog-sentry-bundle
包简介
Improve logging to Sentry with user, user agent, revision and Symfony version data
README 文档
README
Bundle for appending useful data to Monolog log records like username, parsed user-agent header, host name, Symfony version, commit hash and a lot more - you can provide custom tags to be added to all your logs.
Installation
Install bundle with composer require dziki/monolog-sentry-bundle command.
TL;DR
Comparison of exactly same error handled by default monolog raven handler with sentry/sentry package client with bundle
turned off and on with some basic config. As you can see - after turning bundle on - browser, user,
breadcrumbs and some valuable tags showed up, making your error logs much easier to read.
Before
After
Enable the Bundle
Add entry to config/bundles.php:
return [ // ... Dziki\MonologSentryBundle\MonologSentryBundle::class => ['all' => true], ];
or to app/AppKernel.php
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Dziki\MonologSentryBundle\MonologSentryBundle(), ); // ... } // ... }
Configuration
Default configuration does nothing, You need to adjust it manually according to Your needs:
monolog_sentry: user_context: false # append username from TokenStorage to log user_agent_parser: false # install donatj/phpuseragentparser package # and set to 'phpuseragent' to parse browser name, version and platform from user agent
You can turn on logging user context by setting value to true - it requires symfony/security-bundle package.
user_agent_parser requires valid user agent header parser service as value.
Parsing user agent takes about 0.1ms (up to 1ms using native parser) for every request, so...
Caching once parsed User Agents
Caching is supported when service implementing Psr\SimpleCache\CacheInterface is provided under cache config entry.
Starting from version 4.1 of Symfony there is default simple cache service cache.app.simple, in previous versions you
need to define own service:
monolog_sentry: cache: cache.app.simple # service implementing "Psr\SimpleCache\CacheInterface" interface
Custom tags
You can extend amount of logged data by adding custom tags. For example, for logging Symfony version, setting useful Sentry environment and server name you should modify config to this:
monolog_sentry: ... tags: symfony_version: !php/const Symfony\Component\HttpKernel\Kernel::VERSION # useful for regression check commit: '%env(APP_REVISION)%' # for example hash of commit, set your own environment variable or parameter environment: '%env(SERVER_NAME)%' # Sentry environment discriminator, much more useful than default `prod`
Full basic config
monolog_sentry: user_context: true # append username from TokenStorage to log user_agent_parser: phpuseragent # parse browser name, version and platform from user agent cache: cache.app.simple # service implementing "Psr\SimpleCache\CacheInterface" interface, since SF 4.1 tags: symfony_version: !php/const Symfony\Component\HttpKernel\Kernel::VERSION # useful for regression check commit: '%env(APP_REVISION)%' # for example hash of commit, set your own environment variable or parameter environment: '%env(SERVER_NAME)%' # Sentry environment discriminator, much more useful than default `prod`
User Agent parser
Bundle supports two parsers:
phpuseragent(github.com/donatj/PhpUserAgent) - as suggested packagenative(get_browser()) - browscap configuration setting in php.ini must point to the correct location of the browscap.ini
Configurable through user_agent_parser value, respectively phpuseragent or native. You can also add own, by providing
name of service implementing ParserInterface.
Hints
- Add
stop_buffering: falseto yourfingers_crossedhandler to keep low level messages notifications as breadcrumbs:
monolog: handlers: main: type: fingers_crossed action_level: error handler: buffered stop_buffering: false sentry: type: raven dsn: '%env(SENTRY_DSN)%' level: info # logs which will be shown as breadcrumbs in Sentry issue release: 1.0.0
- Add Sentry handler
releaseoption to monolog config for easy regression seeking:
monolog: handlers: ... sentry: ... release: '%env(APP_VERSION)%' # version tag or any release ID
License
MonologSentryBundle is released under the MIT license.
dziki/monolog-sentry-bundle 适用场景与选型建议
dziki/monolog-sentry-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78.87k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2018 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「symfony」 「monolog」 「logger」 「bundle」 「sentry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dziki/monolog-sentry-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dziki/monolog-sentry-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dziki/monolog-sentry-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
The bundle for easy using json-rpc api on your project
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
统计信息
- 总下载量: 78.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-23

