You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2020/01/21 16:40:53 UTC

[couchdb] branch prototype/fdb-layer updated: Add `external` tag to opentrace events

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

iilyak 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 963f84b  Add `external`  tag to opentrace events
     new 6b1da76  Merge pull request #2451 from cloudant/tracing-external
963f84b is described below

commit 963f84bad08d0a0e5587ae2f1869c3563d4182d6
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Jan 14 02:41:50 2020 -0800

    Add `external`  tag to opentrace events
    
    This PR adds an ability to selectively enable opentracing for HTTP requests
    with X-B3-... headers. This is helpful in following cases:
    - tracing all requests with X-B3-... headers
      `all = (#{external := E}) when E == true -> true`
    - tracing all requests to specific database with X-B3-... headers
      ```
      all = (#{external := E, 'db.name' := Db})
        when E == true andalso Db == <<"foo">> -> true
      ```
    - tracing requests to specific endpoint with X-B3-... headers
      ```
      db.design.view.read = (#{external := E, 'design.id' := Name})
        when E == true andalso Name == <<"bar">> -> true
      ```
    
    I want to remind that we support following X-B3-... headers:
    
    - X-B3-TraceId
    - X-B3-SpanId
    - X-B3-ParentSpanId
    - B3 which is in the following format
      <TraceId>-<SpanId>-<1 | 0>-<ParentSpanId>
---
 src/chttpd/src/chttpd.erl | 12 +++++++-----
 src/ctrace/README.md      |  3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index c4bfa60..d5e7314 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -1250,6 +1250,7 @@ start_span(Req) ->
         [] -> <<"">>;
         [_ | _] -> filename:join(PathParts)
     end,
+    {IsExternalSpan, RootOptions} = root_span_options(MochiReq),
     Tags = maps:merge(#{
         peer => Peer,
         'http.method' => Method,
@@ -1257,21 +1258,22 @@ start_span(Req) ->
         'http.url' => MochiReq:get(raw_path),
         path_parts => Path,
         'span.kind' => <<"server">>,
-        component => <<"couchdb.chttpd">>
+        component => <<"couchdb.chttpd">>,
+        external => IsExternalSpan
     }, ExtraTags),
 
     ctrace:start_span(OperationName, [
         {tags, Tags},
         {time, Begin}
-    ] ++ maybe_root_span(MochiReq)).
+    ] ++ RootOptions).
 
-maybe_root_span(MochiReq) ->
+root_span_options(MochiReq) ->
     case get_trace_headers(MochiReq) of
         [undefined, _, _] ->
-            [];
+            {false, []};
         [TraceId, SpanId, ParentSpanId] ->
             Span = ctrace:external_span(TraceId, SpanId, ParentSpanId),
-            [{root, Span}]
+            {true, [{root, Span}]}
     end.
 
 parse_trace_id(undefined) ->
diff --git a/src/ctrace/README.md b/src/ctrace/README.md
index 6e40b43..3172f26 100644
--- a/src/ctrace/README.md
+++ b/src/ctrace/README.md
@@ -146,7 +146,10 @@ and logged.
 
 ```ini
 [tracing.filters]
+; trace all events
 ; all = (#{}) -> true
+; trace all events with X-B3-... headers
+; all = (#{external := External}) when External == true -> true
 ; database-info.read = (#{'http.method' := Method}) when Method == 'GET' -> true
 ; view.build = (#{'view.name' := Name}) when Name == "foo" -> 0.25
 ```