Spectator

Package Version Hex Docs

Spectator is a BEAM observer tool written in Gleam, that plays well with gleam_otp processes.

Note

This is a work in progress, so far it has the following features:

The goal is to extend it with these features in the future:

Installation

gleam add spectator@1

Usage

🦔 Spectator is a tool intended to be used for debugging and inspecting applications in development, you should not include spectator in your production application

Call spectator.start() in your application, to start the spectator service and WebUI.

In order to make it easier to identify your Gleam processes in the process list, you can tag them with a friendly name with spectator.tag, spectator.tag_subject or spectator.tag_result after starting the spectator service.

Example

import gleam/erlang/process
import spectator
import utils/pantry

pub fn main() {
  // Start the spectator service
  let assert Ok(_) = spectator.start()

  // Start an OTP actor
  let assert Ok(sub) = pantry.new()

  // Tag the actor with a name for easier identification in the spectator UI
  // Note: this only works because we called spectator.start before!
  sub
  |> spectator.tag_subject("Pantry Actor")

  // Add some state to the actor
  pantry.add_item(sub, "This actor has some state")
  pantry.add_item(sub, "Another item in the state of this actor")
  pantry.add_item(sub, "And some more state I've put into this demo actor")

  // Sleep on the main process so the program doesn't exit
  process.sleep_forever()
}

Further documentation can be found at https://hexdocs.pm/spectator.

Search Document