You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/10/17 15:45:49 UTC

[couchdb] branch prototype/fdb-layer updated: Enable FDB transaction tracing

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new bfb986f  Enable FDB transaction tracing
bfb986f is described below

commit bfb986f718b6e4c9f1b50bc63e9d2a10d19ebdb5
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Wed Oct 16 15:46:19 2019 -0400

    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.
---
 src/chttpd/src/chttpd.erl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 4d32c03..fb227ae 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").