Skip to content

Add requester field and enricher hook to controller metrics#58

Merged
DylanBlakemore merged 4 commits into
masterfrom
controller-metrics-enricher
Jun 1, 2026
Merged

Add requester field and enricher hook to controller metrics#58
DylanBlakemore merged 4 commits into
masterfrom
controller-metrics-enricher

Conversation

@DylanBlakemore
Copy link
Copy Markdown
Collaborator

Summary

  • Add requester field to Zexbox.Metrics.ControllerSeries (not populated by default)
  • Add Zexbox.Metrics.ControllerSeriesEnricher behaviour and an :enricher option on Zexbox.Metrics.start_link/1 (also configurable via config :zexbox, :metrics_enricher)
  • Invoke the enricher from the metric handler with exception fallback

Details

Host apps frequently need to attach context to the controller metric that zexbox itself doesn't know about — most immediately, an identifier for the caller derived from an API key lookup. Rather than baking specific knowledge of those values into zexbox, this adds a small extension point: a Plug-shaped behaviour (init/1 + call/3) that receives the in-flight ControllerSeries and the conn, and returns a possibly-modified series. The host app configures their enricher module either at supervision time or via application env, and uses it to copy values they've already stashed on conn.assigns (e.g. an API key description set by their auth plug) onto the series.

The new requester field is the canonical place to put that caller identifier, but the enricher is free to set any tag or field on the series. Enricher exceptions are caught by the metric handler and logged — a buggy enricher will not break telemetry; the un-enriched series is written instead.

Comment thread lib/zexbox/metrics/metric_handler.ex
@DylanBlakemore DylanBlakemore merged commit 73d3072 into master Jun 1, 2026
4 checks passed
@DylanBlakemore DylanBlakemore deleted the controller-metrics-enricher branch June 1, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants