Skip to content

Commit 65279d6

Browse files
Add conn.request_path to google_cloud_logger format (#34)
Adding the request_path means that this value can be indexed and filtered upon. Although the request_url attribute includes the request path, the hostname in the request_url may not be a static value which can make filtering on the request_path portion slow. Including the request path as it's own top level attribute resolves this problem.
1 parent 6fc1ca9 commit 65279d6

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ By-default, generated JSON is compatible with
4747
"latency":"0.350s",
4848
"remoteIp":"::ffff:10.142.0.2",
4949
"requestMethod":"GET",
50+
"requestPath":"/",
5051
"requestUrl":"http://10.16.0.70/",
5152
"status":200,
5253
"userAgent":"kube-probe/1.10+"

lib/logger_json/plug/metadata_formatters/google_cloud_logger.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if Code.ensure_loaded?(Plug) do
1818
def build_metadata(conn, latency, client_version_header) do
1919
latency_seconds = native_to_seconds(latency)
2020
request_method = conn.method
21+
request_path = conn.request_path
2122
request_url = request_url(conn)
2223
status = conn.status
2324
user_agent = LoggerJSON.Plug.get_header(conn, "user-agent")
@@ -31,6 +32,7 @@ if Code.ensure_loaded?(Plug) do
3132
httpRequest:
3233
json_map(
3334
requestMethod: request_method,
35+
requestPath: request_path,
3436
requestUrl: request_url,
3537
status: status,
3638
userAgent: user_agent,

test/unit/logger_json/plug_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ defmodule LoggerJSON.PlugTest do
3939
"referer" => nil,
4040
"remoteIp" => "127.0.0.1",
4141
"requestMethod" => "GET",
42+
"requestPath" => "/",
4243
"requestUrl" => "http://www.example.com/",
4344
"status" => 200,
4445
"userAgent" => nil

0 commit comments

Comments
 (0)