# `DalaDev.Remote`
[🔗](https://github.com/manhvu/dala_dev/blob/main/lib/dala_dev/remote.ex#L1)

Easy remote debugging and tracing interface for dala Elixir cluster nodes.

Provides a simple interface to debug and trace remote nodes without needing
to manually handle RPC calls or node selection.

## Usage

### Select a node

    iex> DalaDev.Remote.select_node(:"dala_demo@127.0.0.1")
    :ok

### List available nodes

    iex> DalaDev.Remote.nodes()
    [node1@host, node2@host]

### Call remote functions

    iex> DalaDev.Remote.Observer.observe()
    {:ok, %{system: %{...}, processes: [...], ...}}

    iex> DalaDev.Remote.Debugger.memory_report()
    {:ok, %{total: "1.2 GB", processes: "45 MB", ...}}

    iex> DalaDev.Remote.Debugger.inspect_process(MyApp.Worker)
    {:ok, %{pid: "#PID<0.123.0>", state: "...", ...}}

    iex> DalaDev.Remote.Debugger.eval("1 + 1")
    {:ok, 2}

    iex> DalaDev.Remote.Tracer.trace_messages(MyApp.Worker, duration: 5000)
    {:ok, [%{type: :send, message: "..."}, ...]}

### Set custom timeout

    iex> DalaDev.Remote.set_timeout(10_000)
    :ok

### Get current selection

    iex> DalaDev.Remote.selected_node()
    {:ok, node()}

## Automatic Node Selection

If only one remote node is available, it will be automatically selected.
If multiple nodes are available, you must explicitly select one.

## Default Timeout

The default timeout for all remote operations is 5000ms (5 seconds).
This can be changed using `set_timeout/1`.

# `auto_select`

```elixir
@spec auto_select() :: {:ok, node()} | {:error, term()}
```

Automatically selects a node if only one is available.

Returns `{:ok, node}` if auto-selected, `{:error, reason}` otherwise.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear_selection`

```elixir
@spec clear_selection() :: :ok
```

Clears the currently selected node.

Returns `:ok`.

# `get_timeout`

```elixir
@spec get_timeout() :: non_neg_integer()
```

Gets the current timeout setting.

Returns the timeout in milliseconds.

# `nodes`

```elixir
@spec nodes() :: [node()]
```

Lists all connected remote nodes (excluding the current node).

# `select_node`

```elixir
@spec select_node(node() | String.t()) :: :ok | {:error, term()}
```

Selects a node for subsequent remote operations.

Returns `:ok` on success, `{:error, reason}` on failure.

# `selected_node`

```elixir
@spec selected_node() :: {:ok, node()} | {:error, :no_node_selected}
```

Gets the currently selected node.

Returns `{:ok, node}` if a node is selected, `{:error, :no_node_selected}` otherwise.

# `set_timeout`

```elixir
@spec set_timeout(non_neg_integer()) :: :ok
```

Sets the default timeout for remote operations.

Returns `:ok`.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the Remote helper.

This is automatically started by the application supervisor.

---

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