summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2020-01-14 02:41:50 -0800
committerILYA Khlopotov <iilyak@apache.org>2020-01-14 03:00:04 -0800
commit963f84bad08d0a0e5587ae2f1869c3563d4182d6 (patch)
tree7eb09f50046057f2c024819f3d3dc55b326811db
parentab4eafab0d555881f118b2ab19678872814b5059 (diff)
downloadcouchdb-963f84bad08d0a0e5587ae2f1869c3563d4182d6.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.erl12
-rw-r--r--src/ctrace/README.md3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index c4bfa602f..d5e731423 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 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
```