samba6
Filter out oban database metrics from telemetry
I wish to filter out oban database metrics from telemetry.
The following is my poor attempt, but I am not succeeding:
defmodule MyAppWeb.Telemetry do
use Supervisor
import Telemetry.Metrics
def start_link(arg) do
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
end
@impl true
def init(_arg) do
children = [
# Telemetry poller will execute the given period measurements
# every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
{:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
# Add reporters as children of your supervision tree.
{Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
]
Supervisor.init(children, strategy: :one_for_one)
end
def metrics do
[
# Database Metrics
summary("my_app.repo.query.total_time",
unit: {:native, :millisecond},
description: "The sum of the other measurements",
drop: &drop_oban_queries/1
),
summary("my_app.repo.query.decode_time",
unit: {:native, :millisecond},
description: "The time spent decoding the data received from the database",
drop: &drop_oban_queries/1
),
summary("my_app.repo.query.query_time",
unit: {:native, :millisecond},
description: "The time spent executing the query",
drop: &drop_oban_queries/1
),
summary("my_app.repo.query.queue_time",
unit: {:native, :millisecond},
description: "The time spent waiting for a database connection",
drop: &drop_oban_queries/1
),
summary("my_app.repo.query.idle_time",
unit: {:native, :millisecond},
description:
"The time the connection spent waiting before being checked out for the query",
drop: &drop_oban_queries/1
)
]
end
defp periodic_measurements do
[
# A module, function and arguments to be invoked periodically.
# This function must call :telemetry.execute/3 and a metric must be added above.
# {MyAppWeb, :count_users, []}
]
end
defp drop_oban_queries(metadata) do
case metadata do
%{options: options} when is_list(options) ->
Keyword.has_key?(options, :oban_conf)
_ ->
false
end
end
end
Marked As Solved
samba6
I figured it out. The answer lies here. So I needed to add keep option instead of drop. I ended up doing:
def metrics do
[
# Database Metrics
summary("my_app.repo.query.total_time",
unit: {:native, :millisecond},
description: "The sum of the other measurements",
keep: &keep?/1
),
summary("my_app.repo.query.decode_time",
unit: {:native, :millisecond},
description: "The time spent decoding the data received from the database",
keep: &keep?/1
),
summary("my_app.repo.query.query_time",
unit: {:native, :millisecond},
description: "The time spent executing the query",
keep: &keep?/1
),
summary("my_app.repo.query.queue_time",
unit: {:native, :millisecond},
description: "The time spent waiting for a database connection",
keep: &keep?/1
),
summary("my_app.repo.query.idle_time",
unit: {:native, :millisecond},
description: "The time the connection spent waiting before being checked out for the query",
keep: &keep?/1
)
]
end
defp keep?(%{options: options}) when is_list(options) do
not Keyword.has_key?(options, :oban_conf)
end
defp keep?(_) do
true
end
Popular in Questions
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
can someone please explain to me how Enum.reduce works with maps
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New








