andreyuhai

andreyuhai

Telemetry metrics how to increment counter by a given amount?

I think I don’t really get the idea of measurement options in Telemetry.Metrics.

I’ve got a function

def batch_process_jobs do
       # process jobs somewhere here...

        :telemetry.execute(
          [:my_app, :jobs],
          %{count: length(failed_task_ids)},
          %{status: "failed"}
        )

        :telemetry.execute(
          [:my_app, :jobs],
          %{count: length(succeeded_task_ids)},
          %{status: "succeeded"}
        )
end

So the idea is I want to see how many jobs failed and how many jobs succeeded after a batch process. My thinking is that if I give the number of failed and succeeded jobs (by calculating the length of IDs) as the count I’d expect that much increase in my bar graph as I am grouping by status.

Below you can see an example graph. As you can see both succeeded (light blue) and failed (dark blue) job count are the same however that’s not the case actually.

Why does that happen? When and how to use the measurement options like I tried in this case by giving count?

Edit: I figured that the count in the graph is actually the number of times :telemetry.execute was invoked for that specific metric type. Since they are in the same block, they are called the same number of times regardless of the count value I pass. Not sure whether that helps.

Cheers,
Burak

Marked As Solved

andreyuhai

andreyuhai

I think I’ve figured it out, I’ve tested it as well so it worked.

We are using telemetry_metrics_statsd as the reporter and from its docs regarding the counter metric:

Note that the counter was bumped by 1, regardless of the measurements included in the event (careful reader will notice that the :count measurement we chose for the metric wasn’t present in the map of measurements at all!). Such behaviour conforms to the specification of counter as defined by Telemetry.Metrics package - a counter should be incremented by 1 every time a given event is dispatched.

What I should’ve used instead is the sum metric:

Sum metric is also represented as a gauge - the difference is that it always changes relatively and is never set to an absolute value. Given metric definition below

So I’ve changed this

counter("my_app.jobs.count", tags: [:status]),

into this:

sum("my_app.jobs.count",
  tags: [:status],
  reporter_options: [report_as: :counter]
)

I think I should’ve mentioned that in my question to start with, but I didn’t know it could be related. Sorry for that.

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
sergio_101
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

axelson
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...
239 48342 226
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
alice
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement