Skip to content

Commit

Permalink
Only set the span parent ID if it is valid.
Browse files Browse the repository at this point in the history
If there is no parent span ID, we something nonsensical, so we need to
validate it.

Yes, this is hilarious.
  • Loading branch information
SamirTalwar committed Nov 21, 2023
1 parent fb03873 commit ee5d0a8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rust-connector-sdk/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub fn init_tracing(
// tracing crate requires all fields to be defined at creation time, so any fields that will be set
// later should be defined as Empty
pub fn make_span(request: &Request<Body>) -> Span {
use opentelemetry::trace::TraceContextExt;

let span = tracing::info_span!(
"request",
method = %request.method(),
Expand All @@ -83,7 +85,13 @@ pub fn make_span(request: &Request<Body>) -> Span {
let parent_context = global::get_text_map_propagator(|propagator| {
propagator.extract(&HeaderExtractor(request.headers()))
});
span.set_parent(parent_context);
// if there is no parent span ID, we something nonsensical, so we need to validate it
// (yes, this is hilarious)
let parent_context_span = parent_context.span();
let parent_context_span_context = parent_context_span.span_context();
if parent_context_span_context.is_valid() {
span.set_parent(parent_context);
}

span
}
Expand Down

0 comments on commit ee5d0a8

Please sign in to comment.