summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2019-11-12 16:21:55 +0000
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-11-20 16:58:56 -0600
commit4680884b1d232d1f3159d1222b63e4e30bfffc25 (patch)
tree4f3d374e8ba0e762b5a3aa1b4bcf2715a00c0347
parent98bc5ea80a3606302cd7646ad623f8314e016a8c (diff)
downloadcouchdb-4680884b1d232d1f3159d1222b63e4e30bfffc25.tar.gz
Trace fdb transactions
-rw-r--r--src/fabric/src/fabric.app.src1
-rw-r--r--src/fabric/src/fabric2_fdb.erl47
-rw-r--r--src/fabric/test/fabric2_dir_prefix_tests.erl2
3 files changed, 39 insertions, 11 deletions
diff --git a/src/fabric/src/fabric.app.src b/src/fabric/src/fabric.app.src
index 77260f962..0538b19b4 100644
--- a/src/fabric/src/fabric.app.src
+++ b/src/fabric/src/fabric.app.src
@@ -23,6 +23,7 @@
config,
couch_epi,
couch,
+ ctrace,
rexi,
mem3,
couch_log,
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 0d741385c..fb2891be7 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -74,12 +74,15 @@ transactional(Fun) ->
transactional(DbName, Options, Fun) when is_binary(DbName) ->
- transactional(fun(Tx) ->
- Fun(init_db(Tx, DbName, Options))
+ with_span(Fun, #{'db.name' => DbName}, fun() ->
+ transactional(fun(Tx) ->
+ Fun(init_db(Tx, DbName, Options))
+ end)
end).
transactional(#{tx := undefined} = Db, Fun) ->
+ DbName = maps:get(name, Db, undefined),
try
Db1 = refresh(Db),
Reopen = maps:get(reopen, Db1, false),
@@ -88,18 +91,25 @@ transactional(#{tx := undefined} = Db, Fun) ->
true -> undefined;
false -> maps:get(layer_prefix, Db2)
end,
- do_transaction(fun(Tx) ->
- case Reopen of
- true -> Fun(reopen(Db2#{tx => Tx}));
- false -> Fun(Db2#{tx => Tx})
- end
- end, LayerPrefix)
+ with_span(Fun, #{'db.name' => DbName}, fun() ->
+ do_transaction(fun(Tx) ->
+ case Reopen of
+ true -> Fun(reopen(Db2#{tx => Tx}));
+ false -> Fun(Db2#{tx => Tx})
+ end
+ end, LayerPrefix)
+ end)
catch throw:{?MODULE, reopen} ->
- transactional(Db#{reopen => true}, Fun)
+ with_span('db.reopen', #{'db.name' => DbName}, fun() ->
+ transactional(Db#{reopen => true}, Fun)
+ end)
end;
transactional(#{tx := {erlfdb_transaction, _}} = Db, Fun) ->
- Fun(Db).
+ DbName = maps:get(name, Db, undefined),
+ with_span(Fun, #{'db.name' => DbName}, fun() ->
+ Fun(Db)
+ end).
do_transaction(Fun, LayerPrefix) when is_function(Fun, 1) ->
@@ -1384,3 +1394,20 @@ run_on_commit_fun(Tx) ->
Fun(),
ok
end.
+
+with_span(Operation, ExtraTags, Fun) ->
+ case ctrace:has_span() of
+ true ->
+ Tags = maps:merge(#{
+ 'span.kind' => <<"client">>,
+ component => <<"couchdb.fabric">>,
+ 'db.instance' => fabric2_server:fdb_cluster(),
+ 'db.namespace' => fabric2_server:fdb_directory(),
+ 'db.type' => <<"fdb">>,
+ nonce => get(nonce),
+ pid => self()
+ }, ExtraTags),
+ ctrace:with_span(Operation, Tags, Fun);
+ false ->
+ Fun()
+ end.
diff --git a/src/fabric/test/fabric2_dir_prefix_tests.erl b/src/fabric/test/fabric2_dir_prefix_tests.erl
index c7bc8bba4..e4e78a338 100644
--- a/src/fabric/test/fabric2_dir_prefix_tests.erl
+++ b/src/fabric/test/fabric2_dir_prefix_tests.erl
@@ -28,7 +28,7 @@ dir_prefix_test_() ->
% erlfdb, rexi and mem3 are all dependent apps for fabric. We make
% sure to start them so when fabric is started during the test it
% already has its dependencies
- test_util:start_couch([erlfdb, rexi, mem3])
+ test_util:start_couch([erlfdb, rexi, mem3, ctrace])
end,
fun(Ctx) ->
config:delete("fabric", "fdb_directory"),