View Source CozyTelemetry (cozy_telemetry v0.3.0)
Provides a modular approach to using beam-telemetry packages.
quick-start
Quick Start
Before running Elixir.CozyTelemetry
, you must provide some metrics modules. For example:
defmodule MyApp.Cache do
use CozyTelemetry.Metrics
@impl CozyTelemetry.Metrics
def metrics(meta) do
[
summary("cache.duration",
unit: {:native, :second},
tags: [:type, :key]
)
]
end
end
Then, set some base configuration within config/config.exs
:
config :my_app, CozyTelemetry,
meta: [],
metrics: [
MyApp.Cache
],
reporter: {:console, []}
Use the application configuration you've already set and include Elixir.CozyTelemetry
in the list of
supervised children:
# lib/my_app/application.ex
def start(_type, _args) do
children = [
{CozyTelemetry, Application.fetch_env!(:my_app, CozyTelemetry)}
# ...
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
about-option-meta
about option :meta
The value of option :meta
is a keyword list, which will be passed as the argument of callback
metrics/1
of CozyTelemetry.Metrics
.
about-option-metrics
about option :metrics
The value of option :metrics
is a list of metrics modules.
about-option-optional_metrics
about option :optional_metrics
Same as option :metrics
, but ignore errors when the given metrics module is missing.
When using
:cozy_telemetry
as a direct dependency, this option is unnecessary. But, when building a new package on:cozy_telemetry
, this option is useful for some case, such as auto loading metrics modules.
about-option-reporter
about option :reporter
The value of option :reporter
specifies the reporter and its options, which is in format of
{type, reporter_opts}
:
- available values of
type
are:console
,:statsd
,prometheus
. - available values of
reporter_opts
can be found in corresponding underlying modules: