Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Consolidating Span and RootSpan to allow Spans to recursively have children #441

Merged
merged 7 commits into from
Apr 11, 2019
Merged

Conversation

kenashcraft
Copy link
Contributor

@kenashcraft kenashcraft commented Mar 22, 2019

Consolidate the functionality of Span and RootSpan to allow Spans to recursively have children.

  • Moved the functionality from Span into BaseSpan and then renamed the files. Unfortunately, that makes for a pretty terrible diff in Github. Try pulling from my fork and doing git diff master:packages/opencensus-core/src/trace/model/span-base.ts span-refactor:packages/opencensus-core/src/trace/model/span.ts
  • Ditto for no-record-span.ts
  • I had to make more extensive changes to tracez.page-handler.ts. Please pay attention to that one.
  • I added some tests to test-root-span.ts. Please advise whether that is the appropriate place for those tests (vs test-span.ts) and whether you can think of additional tests.
  • I have not updated all of the exporters to use allDescendants() yet. They still get just the root's immediate children. I think we can do that in a subsequent PR.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

I think this is a good step in the right direction. I would also want Tracer to support trace contexts that aren't root spans, and maybe even to collapse the distinction between Span and RootSpan.

But doing this step-by-step makes sense to me, and I think this general approach is a decent first step.

@mayurkale22 what do you think?

@codecov-io
Copy link

codecov-io commented Apr 8, 2019

Codecov Report

Merging #441 into master will increase coverage by 0.4%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #441     +/-   ##
=========================================
+ Coverage   94.34%   94.75%   +0.4%     
=========================================
  Files         150      148      -2     
  Lines        8884     9940   +1056     
  Branches      731      750     +19     
=========================================
+ Hits         8382     9419   +1037     
- Misses        502      521     +19
Impacted Files Coverage Δ
src/trace/propagation/noop-propagation.ts 50% <0%> (-50%) ⬇️
src/trace/model/no-record/no-record-root-span.ts 45.83% <0%> (-10.05%) ⬇️
src/internal/cls.ts 91.66% <0%> (-8.34%) ⬇️
src/tags/propagation/text-format.ts 95% <0%> (-5%) ⬇️
src/tags/propagation/variant-encoding.ts 95.83% <0%> (-4.17%) ⬇️
src/trace/model/span.ts 97.6% <0%> (-2.41%) ⬇️
src/trace/model/root-span.ts 96% <0%> (-1.96%) ⬇️
src/tags/propagation/binary-serializer.ts 95.23% <0%> (-0.92%) ⬇️
test/test-ioredis.ts 96.96% <0%> (-0.09%) ⬇️
test/test-zpages.ts 99.62% <0%> (-0.01%) ⬇️
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbc618b...d5895e9. Read the comment docs.

@kenashcraft
Copy link
Contributor Author

kenashcraft commented Apr 8, 2019

@mayurkale22 @draffensperger Please take a look. PR description updated. All tests are passing. I'd like to get this merged quickly since it touches so many files that keeping it up to date is a challenge.

Thanks to @hekike for helping me keep this PR up to date!

@kenashcraft kenashcraft changed the title Initial sketch of consolidating Span and RootSpan Consolidating Span and RootSpan to allow Spans to recursively have children Apr 8, 2019
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes labels Apr 8, 2019
@hekike
Copy link
Contributor

hekike commented Apr 8, 2019

I signed the CLA in the meantime.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

First pass. Looks great!

Nit: Should we rename rootSpan -> span & rootSpans -> spans variable names in seperate PR?

packages/opencensus-core/src/trace/model/span.ts Outdated Show resolved Hide resolved
packages/opencensus-core/src/trace/model/span.ts Outdated Show resolved Hide resolved
packages/opencensus-core/src/trace/model/span.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

LGTM pending a few minor comments.

I do support getting this in given the number of files it touches and think that further cleanup / improvement should be in follow up PRs.

/** Gets the ID of the parent span. */
get parentSpanId(): string {
if (!this.parentSpan) {
return 'no-parent';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this just return the empty string ('') which means "no parent" in other context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/** Recursively gets the descendant spans. */
allDescendants(): types.Span[] {
console.log('Calling allDescendants', this.name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this and the other log lines below be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. Sorry about that.

traceId: this.traceId,
spanId: this.id,
name: this.name,
options: 0x1, // always traced
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming this was adapted from SpanBase - will it cause all spans to be sampled? @mayurkale22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... I didn't touch this line, just moved it.

Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this was adapted from SpanBase - will it cause all spans to be sampled?

No. The Sampling Decision happens at the top level (when we create the root span using startRootSpan). Depending on the decision, it creates either RootSpan (which has options set to 0x1) or NoRecordRootSpan (options set to 0x0). Does it make sense?

duration: childSpan.duration
}));
}
// tslint:disable-next-line:no-any
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this doesn't use any below, can you remove this tslint disable comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Ken Ashcraft and others added 5 commits April 9, 2019 09:20
Squashed commits:
[a4f2234] Get the test passing
[8276c98] Get allDescendants() working
[379b2eb] Big refactor, tests are mostly passing
[6d93312] Lerna handles cross-package dependencies
[3567e2e] Rough draft of making Span and RootSpan almost identical
[eba18f3] Set 'shared' based on the type of span
[b56a884] Reformat tests
[b1b6dfb] Use parentSpanId if provided
[9d4e601] Tests that ensure nested spans are properly translated for Zipkin
[585034e] Add tests for nested spans.
@mayurkale22
Copy link
Member

Ping @googlebot

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes labels Apr 9, 2019
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

ℹ️ Googlers: Go here for more info.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution.

@mayurkale22 mayurkale22 merged commit abd41db into census-instrumentation:master Apr 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants