Telemetry integration for PhoenixGenApi.
This module provides a central place to discover, attach to, and handle all telemetry events emitted by PhoenixGenApi.
Events
Executor
| Event | Measurements | Metadata |
|---|---|---|
[:phoenix_gen_api, :executor, :request, :start] | %{system_time: integer()} | %{request_id: String.t(), request_type: String.t(), service: String.t(), user_id: String.t()} |
[:phoenix_gen_api, :executor, :request, :stop] | %{duration_us: integer()} | %{request_id: String.t(), request_type: String.t(), service: String.t(), user_id: String.t(), success: boolean(), async: boolean()} |
[:phoenix_gen_api, :executor, :request, :exception] | %{duration_us: integer()} | %{request_id: String.t(), request_type: String.t(), service: String.t(), user_id: String.t(), kind: atom(), reason: String.t(), stacktrace: Exception.stacktrace()} |
[:phoenix_gen_api, :executor, :retry] | %{attempt: non_neg_integer()} | %{mode: :same_node or :all_nodes, type: :local or :remote} + optional nodes: list() for remote retries |
Rate Limiter
| Event | Measurements | Metadata |
|---|---|---|
[:phoenix_gen_api, :rate_limiter, :check] | %{duration_us: integer()} | %{request_id: String.t(), user_id: String.t(), service: String.t(), request_type: String.t(), result: :ok or {:error, :rate_limited, map()}} |
[:phoenix_gen_api, :rate_limiter, :exceeded] | %{retry_after_ms: non_neg_integer()} | %{key: String.t(), scope: :global or {String.t(), String.t()}, max_requests: non_neg_integer(), current_requests: non_neg_integer(), request_id: String.t(), user_id: String.t()} |
[:phoenix_gen_api, :rate_limiter, :reset] | %{} | %{key: String.t(), scope: atom(), rate_limit_key: atom()} |
[:phoenix_gen_api, :rate_limiter, :cleanup] | %{duration_us: integer(), cleaned_entries: non_neg_integer()} | %{global_limits_count: non_neg_integer(), api_limits_count: non_neg_integer()} |
Hooks
| Event | Measurements | Metadata |
|---|---|---|
[:phoenix_gen_api, :hook, :before, :start] | %{system_time: integer()} | %{module: module(), function: atom(), type: :before} |
[:phoenix_gen_api, :hook, :before, :stop] | %{duration_us: integer()} | %{module: module(), function: atom(), type: :before} |
[:phoenix_gen_api, :hook, :before, :exception] | %{duration_us: integer()} | %{module: module(), function: atom(), type: :before, kind: atom(), reason: String.t(), stacktrace: Exception.stacktrace()} |
[:phoenix_gen_api, :hook, :after, :start] | %{system_time: integer()} | %{module: module(), function: atom(), type: :after} |
[:phoenix_gen_api, :hook, :after, :stop] | %{duration_us: integer()} | %{module: module(), function: atom(), type: :after} |
[:phoenix_gen_api, :hook, :after, :exception] | %{duration_us: integer()} | %{module: module(), function: atom(), type: :after, kind: atom(), reason: String.t(), stacktrace: Exception.stacktrace()} |
Worker Pool
| Event | Measurements | Metadata |
|---|---|---|
[:phoenix_gen_api, :worker_pool, :task, :start] | %{system_time: integer()} | %{pool_name: atom()} |
[:phoenix_gen_api, :worker_pool, :task, :stop] | %{duration_us: integer()} | %{pool_name: atom()} |
[:phoenix_gen_api, :worker_pool, :task, :exception] | %{duration_us: integer()} | %{pool_name: atom(), kind: atom(), reason: term(), stacktrace: Exception.stacktrace()} |
[:phoenix_gen_api, :worker_pool, :circuit_breaker, :open] | %{} | %{pool_name: atom(), consecutive_failures: non_neg_integer()} |
[:phoenix_gen_api, :worker_pool, :circuit_breaker, :close] | %{} | %{pool_name: atom()} |
Config Cache
| Event | Measurements | Metadata |
|---|
| [:phoenix_gen_api, :config, :pull, :start] | %{system_time: integer()} | %{service: String.t() | atom()} |
| [:phoenix_gen_api, :config, :pull, :stop] | %{duration_us: integer(), count: non_neg_integer()} | %{service: String.t() | atom(), version: String.t() | nil} |
| [:phoenix_gen_api, :config, :push] | %{count: non_neg_integer()} | %{service: String.t() | atom(), version: String.t()} |
| [:phoenix_gen_api, :config, :add] | %{} | %{service: String.t() | atom(), request_type: String.t(), version: String.t()} |
| [:phoenix_gen_api, :config, :batch_add] | %{count: non_neg_integer()} | %{service: String.t() | atom()} |
| [:phoenix_gen_api, :config, :delete] | %{} | %{service: String.t() | atom(), request_type: String.t(), version: String.t()} |
| [:phoenix_gen_api, :config, :clear] | %{} | %{service: atom(), request_type: atom(), version: atom()} |
| [:phoenix_gen_api, :config, :disable] | %{} | %{service: String.t() | atom(), request_type: String.t(), version: String.t()} |
| [:phoenix_gen_api, :config, :enable] | %{} | %{service: String.t() | atom(), request_type: String.t(), version: String.t()} |
Usage
# Attach a handler to all events
PhoenixGenApi.Telemetry.attach_all("my-handler", &MyApp.handle_event/4)
# Attach only to executor events
PhoenixGenApi.Telemetry.attach_executor("my-handler", &MyApp.handle_event/4)
# Attach the built-in debug logger
PhoenixGenApi.Telemetry.attach_default_logger()
# Detach everything for a handler ID
PhoenixGenApi.Telemetry.detach_all("my-handler")
Summary
Functions
Attaches a handler function to all PhoenixGenApi telemetry events.
Attaches a handler to config cache events.
Attaches a default console logger that logs all telemetry events at debug level.
Attaches a handler to executor events.
Attaches a handler to hook events.
Attaches a handler to a list of events.
Attaches a handler to rate limiter events.
Attaches a handler to worker pool events.
Detaches all handlers for the given handler ID.
Detaches the default console logger.
Emits a telemetry event. Thin wrapper around :telemetry.execute/3.
Returns the full list of telemetry events emitted by PhoenixGenApi.
Wraps a function in a telemetry span. Thin wrapper around :telemetry.span/3.
Functions
Attaches a handler function to all PhoenixGenApi telemetry events.
Attaches a handler to config cache events.
@spec attach_default_logger(String.t()) :: :ok
Attaches a default console logger that logs all telemetry events at debug level.
Attaches a handler to executor events.
Attaches a handler to hook events.
Attaches a handler to a list of events.
Attaches a handler to rate limiter events.
Attaches a handler to worker pool events.
@spec detach_all(String.t()) :: :ok
Detaches all handlers for the given handler ID.
@spec detach_default_logger(String.t()) :: :ok
Detaches the default console logger.
Emits a telemetry event. Thin wrapper around :telemetry.execute/3.
@spec list_events() :: [[atom()]]
Returns the full list of telemetry events emitted by PhoenixGenApi.
Wraps a function in a telemetry span. Thin wrapper around :telemetry.span/3.