定制 oneup/contao-sentry-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oneup/contao-sentry-bundle

Composer 安装命令:

composer require oneup/contao-sentry-bundle

包简介

This bundle provides an easy integration of sentry.io for Contao 4.4.x and newer.

README 文档

README

This Contao bundle provides an easy integration of sentry.io for Contao 4.13 and 5.x.

Author Software License Total Downloads

--

This is a "wrapper extension" for the sentry/sentry-symfony bundle.

Setup in the Contao Managed Edition

The basic integration is automatically configured to some sane defaults. To enable the integration, configure the SENTRY_DSN variable in your .env.local file.

Additionally, you can name the SENTRY_ENV in your .env.local file, which can be useful if you e.g. have a test and prod installation.

If you need to change any of the defaults, simply configure the sentry/sentry-symfony bundle according to the Documentation.

Manual configuration

If you do not use the Contao Managed Edition, you need to configure this bundle as you would configure the sentry/sentry-symfony bundle: Documentation

Special case before_send callback

In the sentry/sentry-symfony bundle, there can only be one service responsible for filtering events before sending them to sentry. You'd configure it like so:

sentry:
    options:
        before_send: 'my_service_id'

However, this conflicts with the idea of this bundle to be extensible. Hence, this bundle ships with a default callback that dispatches the BeforeSendEvent. Thus giving other extensions (or your app), the option to filter the events before sending, without replacing each other.

Usage:

use Oneup\ContaoSentryBundle\Event\BeforeSendEvent;
use Sentry\Event;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class SentryBeforeSendListener
{
    public function __invoke(BeforeSendEvent $beforeSendEvent): void
    {
        // Might have been unset already by a different listener
        $event = $beforeSendEvent->getEvent();
        if (null === $event) {
            return;
        }

        // Your custom logic
        if ($this->shouldEventBeIgnored($event)) {
            $beforeSendEvent->setEvent(null);
        }
    }
}

User feedback

On the other hand you might want to implement the User feedback feature of sentry. The user feedback is primarily useful to let the users know that you've gotten notified about the issue and to let users give the opportunity to add some comments.

In order to integrate this feature, you have to alter the error page template. Place a copy of vendor/contao/core-bundle/src/Resources/views/Error/layout.html.twig in the directory templates/ContaoCoreBundle/views/Error/.

Modify the copied template and place the following snippet just before the closing </body> tag:

{% set sentry_id = ''|sentry_last_event_id %}
{% if sentry_id %}
    <script src="https://browser.sentry-cdn.com/8.7.0/bundle.feedback.min.js"
            integrity="sha384-If5t0OtWMly236c4qvXxYalt8pOLHOj9qKZaXu/xDqMqJ5xmdMCwVwXP6dlPyALI"
            crossorigin="anonymous"></script>
    <script>
        Sentry.init({dsn: '{{ ''|sentry_dsn }}'});
        Sentry.showReportDialog({eventId: '{{ sentry_id }}'})

        // You can also bind the "show" method to an event, e.g. to open the modal on button click
        {#document.querySelector('.btn-report').addEventListener('click', function (e) {#}
        {#    e.preventDefault();#}
        {#    Sentry.showReportDialog({eventId: '{{ sentry_id }}'})#}
        {#});#}
    </script>
{% endif %}

User Feedback in action

Error tracking helper

The Oneup\ContaoSentryBundle\ErrorHandlingTrait adds useful Sentry helpers.

  • ErrorHandlingTrait::sentryOrThrow will either log an error/exception to sentry, or it will throw an exception if Sentry integration is not available (e.g. on localhost or in dev environment). It is mostly useful when running looping cronjobs, like synchronizing Contao with a remote system, so an error on syncing a record will not prevent the sync loop from finishing other records.

  • ErrorHandlingTraig::sentryCheckIn has been added for the new Sentry Cron job monitoring. Call sentryCheckIn() without argument to start a check in, and subsequently with a boolean true or false after the job has successfully run or failed.

oneup/contao-sentry-bundle 适用场景与选型建议

oneup/contao-sentry-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.34k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「error」 「sentry」 「tracking」 「raven」 「contao」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 oneup/contao-sentry-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 oneup/contao-sentry-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 oneup/contao-sentry-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-05