Spectator Package
Spectator is a BEAM observer tool written in Gleam, that plays well with gleam_otp processes.
This is the spectator package, published on hex, which allows you to run spectator from within your application, which is useful for development.
If you want to use spectator to inspect a deployed production application instead, please see the main README.
Use Spectator in Development
gleam add spectator
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.
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()
}
For an overview of spectator itself, please see the main README.