diff --git a/lib/telemetry_metrics_statsd/event_handler.ex b/lib/telemetry_metrics_statsd/event_handler.ex index e2934c5..f642c7b 100644 --- a/lib/telemetry_metrics_statsd/event_handler.ex +++ b/lib/telemetry_metrics_statsd/event_handler.ex @@ -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 diff --git a/test/telemetry_metrics_statsd_test.exs b/test/telemetry_metrics_statsd_test.exs index ca80d08..cda5a5b 100644 --- a/test/telemetry_metrics_statsd_test.exs +++ b/test/telemetry_metrics_statsd_test.exs @@ -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 @@ -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