diff options
author | ILYA Khlopotov <iilyak@apache.org> | 2020-01-14 02:41:50 -0800 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-03-02 12:26:22 -0600 |
commit | e6c4ca3a415cae873f13fd61fa19219985326502 (patch) | |
tree | af743975b98e22c765bd129fe7a4aa08050e3007 | |
parent | f358971f6ff9673af289fcdb2bbc12c09ada5d3a (diff) | |
download | couchdb-e6c4ca3a415cae873f13fd61fa19219985326502.tar.gz |
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>
-rw-r--r-- | src/chttpd/src/chttpd.erl | 12 | ||||
-rw-r--r-- | 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 7fc9cffd4..848fdcafb 100644 --- a/src/chttpd/src/chttpd.erl +++ b/src/chttpd/src/chttpd.erl @@ -1252,6 +1252,7 @@ start_span(Req) -> [] -> <<"">>; [_ | _] -> filename:join(PathParts) end, + {IsExternalSpan, RootOptions} = root_span_options(MochiReq), Tags = maps:merge(#{ peer => Peer, 'http.method' => Method, @@ -1259,21 +1260,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 6e40b434c..3172f268b 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 ``` |