Skip to content

Commit

Permalink
Replace μs with us because unicode is not always available in log agg…
Browse files Browse the repository at this point in the history
…regators
  • Loading branch information
AndrewDryga committed Aug 26, 2024
1 parent 8ee75eb commit 625dd08
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lib/logger_json/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ if Code.ensure_loaded?(Ecto) and Code.ensure_loaded?(:telemetry) do
metadata = [
query: %{
repo: inspect(repo),
execution_time_μs: query_time,
decode_time_μs: decode_time,
queue_time_μs: queue_time,
latency_μs: latency
execution_time_us: query_time,
decode_time_us: decode_time,
queue_time_us: queue_time,
latency_us: latency
}
]

Expand Down
4 changes: 2 additions & 2 deletions lib/logger_json/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if Code.ensure_loaded?(Plug) and Code.ensure_loaded?(:telemetry) do
]
end,
conn: conn,
duration_μs: duration
duration_us: duration
)
else
:ok
Expand All @@ -98,7 +98,7 @@ if Code.ensure_loaded?(Plug) and Code.ensure_loaded?(:telemetry) do
if duration > 1000 do
[duration |> div(1000) |> Integer.to_string(), "ms"]
else
[Integer.to_string(duration), "µs"]
[Integer.to_string(duration), "us"]
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/logger_json/ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ defmodule LoggerJSON.EctoTest do
"message" => "begin",
"metadata" => %{
"query" => %{
"decode_time_μs" => 0,
"execution_time_μs" => 2930,
"latency_μs" => 3036,
"queue_time_μs" => 106,
"decode_time_us" => 0,
"execution_time_us" => 2930,
"latency_us" => 3036,
"queue_time_us" => 106,
"repo" => "Repo"
}
}
Expand Down
32 changes: 16 additions & 16 deletions test/logger_json/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent 200 in 500µs]",
"metadata" => %{"duration_μs" => 500},
"message" => "GET / [Sent 200 in 500us]",
"metadata" => %{"duration_us" => 500},
"request" => %{
"client" => %{"ip" => "127.0.0.1", "user_agent" => nil},
"connection" => %{"method" => "GET", "path" => "/", "protocol" => "HTTP/1.1", "status" => 200}
Expand All @@ -69,8 +69,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent in 500µs]",
"metadata" => %{"duration_μs" => 500},
"message" => "GET / [Sent in 500us]",
"metadata" => %{"duration_us" => 500},
"request" => %{
"client" => %{"ip" => "127.0.0.1", "user_agent" => nil},
"connection" => %{"method" => "GET", "path" => "/", "protocol" => "HTTP/1.1", "status" => nil}
Expand All @@ -94,8 +94,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Chunked in 500µs]",
"metadata" => %{"duration_μs" => 500},
"message" => "GET / [Chunked in 500us]",
"metadata" => %{"duration_us" => 500},
"request" => %{
"client" => %{"ip" => "127.0.0.1", "user_agent" => nil},
"connection" => %{"method" => "GET", "path" => "/", "protocol" => "HTTP/1.1", "status" => nil}
Expand Down Expand Up @@ -162,7 +162,7 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent 200 in 500µs]",
"message" => "GET / [Sent 200 in 500us]",
"http" => %{
"method" => "GET",
"referer" => nil,
Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule LoggerJSON.PlugTest do
},
"useragent" => "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
},
"message" => "GET /foo/bar [Sent 200 in 500µs]",
"message" => "GET /foo/bar [Sent 200 in 500us]",
"network" => %{"client" => %{"ip" => "127.0.0.1"}}
} = decode_or_print_error(log)
end
Expand All @@ -241,7 +241,7 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent in 500µs]",
"message" => "GET / [Sent in 500us]",
"http" => %{
"method" => "GET",
"referer" => nil,
Expand Down Expand Up @@ -278,7 +278,7 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Chunked in 500µs]",
"message" => "GET / [Chunked in 500us]",
"http" => %{
"method" => "GET",
"referer" => nil,
Expand Down Expand Up @@ -358,8 +358,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent 200 in 500µs]",
"duration_μs" => 500,
"message" => "GET / [Sent 200 in 500us]",
"duration_us" => 500,
"httpRequest" => %{
"protocol" => "HTTP/1.1",
"referer" => nil,
Expand Down Expand Up @@ -389,8 +389,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Sent in 500µs]",
"duration_μs" => 500,
"message" => "GET / [Sent in 500us]",
"duration_us" => 500,
"httpRequest" => %{
"protocol" => "HTTP/1.1",
"referer" => nil,
Expand Down Expand Up @@ -420,8 +420,8 @@ defmodule LoggerJSON.PlugTest do
end)

assert %{
"message" => "GET / [Chunked in 500µs]",
"duration_μs" => 500,
"message" => "GET / [Chunked in 500us]",
"duration_us" => 500,
"httpRequest" => %{
"protocol" => "HTTP/1.1",
"referer" => nil,
Expand Down

0 comments on commit 625dd08

Please sign in to comment.