From 57e90bf9cc71169bda08df6aee15b4b6c159f542 Mon Sep 17 00:00:00 2001 From: Tobias Lindahl Date: Mon, 4 May 2020 15:04:21 +0200 Subject: [PATCH 1/2] Add redbug to release --- rebar.config | 5 +++-- rebar.lock | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index ee02d575c..3c68f2103 100644 --- a/rebar.config +++ b/rebar.config @@ -35,7 +35,8 @@ {jose, {git, "https://github.com/NYNJA-MC/jose-erlang.git", {ref, "7094018"}}}, {uuid, {git, "https://github.com/avtobiff/erlang-uuid.git",{branch,"master"}}}, {enenra, {git, "https://github.com/nlfiedler/enenra", {tag, "0.3.0"}}}, - {'qdate', {git, "https://github.com/enterprizing/qdate.git", {ref,"fba988fc54214bb37a3ce11d5c5a3cc68752c3ce"}}} + {'qdate', {git, "https://github.com/enterprizing/qdate.git", {ref,"fba988fc54214bb37a3ce11d5c5a3cc68752c3ce"}}}, + {redbug, {git, "https://github.com/massemanet/redbug.git", {tag, "2.0.1"}}} ]}. @@ -87,7 +88,7 @@ ssl_verify_fun,locus,emqttd,hackney,roster,service,active, cowboy,emq_dashboard,emqttc,enenra,envy,uuid,erlydtl,forms, gen_smtp, jwt, migresia, mini_s3, nitro, opencensus, - qdate,rest,rfc3339,sh,stacktrace_compat]}, + qdate,rest,rfc3339,sh,stacktrace_compat, redbug]}, {sys_config, "./sys.config"}, {vm_args, "./vm.args"}, {dev_mode, true}, diff --git a/rebar.lock b/rebar.lock index dedcc49b0..c972e7c5d 100644 --- a/rebar.lock +++ b/rebar.lock @@ -171,6 +171,10 @@ {git,"https://github.com/ninenines/ranch", {ref,"3190aef88aea04d6dce8545fe9b4574288903f44"}}, 1}, + {<<"redbug">>, + {git,"https://github.com/massemanet/redbug.git", + {ref,"4cdfd2106432579502da535e390466fe9ca0d41f"}}, + 0}, {<<"rest">>, {git,"git://github.com/synrc/rest", {ref,"9a4e21d50a96b06649944c9a88ad595114db6c31"}}, -- GitLab From b2a44ce10917a059a3664013d5b6acb3877f75a0 Mon Sep 17 00:00:00 2001 From: Tobias Lindahl Date: Mon, 4 May 2020 15:05:20 +0200 Subject: [PATCH 2/2] Add content type to REST API logging --- apps/roster/src/rest/rest_cowboy_chat_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_cri_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_csv_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_fake_numbers_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_link_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_metric_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_publish_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_push_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_room_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_session_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_test_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_transcribe_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_users_handler.erl | 4 +++- apps/roster/src/rest/rest_cowboy_whitelist_handler.erl | 4 +++- 14 files changed, 42 insertions(+), 14 deletions(-) diff --git a/apps/roster/src/rest/rest_cowboy_chat_handler.erl b/apps/roster/src/rest/rest_cowboy_chat_handler.erl index 7f7e1d45a..c91e67e36 100644 --- a/apps/roster/src/rest/rest_cowboy_chat_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_chat_handler.erl @@ -32,7 +32,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := Endpoint} = State) when Endpoint =:= chat; Endpoint =:= room_chat -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_cri_handler.erl b/apps/roster/src/rest/rest_cowboy_cri_handler.erl index ef02dfaeb..3c06dc791 100644 --- a/apps/roster/src/rest/rest_cowboy_cri_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_cri_handler.erl @@ -49,7 +49,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, Endpoint =:= ?cri_room_members; Endpoint =:= ?cri_room_type; Endpoint =:= ?cri_bubble -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_csv_handler.erl b/apps/roster/src/rest/rest_cowboy_csv_handler.erl index a21da1b59..6f261d005 100644 --- a/apps/roster/src/rest/rest_cowboy_csv_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_csv_handler.erl @@ -31,7 +31,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := Endpoint} = State) when Endpoint =:= ?groups_csv; Endpoint =:= ?chats_csv -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_fake_numbers_handler.erl b/apps/roster/src/rest/rest_cowboy_fake_numbers_handler.erl index 7e3e8591f..e35fb36b8 100644 --- a/apps/roster/src/rest/rest_cowboy_fake_numbers_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_fake_numbers_handler.erl @@ -32,7 +32,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := Endpoint} = State) when Endpoint =:= fn; Endpoint =:= fake_numbers -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. resource_exists(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_link_handler.erl b/apps/roster/src/rest/rest_cowboy_link_handler.erl index 82216edc8..53b89df5a 100644 --- a/apps/roster/src/rest/rest_cowboy_link_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_link_handler.erl @@ -26,7 +26,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := link_room} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_metric_handler.erl b/apps/roster/src/rest/rest_cowboy_metric_handler.erl index 2b88370df..6c0212ede 100644 --- a/apps/roster/src/rest/rest_cowboy_metric_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_metric_handler.erl @@ -25,7 +25,9 @@ %%%=================================================================== init(#{path := Path, method := Method} = Req, #{endpoint := metrics} = State) -> - ?LOG_INFO("~s:~s", [Method, Path]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s", [Method, Path, CT]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_publish_handler.erl b/apps/roster/src/rest/rest_cowboy_publish_handler.erl index a030da52b..2ddc1a6fa 100644 --- a/apps/roster/src/rest/rest_cowboy_publish_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_publish_handler.erl @@ -26,7 +26,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := publish} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~p ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_push_handler.erl b/apps/roster/src/rest/rest_cowboy_push_handler.erl index 5b603bd61..96303a561 100644 --- a/apps/roster/src/rest/rest_cowboy_push_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_push_handler.erl @@ -25,7 +25,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := push_message} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_room_handler.erl b/apps/roster/src/rest/rest_cowboy_room_handler.erl index f8fba266c..a613cfe9b 100644 --- a/apps/roster/src/rest/rest_cowboy_room_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_room_handler.erl @@ -27,7 +27,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := room} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_session_handler.erl b/apps/roster/src/rest/rest_cowboy_session_handler.erl index 1d4b27941..08e054e7b 100644 --- a/apps/roster/src/rest/rest_cowboy_session_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_session_handler.erl @@ -28,7 +28,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := sessions} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. resource_exists(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_test_handler.erl b/apps/roster/src/rest/rest_cowboy_test_handler.erl index 3ffeb3808..16803f9e8 100644 --- a/apps/roster/src/rest/rest_cowboy_test_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_test_handler.erl @@ -23,7 +23,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := test_api} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_transcribe_handler.erl b/apps/roster/src/rest/rest_cowboy_transcribe_handler.erl index fc633efee..92898eafd 100644 --- a/apps/roster/src/rest/rest_cowboy_transcribe_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_transcribe_handler.erl @@ -34,7 +34,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := Endpoint} = State) when Endpoint =:= ?groups_transcribe; Endpoint =:= ?chats_transcribe -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_users_handler.erl b/apps/roster/src/rest/rest_cowboy_users_handler.erl index 138620201..a23ed0fe7 100644 --- a/apps/roster/src/rest/rest_cowboy_users_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_users_handler.erl @@ -27,7 +27,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := users} = State) -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. is_authorized(Req, State) -> diff --git a/apps/roster/src/rest/rest_cowboy_whitelist_handler.erl b/apps/roster/src/rest/rest_cowboy_whitelist_handler.erl index 0597cc95d..e4bb1a16d 100644 --- a/apps/roster/src/rest/rest_cowboy_whitelist_handler.erl +++ b/apps/roster/src/rest/rest_cowboy_whitelist_handler.erl @@ -32,7 +32,9 @@ init(#{path := Path, method := Method, qs := QS} = Req, #{endpoint := Endpoint} = State) when Endpoint =:= whitelist; Endpoint =:= admin_whitelist -> - ?LOG_INFO("~s:~s ~p", [Method, Path, QS]), + Headers = cowboy_req:headers(Req), + CT = maps:get(<<"content-type">>, Headers, <<"no-content-type">>), + ?LOG_INFO("~s:~s:~s ~p", [Method, Path, CT, QS]), {cowboy_rest, Req, State}. resource_exists(Req, State) -> -- GitLab