Add UUID to telemetry payload
parent
bed5153a22
commit
131a5f5e8d
|
@ -20,4 +20,5 @@
|
|||
"timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"tzdata": {:hex, :tzdata, "1.0.1", "f6027a331af7d837471248e62733c6ebee86a72e57c613aa071ebb1f750fc71a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
|
||||
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
|
||||
}
|
||||
|
|
|
@ -65,9 +65,10 @@ defmodule FarmbotExt.AMQP.TelemetryChannel do
|
|||
def handle_info(:consume_telemetry, state) do
|
||||
_ =
|
||||
FarmbotTelemetry.consume_telemetry(fn
|
||||
{captured_at, kind, subsystem, measurement, value, meta} ->
|
||||
{uuid, captured_at, kind, subsystem, measurement, value, meta} ->
|
||||
json =
|
||||
FarmbotCore.JSON.encode!(%{
|
||||
"telemetry.uuid" => uuid,
|
||||
"telemetry.measurement" => measurement,
|
||||
"telemetry.value" => value,
|
||||
"telemetry.kind" => kind,
|
||||
|
|
|
@ -41,4 +41,5 @@
|
|||
"timex": {:hex, :timex, "3.4.2", "d74649c93ad0e12ce5b17cf5e11fbd1fb1b24a3d114643e86dba194b64439547", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"tzdata": {:hex, :tzdata, "0.5.19", "7962a3997bf06303b7d1772988ede22260f3dae1bf897408ebdac2b4435f4e6a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
|
||||
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ defmodule FarmbotTelemetry do
|
|||
@typedoc "Type of telemetry data"
|
||||
@type kind() :: :event | :metric
|
||||
|
||||
@typedoc "UUID of the telemetry data"
|
||||
@type uuid() :: String.t()
|
||||
|
||||
@typedoc "Classifier for telemetry data"
|
||||
@type subsystem() :: atom()
|
||||
|
||||
|
@ -33,6 +36,7 @@ defmodule FarmbotTelemetry do
|
|||
defmacro event(subsystem, measurement, value, meta \\ %{}) do
|
||||
quote location: :keep do
|
||||
FarmbotTelemetry.bare_telemetry(
|
||||
UUID.uuid4(),
|
||||
:event,
|
||||
unquote(subsystem),
|
||||
unquote(measurement),
|
||||
|
@ -47,6 +51,7 @@ defmodule FarmbotTelemetry do
|
|||
defmacro metric(subsystem, measurement, value, meta \\ %{}) do
|
||||
quote location: :keep do
|
||||
FarmbotTelemetry.bare_telemetry(
|
||||
UUID.uuid4(),
|
||||
:metric,
|
||||
unquote(subsystem),
|
||||
unquote(measurement),
|
||||
|
@ -58,16 +63,21 @@ defmodule FarmbotTelemetry do
|
|||
end
|
||||
|
||||
@doc "Function responsible for firing telemetry events"
|
||||
@spec bare_telemetry(kind(), subsystem(), measurement(), value(), DateTime.t(), meta()) :: :ok
|
||||
def bare_telemetry(kind, subsystem, measurement, value, captured_at, meta) do
|
||||
@spec bare_telemetry(uuid, kind(), subsystem(), measurement(), value(), DateTime.t(), meta()) ::
|
||||
:ok
|
||||
def bare_telemetry(uuid, kind, subsystem, measurement, value, captured_at, meta) do
|
||||
_ =
|
||||
:telemetry.execute(
|
||||
[:farmbot_telemetry, kind, subsystem],
|
||||
%{measurement => value, captured_at: captured_at},
|
||||
%{measurement => value, captured_at: captured_at, uuid: uuid},
|
||||
meta
|
||||
)
|
||||
|
||||
_ = :dets.insert(:farmbot_telemetry, {captured_at, kind, subsystem, measurement, value, meta})
|
||||
_ =
|
||||
:dets.insert(
|
||||
:farmbot_telemetry,
|
||||
{uuid, captured_at, kind, subsystem, measurement, value, meta}
|
||||
)
|
||||
end
|
||||
|
||||
@doc "Attach a logger to a kind and subsystem"
|
||||
|
@ -91,7 +101,8 @@ defmodule FarmbotTelemetry do
|
|||
|
||||
@typedoc "Function passed to `consume_telemetry/1`"
|
||||
@type consumer_fun() ::
|
||||
({DateTime.t(), kind(), subsystem(), measurement(), value(), meta()} -> :ok | :error)
|
||||
({uuid(), DateTime.t(), kind(), subsystem(), measurement(), value(), meta()} ->
|
||||
:ok | :error)
|
||||
|
||||
@doc "Consume telemetry events"
|
||||
def consume_telemetry(fun) do
|
||||
|
@ -103,9 +114,9 @@ defmodule FarmbotTelemetry do
|
|||
end)
|
||||
|
||||
_ =
|
||||
Enum.map(tasks, fn {created_at, task} ->
|
||||
Enum.map(tasks, fn {uuid, task} ->
|
||||
case Task.await(task) do
|
||||
:ok -> :dets.delete(:farmbot_telemetry, created_at)
|
||||
:ok -> :dets.delete(:farmbot_telemetry, uuid)
|
||||
_ -> :ok
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -36,6 +36,7 @@ defmodule FarmbotTelemetry.MixProject do
|
|||
defp deps do
|
||||
[
|
||||
{:telemetry, "~> 0.4.0"},
|
||||
{:uuid, "~> 1.1"},
|
||||
{:excoveralls, "~> 0.10", only: [:test], targets: [:host]},
|
||||
{:dialyxir, "~> 1.0.0-rc.3", only: [:dev], targets: [:host], runtime: false},
|
||||
{:ex_doc, "~> 0.19", only: [:dev], targets: [:host], runtime: false}
|
||||
|
|
|
@ -17,4 +17,5 @@
|
|||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"},
|
||||
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
|
||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
|
||||
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue