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

util/tracing: fix an edge case for active span registration #70850

Merged
merged 2 commits into from
Oct 1, 2021

Conversation

andreimatei
Copy link
Contributor

Before this patch, a span with a no-op parent (as opposed to a span
with no parent), would not be present in the active spans registry. The
code was confused: the span didn't qualify as a "local root" because it
had a local parent, but of course it also wasn't really recorded by the
local parent cause a no-op span can't record anything. As such, the span
in question was missing from the registry.
This patch makes a span with a no-op parent behave like a root span.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@tbg tbg requested review from a team and removed request for tbg and irfansharif September 29, 2021 07:04
@andreimatei andreimatei force-pushed the tracing.noop-parent branch 2 times, most recently from 11d726c to f07be42 Compare September 30, 2021 16:39
Copy link
Collaborator

@rimadeodhar rimadeodhar left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @andreimatei)


pkg/util/tracing/span_options.go, line 147 at r2 (raw file):

// obligation to manually propagate the trace data to the parent Span.
func WithParentAndAutoCollection(sp *Span) SpanOption {
	if sp == nil {

Nit: This can be written as:

if sp == nil || sp.IsNoop() {
    return (*parentAndAutoCollectionOption)(nil)
}
return (*parentAndAutoCollectionOption)(sp)

This was hidden in an internal helper, but it's such a common concern
that it deserves better ergonomics, and it even deserves to be public.

Release note: None
Before this patch, a span with a no-op parent (as opposed to a span
with no parent), would not be present in the active spans registry. The
code was confused: the span didn't qualify as a "local root" because it
had a local parent, but of course it also wasn't really recorded by the
local parent cause a no-op span can't record anything. As such, the span
in question was missing from the registry.
This patch makes a span with a no-op parent behave like a root span.

Release note: None
Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @rimadeodhar)


pkg/util/tracing/span_options.go, line 147 at r2 (raw file):

Previously, rimadeodhar (Rima Deodhar) wrote…

Nit: This can be written as:

if sp == nil || sp.IsNoop() {
    return (*parentAndAutoCollectionOption)(nil)
}
return (*parentAndAutoCollectionOption)(sp)

done

@craig
Copy link
Contributor

craig bot commented Oct 1, 2021

Build succeeded:

@craig craig bot merged commit 3426e8d into cockroachdb:master Oct 1, 2021
@andreimatei andreimatei deleted the tracing.noop-parent branch January 22, 2022 22:05
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.

3 participants