Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support keep and drop #13

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
format:
name: Check formatting
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
Expand All @@ -21,7 +21,7 @@ jobs:
- run: mix format --check-formatted
test:
name: Test on Elixir ${{ matrix.elixir }} (OTP ${{ matrix.otp }})
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
otp: ["23.3.4.18", "24.3.4.6"]
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:

dialyze:
name: Dialyze on Elixir ${{ matrix.elixir }} (OTP ${{ matrix.otp }})
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
otp: ["23.3.4.18", "24.3.4.6"]
Expand Down
18 changes: 15 additions & 3 deletions lib/telemetry_metrics_appsignal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,25 @@ defmodule TelemetryMetricsAppsignal do
metrics = Keyword.get(config, :metrics, [])

Enum.each(metrics, fn metric ->
if value = prepare_metric_value(metric, measurements, metadata) do
tags = prepare_metric_tags(metric, metadata)
send_metric(metric, value, tags)
if keep?(metric, metadata) do
if value = prepare_metric_value(metric, measurements, metadata) do
tags = prepare_metric_tags(metric, metadata)
send_metric(metric, value, tags)
end
end
end)
end

defp keep?(%{keep: keep}, metadata) when is_function(keep, 1) do
keep.(metadata)
end

defp keep?(%{drop: drop}, metadata) when is_function(drop, 1) do
not drop.(metadata)
end

defp keep?(_, _), do: true

defp prepare_metric_value(metric, measurements, metadata)

defp prepare_metric_value(%Counter{}, _measurements, _metadata), do: 1
Expand Down
31 changes: 16 additions & 15 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
%{
"appsignal": {:hex, :appsignal, "2.4.1", "5df972d3d462ae18611c2213b6505d191a076b3b5310f5fcfb1d65b6cdeed662", [:make, :mix], [{:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "792fa2afc17d637726b0a7b6fbfbcd864bbb64a405cca2ae266ed4ea7f268140"},
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"appsignal": {:hex, :appsignal, "2.7.10", "974528d45384b3d1928c859672da9e3a0ad1936f43fdcdefbc647fb3785089ed", [:make, :mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1a3ce18e37d97314320347a5e6a99704342bda3ce22092e1e4ba82b118bb34f3"},
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"decorator": {:hex, :decorator, "1.4.0", "a57ac32c823ea7e4e67f5af56412d12b33274661bb7640ec7fc882f8d23ac419", [:mix], [], "hexpm", "0a07cedd9083da875c7418dea95b78361197cf2bf3211d743f6f7ce39656597f"},
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
"dialyxir": {:hex, :dialyxir, "1.4.2", "764a6e8e7a354f0ba95d58418178d486065ead1f69ad89782817c296d0d746a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "516603d8067b2fd585319e4b13d3674ad4f314a5902ba8130cd97dc902ce6bbd"},
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"},
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~> 2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"hammox": {:hex, :hammox, "0.7.0", "a49dc95e0a78e1c38db11c2b6eadff38f25418ef92ecf408bd90d95d459f35a2", [:mix], [{:mox, "~> 1.0", [hex: :mox, repo: "hexpm", optional: false]}, {:ordinal, "~> 0.1", [hex: :ordinal, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5e228c4587f23543f90c11394957878178c489fad46da421c37ca696e37dd91b"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mox": {:hex, :mox, "1.0.2", "dc2057289ac478b35760ba74165b4b3f402f68803dd5aecd3bfd19c183815d64", [:mix], [], "hexpm", "f9864921b3aaf763c8741b5b8e6f908f44566f1e427b2630e89e9a73b981fef2"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"mox": {:hex, :mox, "1.1.0", "0f5e399649ce9ab7602f72e718305c0f9cdc351190f72844599545e4996af73c", [:mix], [], "hexpm", "d44474c50be02d5b72131070281a5d3895c0e7a95c780e90bc0cfe712f633a13"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"ordinal": {:hex, :ordinal, "0.2.0", "d3eda0cb04ee1f0ca0aae37bf2cf56c28adce345fe56a75659031b6068275191", [:mix], [], "hexpm", "defca8f10dee9f03a090ed929a595303252700a9a73096b6f2f8d88341690d65"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
120 changes: 103 additions & 17 deletions test/telemetry_metrics_appsignal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ defmodule TelemetryMetricsAppsignalTest do
alias Telemetry.Metrics.Sum
alias Telemetry.Metrics.Summary

@moduletag capture_log: true

setup :verify_on_exit!

test "registering a name with the genserver" do
Expand Down Expand Up @@ -83,7 +81,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:web, :request], %{}, %{})
assert capture_log(fn ->
:telemetry.execute([:web, :request], %{}, %{})
end) == ""

assert_receive {^ref, :called}

# Measurements should be ignored for counter metric
Expand All @@ -94,7 +95,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:web, :request], %{count: 5}, %{})
assert capture_log(fn ->
:telemetry.execute([:web, :request], %{count: 5}, %{})
end) == ""

assert_receive {^ref, :called}

ref = make_ref()
Expand All @@ -105,7 +109,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:worker, :events], %{consumed: 11}, %{})
assert capture_log(fn ->
:telemetry.execute([:worker, :events], %{consumed: 11}, %{})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -123,7 +130,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:worker, :queue], %{length: 42}, %{})
assert capture_log(fn ->
:telemetry.execute([:worker, :queue], %{length: 42}, %{})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -141,7 +151,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:db, :query], %{duration: 99}, %{})
assert capture_log(fn ->
:telemetry.execute([:db, :query], %{duration: 99}, %{})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -165,7 +178,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:db, :query], %{duration: 99}, %{})
assert capture_log(fn ->
:telemetry.execute([:db, :query], %{duration: 99}, %{})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -189,7 +205,10 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:db, :query], %{duration: 99}, %{multiplier: 2})
assert capture_log(fn ->
:telemetry.execute([:db, :query], %{duration: 99}, %{multiplier: 2})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -207,7 +226,66 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:db, :query], %{duration: native_time}, %{})
assert capture_log(fn ->
:telemetry.execute([:db, :query], %{duration: native_time}, %{})
end) == ""

assert_receive {^ref, :called}
end

test "filtering with keep" do
metric =
last_value("worker.queue.length",
keep: fn metadata ->
assert %{number: number} = metadata
number > 3
end
)

start_reporter(metrics: [metric])

parent = self()
ref = make_ref()

expect(AppsignalMock, :set_gauge, fn
"worker.queue.length", 60, %{} ->
send(parent, {ref, :called})
:ok
end)

assert capture_log(fn ->
:telemetry.execute([:worker, :queue], %{length: 42}, %{number: 2})
:telemetry.execute([:worker, :queue], %{length: 60}, %{number: 5})
end) == ""

assert_receive {^ref, :called}
end

test "filtering with drop" do
metric =
last_value("worker.queue.length",
drop: fn metadata ->
assert %{number: number} = metadata
number > 3
end
)

start_reporter(metrics: [metric])

parent = self()
ref = make_ref()

expect(AppsignalMock, :set_gauge, fn
"worker.queue.length", 42, %{} ->
send(parent, {ref, :called})
:ok
end)

assert capture_log(fn ->
:telemetry.execute([:worker, :queue], %{length: 42}, %{number: 2})
:telemetry.execute([:worker, :queue], %{length: 60}, %{number: 5})
end) == ""

assert_receive {^ref, :called}
end

Expand All @@ -224,10 +302,12 @@ defmodule TelemetryMetricsAppsignalTest do
:ok
end)

:telemetry.execute([:worker, :queue], %{length: 42}, %{
queue: "mailer",
host: "localhost"
})
assert capture_log(fn ->
:telemetry.execute([:worker, :queue], %{length: 42}, %{
queue: "mailer",
host: "localhost"
})
end) == ""

tag_permutations = [
%{queue: "mailer", host: "localhost"},
Expand All @@ -246,21 +326,27 @@ defmodule TelemetryMetricsAppsignalTest do
parent = self()
ref = make_ref()

expect(AppsignalMock, :set_gauge, 1, fn
expect(AppsignalMock, :set_gauge, 2, fn
"worker.queue.length", 42, tags ->
send(parent, {ref, tags})
:ok
end)

:telemetry.execute([:worker, :queue], %{length: 42}, %{})
assert capture_log(fn ->
:telemetry.execute([:worker, :queue], %{length: 42}, %{})
end) == ""

assert_receive({^ref, %{value: "value"}})
assert_receive({^ref, %{value: "any"}})
end

test "handling unsupported metrics" do
metric = distribution("web.request.duration", buckets: [100, 200, 400])
start_reporter(metrics: [metric])
:telemetry.execute([:web, :request], %{duration: 99}, %{})

assert capture_log(fn ->
:telemetry.execute([:web, :request], %{duration: 99}, %{})
end) =~ "Ignoring unsupported metric"
end

test "handling missing measurement" do
Expand Down
Loading