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/16 19:56:19 UTC

[couchdb] branch optional-fdb-tracing created (now 920dfa4)

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

vatamane pushed a change to branch optional-fdb-tracing
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 920dfa4  Enable FDB transaction tracing

This branch includes the following new commits:

     new 920dfa4  Enable FDB transaction tracing

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Enable FDB transaction tracing

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 920dfa4ee3a9b3df437df11fba13000a4aafc397
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.
    
    Config value (2) guards against DoS abuse. Even with tracing disabled in the
    FDB C client, setting the transaction name is an expensive operation.
    
    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").