# InstrumentationGuard

> Executes diagnostic observers without allowing their failures to alter application behavior.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Instrumentation](/docs/extensions/debug-core/reference/instrumentation/index.md) › InstrumentationGuard

| final readonly class | `PHPForge\Debug\Instrumentation\InstrumentationGuard` |
| --- | --- |
| Source | [`src/Instrumentation/InstrumentationGuard.php`](https://github.com/php-forge/debug-core/blob/main/src/Instrumentation/InstrumentationGuard.php#L13) |

Executes diagnostic observers without allowing their failures to alter application behavior.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a guard around an optional diagnostic failure observer. | `InstrumentationGuard` |
| [`observe()`](#method-observe) | Runs one diagnostic observer and reports, but never propagates, its failure. | `InstrumentationGuard` |
| [`report()`](#method-report) | Reports a failure that was already caught, keeping the handler itself fail-open. | `InstrumentationGuard` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(callable(Throwable): void|null $failureHandler = null)
```

Creates a guard around an optional diagnostic failure observer.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$failureHandler` | `callable(`[`Throwable`](https://www.php.net/manual/en/class.throwable.php)`): void\|null` | Optional observer for suppressed instrumentation errors. |

### observe() <span id="method-observe"></span>

```php
public function observe(callable(): void $observer): void
```

Runs one diagnostic observer and reports, but never propagates, its failure.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$observer` | `callable(): void` | Diagnostic side effect. |

### report() <span id="method-report"></span>

```php
public function report(Throwable $failure): void
```

Reports a failure that was already caught, keeping the handler itself fail-open.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$failure` | [`Throwable`](https://www.php.net/manual/en/class.throwable.php) | Suppressed instrumentation failure. |