Rulestead.Telemetry (rulestead v1.0.0)

Copy Markdown View Source

Telemetry helpers and the locked 1.x public event catalog for Rulestead.

Rulestead.Telemetry is stable in the 1.x contract (api_stability.md — "Stable rulestead Modules"). It wraps :telemetry with Rulestead-aware metadata normalisation and provides the canonical event names emitted by the runtime.

Event Catalog (stable, 1.x)

All events follow the [:rulestead | rest] prefix convention.

EventWhen emitted
[:rulestead, :eval, :decide, :stop]After every flag evaluation
[:rulestead, :admin, :scheduled_execution, :*]Scheduled governance executions
[:rulestead, :admin, :webhook_outbound, :*]Outbound webhook deliveries

Event names and their documented metadata keys are stable for 1.x. Adding a new event name is a minor change; removing or renaming one is a breaking change.

Attaching handlers

Rulestead.Telemetry.attach_many(
  "my-app-rulestead-handler",
  [[:rulestead, :eval, :decide, :stop]],
  &MyApp.Telemetry.handle_event/4,
  nil
)

Use detach/1 with the same handler ID to remove a handler.

Internal use

span/3, execute/3, and the *_metadata helpers are used internally by the Rulestead runtime. They are part of the public module but primarily exist to normalise metadata; most adopters only need attach_many/4 and detach/1.

Summary

Types

event_name()

@type event_name() :: [atom()]

event_prefix()

@type event_prefix() :: [atom()]

metadata()

@type metadata() :: map()

Functions

attach_many(handler_id, events, function, config)

@spec attach_many(term(), [event_name()], :telemetry.handler_function(), term()) ::
  :ok | {:error, term()}

base_metadata(flag_payload, context, attrs \\ %{})

@spec base_metadata(
  map() | nil,
  Rulestead.Context.t() | map() | keyword() | nil,
  map()
) :: map()

command_metadata(command, attrs \\ %{})

@spec command_metadata(
  struct(),
  map()
) :: map()

detach(handler_id)

@spec detach(term()) :: :ok

dispatch(event, measurements, metadata, registered_event)

@spec dispatch(event_name(), map(), metadata(), event_name()) :: :ok

execute(event_name, measurements, metadata)

@spec execute(event_name(), map(), metadata()) :: :ok

governance_metadata(command, attrs \\ %{})

@spec governance_metadata(
  struct(),
  map()
) :: map()

guardrail_metadata(guardrail, attrs \\ %{})

@spec guardrail_metadata(map(), map()) :: map()

metadata(attrs)

@spec metadata(map()) :: map()

result_metadata(result, context, attrs \\ %{})

@spec result_metadata(
  Rulestead.Result.t(),
  Rulestead.Context.t() | map() | keyword() | nil,
  map()
) ::
  map()

runtime_metadata(runtime_metadata, attrs \\ %{})

@spec runtime_metadata(map(), map()) :: map()

scheduled_execution_event(name)

@spec scheduled_execution_event(atom() | binary()) :: event_name()

scheduled_execution_metadata(scheduled_execution, attrs \\ %{})

@spec scheduled_execution_metadata(map(), map()) :: map()

span(event_prefix, metadata, fun)

@spec span(event_prefix(), metadata(), (-> {term(), metadata()} | term())) :: term()

webhook_delivery_event(status, delivery, attrs \\ %{})

@spec webhook_delivery_event(atom(), map(), map()) :: :ok

webhook_metadata(receipt, attrs \\ %{})

@spec webhook_metadata(map(), map()) :: map()

webhook_outbound_metadata(delivery, attrs \\ %{})

@spec webhook_outbound_metadata(map(), map()) :: map()