Skip to content

Commit

Permalink
Don't report tags with empty values for traffic optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Oct 4, 2024
1 parent 0e72efd commit 7db6882
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/telemetry_metrics_statsd/event_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ defmodule TelemetryMetricsStatsd.EventHandler do
|> Map.new()
|> Map.merge(metric.tag_values.(metadata))

tags = Enum.map(metric.tags, &{&1, Map.get(tag_values, &1, "")})
tags =
Enum.map(metric.tags, &{&1, Map.get(tag_values, &1, "")})
|> Enum.filter(fn {_, tag_value} -> tag_value != "" end)

Formatter.format(formatter_mod, metric, prefix, value, tags)
else
:nopublish
Expand Down
5 changes: 3 additions & 2 deletions test/telemetry_metrics_statsd_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ defmodule TelemetryMetricsStatsdTest do
handlers_before = :telemetry.list_handlers([])

:telemetry.execute([:http, :request], %{latency: 172}, %{method: "GET"})
assert_reported(socket, "")

assert_reported(socket, "http.request.count.GET:1|c")

handlers_after = :telemetry.list_handlers([])
assert handlers_after == handlers_before
Expand Down Expand Up @@ -196,7 +197,7 @@ defmodule TelemetryMetricsStatsdTest do
handlers_before = :telemetry.list_handlers([])

:telemetry.execute([:http, :request], %{latency: 172}, %{method: "GET"})
assert_reported(socket, "http.request.count:1|c|#method:GET,status:")
assert_reported(socket, "http.request.count:1|c|#method:GET")

handlers_after = :telemetry.list_handlers([])
assert handlers_after == handlers_before
Expand Down

0 comments on commit 7db6882

Please sign in to comment.