facile-it/sentry-module 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

facile-it/sentry-module

Composer 安装命令:

composer require facile-it/sentry-module

包简介

This module allows integration of Sentry Client into laminas and mezzio

README 文档

README

This module allows integration with Sentry Client into laminas and mezzio.

Installation

The only supported way to install this module is trough composer. For composer documentation you can refer to getcomposer.org.

Install with implementations of php-http/async-client-implementation and psr/http-message-implementation:

php composer.phar require facile-it/sentry-module php-http/curl-client laminas/laminas-diactoros

Configuration

Client

To configure an instance of the client you can do as below:

return [
    'sentry' => [
        'disable_module' => false,
        'options' => [
            'dsn' => '',
            // other sentry options
            // https://docs.sentry.io/error-reporting/configuration/?platform=php
        ],
        'javascript' => [
            'inject_script' => false,
            'script' => [
                'src' => 'https://browser.sentry-cdn.com/5.6.3/bundle.min.js',
                'integrity' => 'sha384-/Cqa/8kaWn7emdqIBLk3AkFMAHBk0LObErtMhO+hr52CntkaurEnihPmqYj3uJho',
                'crossorigin' => 'anonymous',
            ],
            'options' => [
                'dsn' => '',
                // other sentry options
                // https://docs.sentry.io/error-reporting/configuration/?platform=php
            ],
        ],
    ],
];
//...

Now you can use the client and the Hub by retrieving it from the Service Locator.

use Sentry\HubInterface;

$hub = $this->getServiceLocator()->get(HubInterface::class);

Error Handler Listener

This module provides a listener for MvcEvent::EVENT_DISPATCH_ERROR and MvcEvent::EVENT_RENDER_ERROR events in order to log the exceptions caught in these events.

If you want to use it you should register it in your application module.

Example:

<?php

namespace App;

use Facile\SentryModule\Listener\ErrorHandlerListener;
use Laminas\Mvc\MvcEvent;

class Module 
{
    public function onBootstrap(MvcEvent $e): void
    {
        $application = $e->getApplication();
        $container = $application->getServiceManager();
        $eventManager = $application->getEventManager();
        
        /** @var ErrorHandlerListener $errorHandlerListener */
        $errorHandlerListener = $container->get(ErrorHandlerListener::class);
        $errorHandlerListener->attach($eventManager);
    }
}

Log Writer

You can use our log writer to write logs.

Example:

<?php

// global.php
return [
    'log' => [
        'application.log' => [
            'writers' => [
                [
                    'name' => \Facile\SentryModule\Log\Writer\Sentry::class,
                    'options' => [
                        'filters' => [
                            [
                                'name' => 'priority',
                                'options' => [
                                    'priority' => \Laminas\Log\Logger::ERR,
                                ],
                            ],
                        ],
                    ],
                ],
            ]
        ],
    ],
];

Usage:

$logger->crit('Log this message');

// or with exceptions, to see the correct trace in sentry:
$e = new \RuntimeException('test-exception');
$logger->crit($e->getMessage(), ['exception' => $e]);

Javascript

This module can inject the javascript Raven client library and configure it for you.

<?php

// facile-sentry.module.local.php
return [
    'sentry' => [
        'javascript' => [
            'inject_script' => true, // enable it
            'options' => [
                'dsn' => '',
                // other sentry options
                // https://docs.sentry.io/error-reporting/configuration/?platform=php
            ],
            // script options (defaults)
            'script' => [
                'src' => 'https://browser.sentry-cdn.com/5.6.3/bundle.min.js',
                'integrity' => 'sha384-/Cqa/8kaWn7emdqIBLk3AkFMAHBk0LObErtMhO+hr52CntkaurEnihPmqYj3uJho',
                'crossorigin' => 'anonymous',
            ],
        ],
    ],
];

In your layout:

<?= $this->headScript() ?>

Usage with Mezzio (ex zend-expressive)

If you want to use it with Mezzio you should initialize the Sentry client and Hub. You can simply retrieve the HubInterface service to initialize it.

use Sentry\HubInterface;

$container->get(HubInterface::class);

facile-it/sentry-module 适用场景与选型建议

facile-it/sentry-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 397.33k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2015 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 facile-it/sentry-module 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 19
  • Watchers: 4
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-22