summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2019-10-16 15:46:19 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2019-10-17 11:45:23 -0400
commitbfb986f718b6e4c9f1b50bc63e9d2a10d19ebdb5 (patch)
tree12b8781017d7042ba54aef62b5e36df87e368ddd
parentae0dc9657880a03836c4cac04833504dd2711b81 (diff)
downloadcouchdb-bfb986f718b6e4c9f1b50bc63e9d2a10d19ebdb5.tar.gz
Enable FDB transaction tracing
To trace FDB transactions: 1. Enable tracing in erlfdb application environment: `network_options = [{trace_enable, ...}]` OR with an environment variable: `FDB_NETWORK_OPTION_TRACE_ENABLE = ""` 2. Set `[fabric] fdb_trace=true` configuration value 3. Add the `x-couchdb-fdb-trace:true` header to each request that should be traced. The transaction name is set to the nonce value, which is already used by CouchDB to track API requests. Only transactions started from the main request process will be traced. So if a process is spawned without inheriting the `erlfdb_trace` process dict key, that transaction will not be traced.
-rw-r--r--src/chttpd/src/chttpd.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 4d32c03c5..fb227aea3 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -238,6 +238,8 @@ handle_request_int(MochiReq) ->
erlang:put(dont_log_request, true),
erlang:put(dont_log_response, true),
+ maybe_trace_fdb(MochiReq:get_header_value("x-couchdb-fdb-trace")),
+
{HttpReq2, Response} = case before_request(HttpReq0) of
{ok, HttpReq1} ->
process_request(HttpReq1);
@@ -1214,6 +1216,22 @@ get_user(#httpd{user_ctx = #user_ctx{name = User}}) ->
get_user(#httpd{user_ctx = undefined}) ->
"undefined".
+maybe_trace_fdb("true") ->
+ % Remember to also enable tracing in erlfdb application environment:
+ % network_options = [{trace_enable, ...}]
+ % Or via the OS environment variable:
+ % FDB_NETWORK_OPTION_TRACE_ENABLE = ""
+ case config:get_boolean("fabric", "fdb_trace", false) of
+ true ->
+ Nonce = erlang:get(nonce),
+ erlang:put(erlfdb_trace, list_to_binary(Nonce));
+ false ->
+ ok
+ end;
+maybe_trace_fdb(_) ->
+ ok.
+
+
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").