-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tracing: add direct support for a span to spawn a child #932
Changes from 8 commits
a0c8036
d483a33
899df9e
4badb3b
5f38c1b
f6069c3
dc9f57f
3662645
e40a1b0
9176980
683687a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,20 @@ class Config { | |
/* | ||
* Basic abstraction for span. | ||
*/ | ||
class Span; | ||
|
||
typedef std::unique_ptr<Span> SpanPtr; | ||
|
||
class Span { | ||
public: | ||
virtual ~Span() {} | ||
|
||
virtual void setTag(const std::string& name, const std::string& value) PURE; | ||
virtual void finishSpan() PURE; | ||
virtual void injectContext(Http::HeaderMap& request_headers) PURE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about overrides for zipkin spans? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
virtual SpanPtr spawnChild(const std::string& name, SystemTime start_time) PURE; | ||
}; | ||
|
||
typedef std::unique_ptr<Span> SpanPtr; | ||
|
||
/** | ||
* Tracing driver is responsible for span creation. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
namespace Envoy { | ||
namespace Zipkin { | ||
|
||
ZipkinSpan::ZipkinSpan(Zipkin::Span& span) : span_(span) {} | ||
ZipkinSpan::ZipkinSpan(Zipkin::Span& span, Zipkin::Tracer& tracer) : span_(span), tracer_(tracer) {} | ||
|
||
void ZipkinSpan::finishSpan() { span_.finish(); } | ||
|
||
|
@@ -22,6 +22,29 @@ void ZipkinSpan::setTag(const std::string& name, const std::string& value) { | |
} | ||
} | ||
|
||
void ZipkinSpan::injectContext(Http::HeaderMap& request_headers) { | ||
// Set the trace-id and span-id headers properly, based on the newly-created span structure. | ||
request_headers.insertXB3TraceId().value(span_.traceIdAsHexString()); | ||
request_headers.insertXB3SpanId().value(span_.idAsHexString()); | ||
|
||
// Set the parent-span header properly, based on the newly-created span structure. | ||
if (span_.isSetParentId()) { | ||
request_headers.insertXB3ParentSpanId().value(span_.parentIdAsHexString()); | ||
} | ||
|
||
// Set the sampled header. | ||
request_headers.insertXB3Sampled().value(ZipkinCoreConstants::get().ALWAYS_SAMPLE); | ||
|
||
// Set the ot-span-context header with the new context. | ||
SpanContext context(span_); | ||
request_headers.insertOtSpanContext().value(context.serializeToString()); | ||
} | ||
|
||
Tracing::SpanPtr ZipkinSpan::spawnChild(const std::string& name, SystemTime start_time) { | ||
std::unique_ptr<SpanContext> context{new SpanContext(span_)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be allocated on a stack. SpanContext context(span_); |
||
return Tracing::SpanPtr{new ZipkinSpan(*tracer_.startSpan(name, start_time, *context), tracer_)}; | ||
} | ||
|
||
bool ZipkinSpan::hasCSAnnotation() { | ||
auto annotations = span_.annotations(); | ||
if (annotations.size() > 0) { | ||
|
@@ -94,24 +117,8 @@ Tracing::SpanPtr Driver::startSpan(Http::HeaderMap& request_headers, const std:: | |
new_zipkin_span = tracer.startSpan(request_headers.Host()->value().c_str(), start_time); | ||
} | ||
|
||
// Set the trace-id and span-id headers properly, based on the newly-created span structure. | ||
request_headers.insertXB3TraceId().value(new_zipkin_span->traceIdAsHexString()); | ||
request_headers.insertXB3SpanId().value(new_zipkin_span->idAsHexString()); | ||
|
||
// Set the parent-span header properly, based on the newly-created span structure. | ||
if (new_zipkin_span->isSetParentId()) { | ||
request_headers.insertXB3ParentSpanId().value(new_zipkin_span->parentIdAsHexString()); | ||
} | ||
|
||
// Set the sampled header. | ||
request_headers.insertXB3Sampled().value(ZipkinCoreConstants::get().ALWAYS_SAMPLE); | ||
|
||
// Set the ot-span-context header with the new context. | ||
SpanContext new_span_context(*new_zipkin_span); | ||
request_headers.insertOtSpanContext().value(new_span_context.serializeToString()); | ||
|
||
ZipkinSpanPtr active_span; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor, ZipkinSpanPtr active_span(new ZipkinSpan(*new_zipkin_span, tracer)); |
||
active_span.reset(new ZipkinSpan(*new_zipkin_span)); | ||
active_span.reset(new ZipkinSpan(*new_zipkin_span, tracer)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: ZipkinSpanPtr active_span(new ZipkinSpan(*new_zipkin_span, tracer)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is still a valid comment :) |
||
|
||
return std::move(active_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.
comments here in all these methods, sorry I've not put it in the first place