class Hub implements HubInterface

The SDK's Hub with a layer stack per coroutine instead of per instance.

Each coroutine starts from a copy of the baseline scope, and child coroutines inherit a copy of their parent's stack. Compare this class with Sentry\State\Hub on every SDK update.

Constants

CONTEXT_STACK_KEY

CONTEXT_LAST_EVENT_ID_KEY

Properties

protected Scope $scope

Methods

__construct(ClientInterface|null $client = null, Scope|null $scope = null)

Create a new Hub instance.

ClientInterface|null
getClient()

Get the client bound to the hub.

void
bindClient(ClientInterface $client)

Bind a new client to the hub.

EventId|null
getLastEventId()

Get the ID of the last event captured in the current coroutine.

Scope
pushScope()

Push a copy of the current scope onto the current coroutine's stack.

bool
popScope()

Remove the most recently pushed scope from the current coroutine's stack.

EventId|null
captureMessage(string $message, Severity|null $level = null, EventHint|null $hint = null)

Capture a message event and send it to Sentry.

EventId|null
captureException(Throwable $exception, EventHint|null $hint = null)

Capture an exception event and send it to Sentry.

EventId|null
captureEvent(Event $event, EventHint|null $hint = null)

Capture a new event using the provided data.

EventId|null
captureLastError(EventHint|null $hint = null)

Capture an event for the last error that occurred.

bool
addBreadcrumb(Breadcrumb $breadcrumb)

Record a breadcrumb that will be attached to future events.

bool
addAttachment(Attachment $attachment)

Add an attachment to the current scope.

void
configureScope(callable $callback)

Pass the current scope to the callback, or the baseline scope before the application boots.

Transaction
startTransaction(TransactionContext $context, array $customSamplingContext = [])

Start a new transaction and decide whether it is sampled and profiled.

Transaction|null
getTransaction()

Get the transaction on the current scope.

HubInterface
setSpan(Span|null $span)

Set the span on the current scope.

Span|null
getSpan()

Get the span on the current scope.

mixed
withScope(callable $callback)

Run the callback with a new scope that is removed afterwards.

string|null
captureCheckIn(string $slug, CheckInStatus $status, mixed $duration = null, MonitorConfig|null $monitorConfig = null, string|null $checkInId = null)

Capture a check-in.

IntegrationInterface|null
getIntegration(string $className)

Get the client's integration with the given class name.

Scope
getScope()

Get the scope at the top of the current coroutine's stack.

Details

at line 52
__construct(ClientInterface|null $client = null, Scope|null $scope = null)

Create a new Hub instance.

Parameters

ClientInterface|null $client
Scope|null $scope

at line 60
ClientInterface|null getClient()

Get the client bound to the hub.

Return Value

ClientInterface|null

at line 71
void bindClient(ClientInterface $client)

Bind a new client to the hub.

On the shared Hub, per-request use races across coroutines, and existing coroutine layer stacks may already hold the previous client.

Parameters

ClientInterface $client

Return Value

void

at line 80
EventId|null getLastEventId()

Get the ID of the last event captured in the current coroutine.

Return Value

EventId|null

at line 88
Scope pushScope()

Push a copy of the current scope onto the current coroutine's stack.

Return Value

Scope

at line 101
bool popScope()

Remove the most recently pushed scope from the current coroutine's stack.

Return Value

bool

at line 118
EventId|null captureMessage(string $message, Severity|null $level = null, EventHint|null $hint = null)

Capture a message event and send it to Sentry.

Parameters

string $message
Severity|null $level
EventHint|null $hint

Return Value

EventId|null

at line 135
EventId|null captureException(Throwable $exception, EventHint|null $hint = null)

Capture an exception event and send it to Sentry.

Parameters

Throwable $exception
EventHint|null $hint

Return Value

EventId|null

at line 152
EventId|null captureEvent(Event $event, EventHint|null $hint = null)

Capture a new event using the provided data.

Parameters

Event $event
EventHint|null $hint

Return Value

EventId|null

at line 169
EventId|null captureLastError(EventHint|null $hint = null)

Capture an event for the last error that occurred.

Parameters

EventHint|null $hint

Return Value

EventId|null

at line 183
bool addBreadcrumb(Breadcrumb $breadcrumb)

Record a breadcrumb that will be attached to future events.

Parameters

Breadcrumb $breadcrumb

Return Value

bool

at line 221
bool addAttachment(Attachment $attachment)

Add an attachment to the current scope.

Parameters

Attachment $attachment

Return Value

bool

at line 235
void configureScope(callable $callback)

Pass the current scope to the callback, or the baseline scope before the application boots.

Parameters

callable $callback

Return Value

void

at line 254
Transaction startTransaction(TransactionContext $context, array $customSamplingContext = [])

Start a new transaction and decide whether it is sampled and profiled.

Parameters

TransactionContext $context
array $customSamplingContext

Additional context that will be passed to the {\Sentry\Tracing\SamplingContext}

Return Value

Transaction

at line 436
Transaction|null getTransaction()

Get the transaction on the current scope.

Return Value

Transaction|null

at line 444
HubInterface setSpan(Span|null $span)

Set the span on the current scope.

Parameters

Span|null $span

Return Value

HubInterface

at line 454
Span|null getSpan()

Get the span on the current scope.

Return Value

Span|null

at line 468
mixed withScope(callable $callback)

Run the callback with a new scope that is removed afterwards.

Parameters

callable $callback

Return Value

mixed

at line 484
string|null captureCheckIn(string $slug, CheckInStatus $status, mixed $duration = null, MonitorConfig|null $monitorConfig = null, string|null $checkInId = null)

Capture a check-in.

Parameters

string $slug
CheckInStatus $status
mixed $duration
MonitorConfig|null $monitorConfig
string|null $checkInId

Return Value

string|null

at line 523
IntegrationInterface|null getIntegration(string $className)

Get the client's integration with the given class name.

Parameters

string $className

Return Value

IntegrationInterface|null

at line 533
protected Scope getScope()

Get the scope at the top of the current coroutine's stack.

Return Value

Scope