You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/11/20 22:01:38 UTC
[couchdb] 05/05: Trace fdb transactions
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch opentracing-pd
in repository https://gitbox.apache.org/repos/asf/couchdb.git
View the commit online:
https://github.com/apache/couchdb/commit/dfbebbe5a2cd983b527a17a2f01e6b9e947ad54b
commit dfbebbe5a2cd983b527a17a2f01e6b9e947ad54b
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Nov 12 16:21:55 2019 +0000
Trace fdb transactions
---
src/fabric/src/fabric.app.src | 1 +
src/fabric/src/fabric2_fdb.erl | 47 ++++++++++++++++++++++------
src/fabric/test/fabric2_dir_prefix_tests.erl | 2 +-
3 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/src/fabric/src/fabric.app.src b/src/fabric/src/fabric.app.src
index 77260f9..0538b19 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 0d74138..fb2891b 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 c7bc8bb..e4e78a3 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"),