Refactors tracing handler to use HttpServerParser #52
Conversation
This commit introduces an implementaton of HttpServerParser and refactors the server tracing handler such that span name customization is done via the HttpServerParser instead of directly in the tracing handler. In order to make this work, needed to add a wrapper around the standard Ratpack Response so that things like the PathBinding and original ServerRequest are available to the HttpServerParser. Closes #51
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
============================================
- Coverage 79.9% 79.82% -0.08%
- Complexity 33 36 +3
============================================
Files 6 7 +1
Lines 209 228 +19
Branches 7 7
============================================
+ Hits 167 182 +15
- Misses 35 37 +2
- Partials 7 9 +2
Continue to review full report at Codecov.
|
Looks good. FYI I will be raising something soon for "http.template", which is a tag that is uniform across templated requests, though not guaranteed to be a URI template. |
@adriancole thanks for taking a look! I'm wondering if I can get rid of all the explicit Span start/finish stuff that's in ratpack-zipkin/src/main/java/ratpack/zipkin/internal/DefaultServerTracingHandler.java Lines 46 to 55 in ae1a836
|
|
||
//create a scope so that we can @Inject a SpanCustomizer into | ||
//handlers and add tags, annotations, etc. | ||
final Tracer.SpanInScope scope = tracing.tracer().withSpanInScope(span); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually know whether this is "a thing" - i.e. wanting to be able @Inject
a SpanCustomizer
into a handler and add tags, etc. I guess it might be useful if it's something that you don't want to implement as a general "policy" using something like a custom HttpServerParser
¯\(ツ)/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe harder hitting comment could be.. "place the scan in scope so that downstream code, such as logging can see the ids"
Not needed anymore because Brave's HttpServerHandler takes care of all this now.
c8f625f
to
0a79dbb
Compare
ctx.getResponse().beforeSend(response -> { | ||
span.name(spanNameProvider.spanName(request, Optional.ofNullable(ctx.getPathBinding()))); | ||
handler.handleSend(response, null, span); | ||
span.finish(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you asked.. yes, removing explicit start/finish was a good choice!
This commit introduces an implementaton of
HttpServerParser
andrefactors the server tracing handler such that span name customization
is done via the
HttpServerParser
instead of directly in the tracinghandler.
In order to make this work, needed to add a wrapper around the standard
Ratpack
Response
so that things like thePathBinding
and originalServerRequest
are available to theHttpServerParser
.Closes #51