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

tracing: make Span.crdbSpan a pointer #56238

Merged
merged 1 commit into from
Nov 4, 2020

Conversation

tbg
Copy link
Member

@tbg tbg commented Nov 3, 2020

A Span essentially fans out over any subset of the below:

  • CRDB trace span
  • net/trace span
  • external opentracing-comatible tracer Span

The latter two are already pointers, which means that there is a
convenient check for their absence in tracing-internal code.

This wasn't true for crdbSpan, which has bitten me in the past.

Make things more idiomatic by using a pointer for this one, too.
As currently written, our tracer will always populate the crdbSpan
whenever net/trace or opentracing tracers are active. However,
there is no good reason to do that, and even if there were, it
should not reflect as a fundamental requirement in the code.

One nice outcome of this change is that the noopSpan is now
&Span{tracer: t}, and all fields except for the tracer are nil,
meaning that any bug around noop spans will quickly manifest as an NPE.
(One past bug involved erroneously assigning an operation name to the
noopSpan).

Other than a few clarification that resulted from the pointer change,
this commit also improves startSpanGeneric to avoid populating a
struct's internals after the initial assignment, a pattern which I
have found easier to get wrong. Now, all ingredients are held in
local variables, which are assigned to crdbSpan wholesale.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@tbg tbg force-pushed the tracing-nil-crdbspan branch from 3723545 to 29a8aab Compare November 3, 2020 14:42
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @irfansharif, @knz, @RaduBerinde, and @tbg)


pkg/util/tracing/span.go, line 186 at r1 (raw file):

	tracer *Tracer // never nil

	// Internal trace Span; nil if not tracing to crdb.

[nit] mention that this is allocated together with the Span in a single object so it doesn't mean a separate allocation

pkg/util/tracing/shadow.go Outdated Show resolved Hide resolved
pkg/util/tracing/tags.go Outdated Show resolved Hide resolved
pkg/util/tracing/span.go Outdated Show resolved Hide resolved
@tbg tbg force-pushed the tracing-nil-crdbspan branch from 29a8aab to eb7aabb Compare November 3, 2020 22:07
A `Span` essentially fans out over any subset of the below:

- CRDB trace span
- net/trace span
- external opentracing-comatible tracer Span

The latter two are already pointers, which means that there is a
convenient check for their absence in tracing-internal code.

This wasn't true for crdbSpan, which has bitten me in the past.

Make things more idiomatic by using a pointer for this one, too.
As currently written, our tracer will always populate the crdbSpan
whenever net/trace or opentracing tracers are active. However,
there is no good reason to do that, and even if there were, it
should not reflect as a fundamental requirement in the code.

One nice outcome of this change is that the noopSpan is now
`&Span{tracer: t}`, and all fields except for the tracer are nil,
meaning that any bug around noop spans will quickly manifest as an NPE.
(One past bug involved erroneously assigning an operation name to the
noopSpan).

Other than a few clarification that resulted from the pointer change and
some cleanup around log tags, this commit also improves
`startSpanGeneric` to avoid populating a struct's internals after the
initial assignment, a pattern which I have found easier to get wrong.
Now, all ingredients are held in local variables, which are assigned to
`crdbSpan` wholesale.

Release note: None
@tbg tbg force-pushed the tracing-nil-crdbspan branch from eb7aabb to 8010c90 Compare November 4, 2020 08:53
@tbg tbg requested a review from irfansharif November 4, 2020 08:54
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

bors r=RaduBerinde,irfansharif

TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @irfansharif and @knz)


pkg/util/tracing/shadow.go, line 100 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

I think we're missing a word here?

Done.


pkg/util/tracing/span.go, line 630 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

[nit] Break this line up, too many parens.

Done.


pkg/util/tracing/tags.go, line 52 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

[nit] swap the argument order here, will make the call sites look much nicer.

Done.

@craig
Copy link
Contributor

craig bot commented Nov 4, 2020

Build succeeded:

@craig craig bot merged commit b03fb74 into cockroachdb:master Nov 4, 2020
@tbg tbg deleted the tracing-nil-crdbspan branch November 4, 2020 09:33
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.

4 participants