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
33 changes: 33 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,39 @@ $logger->pushHandler(new \Sentry\Monolog\LogsHandler());

To continue sending Monolog records to Sentry issues instead, use `Sentry\Monolog\LogToSentryIssueHandler` for log messages or `Sentry\Monolog\ExceptionToSentryIssueHandler` for exceptions.

### Hub APIs Removed

The Hub API has been removed. This includes:

- **Removed classes and interfaces:**
- `Sentry\State\Hub`
- `Sentry\State\HubAdapter`
- `Sentry\State\HubInterface`

- **Removed methods:**
- `SentrySdk::getCurrentHub()`
- `SentrySdk::setCurrentHub()`

The SDK now exposes runtime state directly through `SentrySdk`, global helpers, and `Scope`:

```php
// Before (4.x)
\Sentry\SentrySdk::getCurrentHub()->configureScope(static function (\Sentry\State\Scope $scope): void {
$scope->setTag('feature', 'checkout');
});

// After (5.0)
\Sentry\configureScope(static function (\Sentry\State\Scope $scope): void {
$scope->setTag('feature', 'checkout');
});
```

Use `SentrySdk::getClient()` for the active client, `SentrySdk::getGlobalScope()` for process-global data, and `SentrySdk::getIsolationScope()` for the current runtime isolation scope. Use the capture helpers such as `captureMessage()`, `captureException()`, and `captureEvent()` to send events.

Use `configureScope()` to mutate the current isolation scope, `withIsolationScope()` to run code with a temporary forked scope, and `startTransaction()` to start manual tracing instrumentation.

`SentrySdk::init()` no longer returns a Hub instance. It now returns `void`.

### Metrics API Removed

The entire Metrics API has been removed as it is no longer supported. This includes:
Expand Down
12 changes: 0 additions & 12 deletions analysis-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1368,18 +1368,6 @@ code = "possibly-invalid-argument"
message = '''Possible argument type mismatch for argument #1 of `Sentry\StacktraceBuilder::buildFromBacktrace`: expected `list<array{'args'?: array<array-key, mixed>, 'class'?: class-string, 'file'?: string, 'function'?: string, 'line'?: int, 'type'?: string}>`, but possibly received `array<array-key, mixed>`.'''
count = 1

[[issues]]
file = "src/State/Hub.php"
code = "mixed-operand"
message = "Right operand in `<` comparison has `mixed` type."
count = 1

[[issues]]
file = "src/State/Hub.php"
code = "possibly-null-operand"
message = "Left operand in `<` comparison might be `null` (type `float|null`)."
count = 1

[[issues]]
file = "src/State/Scope.php"
code = "impossible-condition"
Expand Down
2 changes: 0 additions & 2 deletions src/Integration/ModulesIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function setupOnce(): void
Scope::addGlobalEventProcessor(static function (Event $event): Event {
$integration = SentrySdk::getClient()->getIntegration(self::class);

// The integration could be bound to a client that is not the one
// attached to the current hub. If this is the case, bail out
if ($integration !== null) {
$event->setModules(self::getComposerPackages());
}
Expand Down
2 changes: 0 additions & 2 deletions src/Integration/TransactionIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public function setupOnce(): void
Scope::addGlobalEventProcessor(static function (Event $event, EventHint $hint): Event {
$integration = SentrySdk::getClient()->getIntegration(self::class);

// The client bound to the current hub, if any, could not have this
// integration enabled. If this is the case, bail out
if ($integration === null) {
return $event;
}
Expand Down
29 changes: 2 additions & 27 deletions src/SentrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Sentry\Logs\Logs;
use Sentry\Metrics\TraceMetrics;
use Sentry\State\HubAdapter;
use Sentry\State\HubInterface;
use Sentry\State\RuntimeContext;
use Sentry\State\RuntimeContextManager;
use Sentry\State\Scope;
Expand Down Expand Up @@ -37,38 +35,15 @@ private function __construct()
}

/**
* Initializes the SDK by binding the client to the global scope and reset
* Initializes the SDK by binding the client to the global scope and resetting
* the current local runtime state.
*/
public static function init(?ClientInterface $client = null): HubInterface
public static function init(?ClientInterface $client = null): void
{
if ($client !== null) {
self::getGlobalScope()->setClient($client);
}
self::$runtimeContextManager = new RuntimeContextManager();

return self::getCurrentHub();
}

public static function getCurrentHub(): HubInterface
{
return HubAdapter::getInstance();
}

/**
* Sets the current hub.
*
* If called while an explicit runtime context is active, the hub update is
* scoped to that active context only. Otherwise, it updates the baseline
* hub used by the global fallback context and future contexts.
*
* @param HubInterface $hub The hub to set
*/
public static function setCurrentHub(HubInterface $hub): HubInterface
{
self::getGlobalScope()->setClient($hub->getClient());

return $hub;
}

public static function getGlobalScope(): Scope
Expand Down
Loading