Skip to content
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

Recover the OT context header from the B3 headers if not propagated #1702

Merged
merged 5 commits into from
Sep 21, 2017

Conversation

objectiser
Copy link
Contributor

Resolves #1364

This fixes the issue by detecting that the OtSpanContext header has not been propagated, but the B3 headers have - and therefore will use those values instead.

This means that when an application is only concerned with propagating the span context, they only need to propagate the OtSpanContext header (not the B3 headers) - which is also supported prior to this PR. However if they wish to use a B3 compatible tracer to augment the tracing information within their application, then this tracer would only need to propagate the B3 headers to any outbound (Egress) connections.

So this will simplify the manual propagation case - only one header to propagate, while still allowing more complex tracing requirements to be addressed.

If this change is acceptable, then we may want to consider removing the B3 header propagation from the docs and examples, and instead have a section discussing the case where the application can enhance the default tracing information by using a suitable tracer directly?

@objectiser
Copy link
Contributor Author

Would be good if someone could independently test this using the zipkin-tracing example - simply remove the 'X-Ot-Span-Context', line from the TRACE_HEADERS_TO_PROPAGATE list in https://github.com/envoyproxy/envoy/blob/master/examples/front-proxy/service.py and you should still see the same trace result in the zipkin UI with two spans, one associated with service1 and the child span associated with service2 .

zipkin-no-ot-span-context

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @objectiser. The approach looks good to me. @rshriram @fabolive @adriancole if you could comment.

@@ -107,6 +107,20 @@ Tracing::SpanPtr Driver::startSpan(const Tracing::Config& config, Http::HeaderMa

new_zipkin_span =
tracer.startSpan(config, request_headers.Host()->value().c_str(), start_time, context);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: del newline here and at 123

} else if (request_headers.XB3TraceId() && request_headers.XB3SpanId()) {
uint64_t parentId(0);
if (request_headers.XB3ParentSpanId()) {
parentId = std::stoull(request_headers.XB3ParentSpanId()->value().c_str(), nullptr, 16);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use https://github.com/envoyproxy/envoy/blob/master/source/common/common/utility.h#L92 for string -> int conversions and handle error (also please add tests for that).

@mattklein123
Copy link
Member

If this change is acceptable, then we may want to consider removing the B3 header propagation from the docs and examples, and instead have a section discussing the case where the application can enhance the default tracing information by using a suitable tracer directly?

Agreed. In general, I think we should have better tracing docs. Would love any updates you want to do here: https://envoyproxy.github.io/envoy/intro/arch_overview/tracing.html and elsewhere.

@codefromthecrypt
Copy link
Contributor

Not sure if I grok the relationship between fixing B3 then removing docs for it. It is a widely used format.

On the main topic, the change appears sound!

uint64_t parentId(0);
if (!StringUtil::atoul(request_headers.XB3TraceId()->value().c_str(), traceId, 16)) {
throw EnvoyException(fmt::format("invalid hex string for XB3TraceId '{}'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC you can't safely throw here. It will crash the server. I think you probably want to return a null span or something like that.

if (!StringUtil::atoul(request_headers.XB3TraceId()->value().c_str(), traceId, 16)
|| !StringUtil::atoul(request_headers.XB3SpanId()->value().c_str(), spanId, 16)
|| (request_headers.XB3ParentSpanId() && !StringUtil::atoul(request_headers.XB3ParentSpanId()->value().c_str(), parentId, 16))) {
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd probably return nullspan here to be on a safe side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry yes I meant NullSpan (not nullptr)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem will sort it tomorrow.

Copy link
Member

@RomanDzhabarov RomanDzhabarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except that small comment.

@fabolive
Copy link
Contributor

@objectiser At a high level, the approach makes sense. I agree with @adriancole that removing B3 from the documentation does not sound right. In fact, now that we have a clear way to distinguish ingress from egress we got to a point where the entire implementation of Zipkin support in Envoy could be reworked so that only B3 headers are used. Could this be part of the current PR, or do we want a separate PR for that?

@objectiser
Copy link
Contributor Author

@fabolive I think it would be better to discuss in a separate issue.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, small nit. Thanks.

@@ -112,19 +112,11 @@ Tracing::SpanPtr Driver::startSpan(const Tracing::Config& config, Http::HeaderMa
uint64_t traceId(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't catch this before. Please use snake_case for variables (trace_id, span_id, etc.).

@mattklein123 mattklein123 merged commit 4574487 into envoyproxy:master Sep 21, 2017
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Pickup up the following changes from Envoy repo a82962c...bbef2aa
Risk Level: Low
Testing: N/A
Docs Changes: N/A
Release Notes: N/A
Signed-off-by: Rafal Augustyniak <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Pickup up the following changes from Envoy repo a82962c...bbef2aa
Risk Level: Low
Testing: N/A
Docs Changes: N/A
Release Notes: N/A
Signed-off-by: Rafal Augustyniak <[email protected]>
Signed-off-by: JP Simard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracing headers not propagated when x-ot-span-context header is omitted
5 participants