Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/en/components/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,24 @@ 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:
The default binding uses `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`. It uses a bounded
queue and a fixed worker pool:

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` fails fast and drops telemetry when the queue is full, protecting
application memory when Sentry or the network is slow. Use a small positive value for bounded
backpressure. `CoHttpTransport::getStats()` exposes accepted, dropped, queued, in-flight, and worker
counts.

Published configuration files are not overwritten during upgrades. If an existing application still
uses the previous `65535`, `1000`, and `-1` values, update them manually to enable the bounded defaults.

## Sentry Development Documentation

- OpenTelemetry Semantic Conventions [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
16 changes: 12 additions & 4 deletions docs/zh-cn/components/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,23 @@ SENTRY_CRONS_TIMEZONE=UTC

## 传输

默认绑定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。使用下面的环境
变量调整队列和并发
默认绑定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。它使用有界队列和固定
worker 池

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` 会在队列已满时立即失败并丢弃遥测数据,避免 Sentry 或网络变慢
时持续占用应用内存。如需有限背压,可设置较小的正数。`CoHttpTransport::getStats()` 可查看已接收、
已丢弃、排队中、发送中和 worker 数量。

升级不会覆盖已经发布的配置文件。如果现有应用仍使用之前的 `65535`、`1000` 和 `-1`,需手动
更新这些值才能启用新的有界默认配置。

## Sentry 开发文档

- OpenTelemetry 语义约定 [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
16 changes: 12 additions & 4 deletions docs/zh-hk/components/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,23 @@ SENTRY_CRONS_TIMEZONE=UTC

## 傳輸

默認綁定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。使用下面的環境
變量調整隊列和併發
默認綁定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。它使用有界隊列和固定
worker 池

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` 會在隊列已滿時立即失敗並丟棄遙測數據,避免 Sentry 或網絡變慢
時持續佔用應用內存。如需有限背壓,可設置較小的正數。`CoHttpTransport::getStats()` 可查看已接收、
已丟棄、排隊中、發送中和 worker 數量。

升級不會覆蓋已經發布的配置文件。如果現有應用仍使用之前的 `65535`、`1000` 和 `-1`,需手動
更新這些值才能啓用新的有界默認配置。

## Sentry 開發文檔

- OpenTelemetry 語義約定 [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
16 changes: 12 additions & 4 deletions docs/zh-tw/components/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,23 @@ SENTRY_CRONS_TIMEZONE=UTC

## 傳輸

預設繫結使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。使用下面的環境
變數調整佇列和併發
預設繫結使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。它使用有界佇列和固定
worker 池

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` 會在佇列已滿時立即失敗並丟棄遙測資料,避免 Sentry 或網路變慢
時持續佔用應用記憶體。如需有限背壓,可設定較小的正數。`CoHttpTransport::getStats()` 可檢視已接收、
已丟棄、排隊中、傳送中和 worker 數量。

升級不會覆蓋已經發布的配置檔案。如果現有應用仍使用之前的 `65535`、`1000` 和 `-1`,需手動
更新這些值才能啟用新的有界預設配置。

## Sentry 開發文件

- OpenTelemetry 語義約定 [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
17 changes: 13 additions & 4 deletions src/sentry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,24 @@ 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:
The default binding uses `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`. It uses a bounded
queue and a fixed worker pool:

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` fails fast and drops telemetry when the queue is full, protecting
application memory when Sentry or the network is slow. Use a small positive value for bounded
backpressure. `CoHttpTransport::getStats()` exposes accepted, dropped, queued, in-flight, and worker
counts.

Published configuration files are not overwritten during upgrades. If an existing application still
uses the previous `65535`, `1000`, and `-1` values, update them manually to enable the bounded defaults.

## Sentry Development Documentation

- OpenTelemetry Semantic Conventions [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
16 changes: 12 additions & 4 deletions src/sentry/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,23 @@ SENTRY_CRONS_TIMEZONE=UTC

## 传输

默认绑定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。使用下面的环境
变量调整队列和并发
默认绑定使用 `FriendsOfHyperf\Sentry\Transport\CoHttpTransport`。它使用有界队列和固定
worker 池

```env
SENTRY_TRANSPORT_CHANNEL_SIZE=65535
SENTRY_TRANSPORT_CONCURRENT_LIMIT=1000
SENTRY_TRANSPORT_CHANNEL_SIZE=512
SENTRY_TRANSPORT_CONCURRENT_LIMIT=32
SENTRY_TRANSPORT_TIMEOUT=0
SENTRY_HTTP_TIMEOUT=2.0
```

`SENTRY_TRANSPORT_TIMEOUT=0` 会在队列已满时立即失败并丢弃遥测数据,避免 Sentry 或网络变慢
时持续占用应用内存。如需有限背压,可设置较小的正数。`CoHttpTransport::getStats()` 可查看已接收、
已丢弃、排队中、发送中和 worker 数量。

升级不会覆盖已经发布的配置文件。如果现有应用仍使用之前的 `65535`、`1000` 和 `-1`,需手动
更新这些值才能启用新的有界默认配置。

## Sentry 开发文档

- OpenTelemetry 语义约定 [semantic-conventions](https://github.com/open-telemetry/semantic-conventions/tree/main)
Expand Down
9 changes: 5 additions & 4 deletions src/sentry/publish/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@
'timezone' => env('SENTRY_CRONS_TIMEZONE', date_default_timezone_get()),
],

// Transport configuration
'transport_channel_size' => (int) env('SENTRY_TRANSPORT_CHANNEL_SIZE', 65535),
'transport_concurrent_limit' => (int) env('SENTRY_TRANSPORT_CONCURRENT_LIMIT', 1000),
'transport_timeout' => (float) env('SENTRY_TRANSPORT_TIMEOUT', -1),
// Transport configuration: bounded queue, fixed worker pool, and enqueue timeout in seconds.
// Keep the timeout at 0 to drop telemetry immediately when the queue is full.
'transport_channel_size' => (int) env('SENTRY_TRANSPORT_CHANNEL_SIZE', 512),
'transport_concurrent_limit' => (int) env('SENTRY_TRANSPORT_CONCURRENT_LIMIT', 32),
'transport_timeout' => (float) env('SENTRY_TRANSPORT_TIMEOUT', 0),

'http_timeout' => (float) env('SENTRY_HTTP_TIMEOUT', 2.0),
];
5 changes: 3 additions & 2 deletions src/sentry/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function __invoke(): array
],
'listeners' => [
Listener\SetupSentryListener::class,
Listener\EventHandleListener::class => PHP_INT_MAX - 1,
Listener\RequestContextLifecycleListener::class => PHP_INT_MAX,
Listener\EventHandleListener::class => PHP_INT_MAX - 2,
Crons\Listener\EventHandleListener::class => PHP_INT_MAX - 1,
Metrics\Listener\DBPoolWatcher::class,
Metrics\Listener\OnBeforeHandle::class,
Expand All @@ -67,7 +68,7 @@ public function __invoke(): array
Metrics\Listener\QueueWatcher::class,
Metrics\Listener\RedisPoolWatcher::class,
Metrics\Listener\RequestWatcher::class,
Tracing\Listener\EventHandleListener::class => PHP_INT_MAX, // !! Make sure it is the first one to handle the event
Tracing\Listener\EventHandleListener::class => PHP_INT_MAX - 1,
],
'annotations' => [
'scan' => [
Expand Down
44 changes: 44 additions & 0 deletions src/sentry/src/Listener/RequestContextLifecycleListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact huangdijia@gmail.com
*/
Comment on lines +4 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

在新 PHP 文件头中添加许可证信息。

当前文件头只包含项目链接和联系信息。请添加项目许可证声明。

  • src/sentry/src/Listener/RequestContextLifecycleListener.php#L4-L10:添加项目许可证信息。
  • tests/Sentry/RequestContextLifecycleListenerTest.php#L4-L10:添加相同的项目许可证信息。

As per coding guidelines,所有 PHP 文件头必须包含许可证信息。

📍 Affects 2 files
  • src/sentry/src/Listener/RequestContextLifecycleListener.php#L4-L10 (this comment)
  • tests/Sentry/RequestContextLifecycleListenerTest.php#L4-L10
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/sentry/src/Listener/RequestContextLifecycleListener.php` around lines 4 -
10, 为 src/sentry/src/Listener/RequestContextLifecycleListener.php 第4-10行及
tests/Sentry/RequestContextLifecycleListenerTest.php 第4-10行的 PHP
文件头补充项目许可证声明,两个文件使用一致的许可证信息,并保留现有项目链接、文档和联系信息。

Source: Coding guidelines


namespace FriendsOfHyperf\Sentry\Listener;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\HttpServer\Event as HttpEvent;
use Hyperf\RpcServer\Event as RpcEvent;
use Sentry\SentrySdk;

use function Hyperf\Coroutine\defer;

class RequestContextLifecycleListener implements ListenerInterface
{
public function listen(): array
{
return [
HttpEvent\RequestReceived::class,
RpcEvent\RequestReceived::class,
];
}

public function process(object $event): void
{
$previousContext = SentrySdk::getCurrentRuntimeContext();
SentrySdk::startContext();

if (SentrySdk::getCurrentRuntimeContext() === $previousContext) {
return;
}

// Register cleanup before the remaining request listeners add their deferred
// callbacks. Coroutine defers run in LIFO order, so the context is ended last.
defer(static fn () => SentrySdk::endContext());
}
}
Loading
Loading