# `Spectre.Monitor`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/monitor.ex#L1)

Failure boundary for host delivery around a Spectre agent.

`Spectre.Monitor` wraps host delivery code and creates a fallback through
injected callbacks when that code fails. This keeps databases, queues, and
transport APIs outside the runtime while still giving applications one place
to produce a user-safe failure response. Operational logs contain only
digested identifiers and bounded value or failure classes.

# `callback_result`

```elixir
@type callback_result() :: {:ok, map()} | {:error, term()}
```

# `context`

```elixir
@type context() :: map()
```

# `dispatch`

```elixir
@spec dispatch(module(), context(), keyword()) :: callback_result()
```

Runs a monitored host operation and creates a fallback when it fails.

    Spectre.Monitor.dispatch(MyAgent, context,
      run: fn -> deliver_turn.() end,
      fallback_exists?: &MyApp.Fallbacks.exists?/1,
      create_fallback: &MyApp.Fallbacks.create/3
    )

# `fallback_text`

```elixir
@spec fallback_text(module(), context(), term(), keyword()) ::
  {:ok, String.t()} | {:error, term()}
```

Renders the configured failure fallback prompt.

    {:ok, text} = Spectre.Monitor.fallback_text(MyAgent, context, :timeout)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
