Skip to content
Open
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
18 changes: 18 additions & 0 deletions src/SentrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Logs\Logs;
use Sentry\Metrics\TraceMetrics;
use Sentry\State\Hub;
use Sentry\State\HubInterface;

Expand Down Expand Up @@ -61,4 +63,20 @@ public static function setCurrentHub(HubInterface $hub): HubInterface

return $hub;
}

/**
* Flushes all buffered telemetry data.
*
* This is a convenience facade that forwards the flush operation to all
* internally managed components.
*
* Calling this method is equivalent to invoking `flush()` on each component
* individually. It does not change flushing behavior, improve performance,
* or reduce the number of network requests.
*/
public static function flush(): void
{
Logs::getInstance()->flush();
TraceMetrics::getInstance()->flush();
}
Comment on lines +78 to +81
Copy link

Choose a reason for hiding this comment

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

Bug: The new SentrySdk::flush() method does not flush the main transport layer, which can lead to buffered events like errors and exceptions being lost upon application exit.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The new SentrySdk::flush() method is incomplete. It calls flush() on Logs and TraceMetrics, but it does not flush the main transport layer where events from captureMessage(), captureException(), and captureEvent() are buffered. Users calling this convenience method will expect all telemetry to be sent, but because the transport is not flushed, any buffered events could be lost if the application exits. This contradicts the stated goal of the method, which is to provide a single facade to flush all individual resources.

💡 Suggested Fix

Update SentrySdk::flush() to also flush the transport layer. This can be achieved by getting the current client from the hub and calling its flush() method, like so: SentrySdk::getCurrentHub()->getClient()->flush($timeout);.

🤖 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/SentrySdk.php#L78-L81

Potential issue: The new `SentrySdk::flush()` method is incomplete. It calls `flush()`
on `Logs` and `TraceMetrics`, but it does not flush the main transport layer where
events from `captureMessage()`, `captureException()`, and `captureEvent()` are buffered.
Users calling this convenience method will expect all telemetry to be sent, but because
the transport is not flushed, any buffered events could be lost if the application
exits. This contradicts the stated goal of the method, which is to provide a single
facade to flush all individual resources.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7703038

}
15 changes: 15 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,18 @@ function addFeatureFlag(string $name, bool $result): void
$scope->addFeatureFlag($name, $result);
});
}

/**
* Flushes all buffered telemetry data.
*
* This is a convenience facade that forwards the flush operation to all
* internally managed components.
*
* Calling this method is equivalent to invoking `flush()` on each component
* individually. It does not change flushing behavior, improve performance,
* or reduce the number of network requests.
*/
function flush(): void
{
SentrySdk::flush();
}