Packages

Typed events and timing spans for Pooka

Current section

Files

Jump to
tattle README.md
Raw

README.md

# Tattle

[![Package Version](https://img.shields.io/hexpm/v/tattle?style=for-the-badge&color=75618E)](https://hex.pm/packages/tattle)
[![Hex Docs](https://img.shields.io/website?url=https%3A%2F%2Ftattle.hexdocs.pm%2F&style=for-the-badge&label=hex&up_message=docs&up_color=FF891F&down_message=not%20found&down_color=lightgrey)](https://tattle.hexdocs.pm/)
[![Tests](https://img.shields.io/github/actions/workflow/status/peregrinefinch/tattle/test.yml?branch=main&style=for-the-badge&label=tests)](https://github.com/peregrinefinch/tattle/actions/workflows/test.yml)

Send typed events and measure work using a bus you pass to the code that needs it. Each bus fixes its metadata type. An HTTP service might use a record with a route and request ID, while a worker might use a job name.

```pooka
module main

import tattle.{Phase}

main() {
  let bus = tattle.new().attach("console", ["http"], fn(event) {
    match event.phase {
      Phase.Stop -> {
        echo #(event.name, event.metadata, event.duration_us)
        Nil
      }
      _ -> Nil
    }
  })

  tattle.span(bus, ["http", "request"], "/books", fn() { 200 })
}
```

`emit` sends an instant event and returns delivered and failed handler counts. `span` sends a start event followed by a stop or exception event. Its duration uses the monotonic clock in microseconds. The callback's value or exception propagates to the caller.

`attach` and `detach` return a new bus. An empty prefix matches all events, and attaching an existing ID replaces that handler. Matching handlers run synchronously in the caller, newest first. Keep them short and hand off slow work to a worker. A handler that raises is counted as failed, and the remaining handlers still run.

Run the suite with `pooka test`.

## Licence

Licensed under the [Apache License, Version 2.0](LICENSE).