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

Simplify expression and improve perf to get parent span id #1088

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions opentelemetry-sdk/src/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,22 @@ impl opentelemetry_api::trace::Tracer for Tracer {
let span_kind = builder.span_kind.take().unwrap_or(SpanKind::Internal);
let mut attribute_options = builder.attributes.take().unwrap_or_default();
let mut link_options = builder.links.take();
let mut parent_span_id = SpanId::INVALID;
let trace_id;

let parent_span = if parent_cx.has_active_span() {
Some(parent_cx.span())
} else {
None
};

// Build context for sampling decision
if let Some(sc) = parent_span.as_ref().map(|parent| parent.span_context()) {
parent_span_id = sc.span_id();
trace_id = sc.trace_id();
} else {
trace_id = builder
.trace_id
.unwrap_or_else(|| config.id_generator.new_trace_id());
let (parent_span_id, trace_id) = {
if parent_cx.span().span_context().is_valid() {
(
parent_cx.span().span_context().span_id(),
parent_cx.span().span_context().trace_id(),
)
} else {
(
SpanId::INVALID,
builder
.trace_id
.unwrap_or_else(|| config.id_generator.new_trace_id()),
Copy link
Member

Choose a reason for hiding this comment

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

Hm I don't think this will have identical behavior to the previous implementation as children of invalid spans may be valid (have valid trace ids if not explicitly set to invalid in builder).

)
}
};

// In order to accomodate use cases like `tracing-opentelemetry` we there is the ability
Expand Down