friendsofhyperf/sentry
Composer 安装命令:
composer require friendsofhyperf/sentry
包简介
The sentry component for Hyperf.
README 文档
README
Sentry component for Hyperf. It integrates the Sentry PHP SDK with Hyperf application lifecycle events, logs, tracing, metrics, crons, and coroutine-friendly transport.
Installation
composer require friendsofhyperf/sentry
Optional integrations require the related Hyperf or client packages, for example
hyperf/amqp, hyperf/crontab, hyperf/database, hyperf/rpc-multiplex,
elasticsearch/elasticsearch, phpmyadmin/sql-parser, or hyperf/engine.
Publish Configuration
php bin/hyperf.php vendor:publish friendsofhyperf/sentry
This publishes config/autoload/sentry.php. The core settings are:
<?php return [ 'dsn' => env('SENTRY_DSN', ''), 'release' => env('SENTRY_RELEASE'), 'environment' => env('APP_ENV', 'production'), 'sample_rate' => env('SENTRY_SAMPLE_RATE') === null ? 1.0 : (float) env('SENTRY_SAMPLE_RATE'), 'traces_sample_rate' => env('SENTRY_TRACES_SAMPLE_RATE') === null ? 1.0 : (float) env('SENTRY_TRACES_SAMPLE_RATE'), 'profiles_sample_rate' => env('SENTRY_PROFILES_SAMPLE_RATE') === null ? null : (float) env('SENTRY_PROFILES_SAMPLE_RATE'), 'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', true), ];
The configuration file also accepts Sentry SDK options such as server_name,
traces_sampler, before_send_log, before_send_metric,
before_send_check_in, before_send_transaction, ignore_exceptions, and
ignore_transactions.
Logs
The component registers a logger.channels.sentry channel with
FriendsOfHyperf\Sentry\Monolog\LogsHandler when no Sentry logger channel is
already configured. Configure the minimum level with:
SENTRY_ENABLE_LOGS=true SENTRY_LOGS_CHANNEL_LEVEL=debug
To send diagnostic logs produced by the Sentry SDK itself, configure a PSR logger:
<?php return [ 'logger' => Hyperf\Contract\StdoutLoggerInterface::class, ];
Commands
php bin/hyperf.php sentry:about php bin/hyperf.php sentry:test php bin/hyperf.php sentry:test --dsn=https://examplePublicKey@o0.ingest.sentry.io/0 php bin/hyperf.php sentry:test --transaction=1
sentry:about prints SDK, DSN, environment, release, sample rate, and PII status.
sentry:test sends a test exception and can also send a test transaction.
Annotations
<?php use FriendsOfHyperf\Sentry\Annotation\Breadcrumb; use FriendsOfHyperf\Sentry\Annotation\Graceful; use FriendsOfHyperf\Sentry\Annotation\IgnoreException; use FriendsOfHyperf\Sentry\Metrics\Annotation\Counter; use FriendsOfHyperf\Sentry\Metrics\Annotation\Histogram; use FriendsOfHyperf\Sentry\Tracing\Annotation\Trace; #[IgnoreException] class IgnoredDomainException extends RuntimeException { } class UserService { #[Breadcrumb(category: 'user')] #[Trace(op: 'service.user', description: 'Create user')] #[Counter('user_create_total')] #[Histogram('user_create_duration')] public function create(array $payload): void { // ... } #[Graceful(strategy: Graceful::STRATEGY_SWALLOW, report: true)] public function reportableFallback(): mixed { // ... } }
Available graceful strategies are swallow, rethrow, fallback, and
translate.
Tracing
The component enables tracing by default and can continue trace context across HTTP, RPC, queue, Kafka, AMQP, crontab, command, and coroutine boundaries.
SENTRY_TRACING_ENABLE_AMQP=true SENTRY_TRACING_ENABLE_ASYNC_QUEUE=true SENTRY_TRACING_ENABLE_COMMAND=true SENTRY_TRACING_ENABLE_COROUTINE=true SENTRY_TRACING_ENABLE_CRONTAB=true SENTRY_TRACING_ENABLE_KAFKA=true SENTRY_TRACING_ENABLE_MISSING_ROUTES=true SENTRY_TRACING_ENABLE_REQUEST=true SENTRY_TRACING_SPANS_CACHE=true SENTRY_TRACING_SPANS_COORDINATOR=false SENTRY_TRACING_SPANS_COROUTINE=true SENTRY_TRACING_SPANS_DB=true SENTRY_TRACING_SPANS_ELASTICSEARCH=true SENTRY_TRACING_SPANS_FILESYSTEM=true SENTRY_TRACING_SPANS_GRPC=true SENTRY_TRACING_SPANS_GUZZLE=true SENTRY_TRACING_SPANS_REDIS=true SENTRY_TRACING_SPANS_RPC=true SENTRY_TRACING_SPANS_SQL_QUERIES=true SENTRY_TRACING_SPANS_VIEW=true
Use ignore_commands and ignore_transactions in config/autoload/sentry.php
to exclude noisy commands or routes. Use tracing_tags to control optional span
data such as SQL bindings, results, or response bodies.
Manual instrumentation is available through helper functions:
<?php use Sentry\Tracing\SpanContext; use function FriendsOfHyperf\Sentry\trace; trace(function () { return doSomething(); }, SpanContext::make()->setOp('task')->setDescription('Do something'));
Metrics
SENTRY_ENABLE_METRICS=true SENTRY_ENABLE_DEFAULT_METRICS=true SENTRY_ENABLE_COMMAND_METRICS=true SENTRY_ENABLE_POOL_METRICS=true SENTRY_ENABLE_QUEUE_METRICS=true SENTRY_METRICS_INTERVAL=10
Default metrics cover request timing, coroutine server stats, command timing,
database and Redis pools, and async queues when the related packages are present.
#[Counter] and #[Histogram] add method-level custom metrics.
Crons
Hyperf crontab events can be reported as Sentry check-ins:
SENTRY_CRONS_ENABLE=true SENTRY_CRONS_CHECKIN_MARGIN=5 SENTRY_CRONS_MAX_RUNTIME=15 SENTRY_CRONS_TIMEZONE=UTC
Per-crontab options can override checkin_margin, max_runtime,
failure_issue_threshold, recovery_threshold, and update_monitor_config.
Set monitor to false on a crontab to skip check-ins for that task.
Transport
The default binding uses FriendsOfHyperf\Sentry\Transport\CoHttpTransport.
Tune its queue and concurrency with:
SENTRY_TRANSPORT_CHANNEL_SIZE=65535 SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000 SENTRY_HTTP_TIMEOUT=2.0
Sentry Development Documentation
- OpenTelemetry Semantic Conventions semantic-conventions
- Sentry Span Operations Naming Standards span-operations
Contact
License
friendsofhyperf/sentry 适用场景与选型建议
friendsofhyperf/sentry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75.54k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2022 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sentry」 「hyperf」 「v3.2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 friendsofhyperf/sentry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 friendsofhyperf/sentry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 friendsofhyperf/sentry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fork of a PHP client for Sentry (http://getsentry.com) that work also with php5.2
An implementation of the Sentry User Manager for Laravel.
An async event for hyperf.
Simple Yii2 Sentry target for logging (http://getsentry.com)
Monitoring for scheduled jobs
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 75.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-28