feat(scope): update aggregator flush to use a client#2125
Conversation
| $event = Event::createLogs()->setLogs($logs->drain()); | ||
|
|
||
| return $hub->captureEvent($event); | ||
| return $client->captureEvent($event); |
There was a problem hiding this comment.
Bug: The direct call to client->captureEvent($event) during flush operations bypasses the hub, causing the event to be sent with a null scope and losing all contextual data.
Severity: HIGH
Suggested Fix
Instead of passing the Client to the flush methods in LogsAggregator and MetricsAggregator, pass the Hub instance. Then, inside the flush method, call hub->captureEvent($event) instead of $client->captureEvent($event). This will ensure that the event is processed with the correct scope from the hub before being sent.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/Logs/LogsAggregator.php#L178
Potential issue: The refactoring in `LogsAggregator::flush()` and
`MetricsAggregator::flush()` now calls `$client->captureEvent($event)` directly, instead
of going through the hub. This bypasses the mechanism that attaches the current scope to
the event. As a result, when logs or metrics are flushed, all scope-level context—such
as user data, tags, breadcrumbs, and trace information—is lost. The events are sent
without this critical enrichment, which severely degrades their value for debugging and
analysis. The previous implementation correctly used `$hub->captureEvent()`, which
ensured the scope was applied.
Also affects:
src/Metrics/MetricsAggregator.php:143~143
Did we get this right? 👍 / 👎 to inform future reviews.
db6e223 to
14d6804
Compare
8d1c6f0 to
4d924bf
Compare
14d6804 to
0352e56
Compare
4d924bf to
471adb8
Compare
0352e56 to
3a5d496
Compare
471adb8 to
52283d4
Compare
3a5d496 to
0f25f5f
Compare
52283d4 to
7958239
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7958239. Configure here.
| $event = Event::createLogs()->setLogs($logs->drain()); | ||
|
|
||
| return $hub->captureEvent($event); | ||
| return $client->captureEvent($event); |
There was a problem hiding this comment.
Flush skips hub scope enrichment
Medium Severity
LogsAggregator and MetricsAggregator now send batched telemetry via Client::captureEvent without the hub scope. Previously Hub::captureEvent passed $this->getScope() into prepareEvent, so scope event processors, tags, and other scope enrichment no longer run on flush.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7958239. Configure here.


This PR removes the
Hubfrom the flush signature and replaces it with theClient