Skip to content

(js) Provide hooks for observability #67

@elementbound

Description

@elementbound

Implement a convenient way to add observability on top of the existing command handler logic. This primarily means hooks for submitting metrics, e.g. into Prometheus or Graphite, like number of requests, handler run time, number of errors, etc.

Potential solutions

Global filters

Same principle as Spring's filters, they run for each new handler call:

reactor.filter((cmd, xchg, handler) => {
  const from = time()
  try {
    handler(cmd, xchg)
  } catch (err) {
    pushErrorMetric(...)
    throw err
  } finally {
    const to = time()
    pushDurationMetric(...)
  }
})

Per-command filters

Same as global, except per-command, possibly wrapped in some neat utility function:

reactor.on("lobby/create", (cmd, xchg) => { ... })
  .with(durationMetrics())
  .with(errorMetrics())
.on("lobby/get", (cmd, xchg) => { ... })
  .with(durationMetrics())
  .with(errorMetrics())
.done() // done() returns the reactor itself

Wrapper methods

Functions that take the handler method and extend it by pushing metrics, like a decorator:

reactor.on("lobby/create", withDurationMetrics(withErrorMetrics((cmd, xchg) => {...})))

Notes

  • Having handler chains instead of single handlers per command is still on the table, make sure to keep the design open for that

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions