Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Conversation

@kagaya85
Copy link
Member

Now the Span.End() method will get panic when call it repeatedly, to improve the robustness, we can add a IsValid method to check if the current span is still valid in the context, and according to SkyAPM/go2sky-plugins#40 (comment), we can provide this method to avoid creating a span from a invalid parent span

For a valid span, the EndTime value shoud be zero, and after call End(), it will be assigned the value of time.Now(), so I check this value to determine if current span is valid:

func (ds *defaultSpan) IsValid() bool {
	return ds.EndTime.IsZero()
}

This PR will add a new method to the Span interface, so we may need to consider if it caused a break change and it may not be thread-safe in some concurrency scenarios.

@kagaya85 kagaya85 added the enhancement New feature or request label Dec 28, 2021
@kagaya85 kagaya85 requested a review from rainbend December 28, 2021 05:56
@codecov-commenter
Copy link

codecov-commenter commented Dec 28, 2021

Codecov Report

Merging #141 (b4a580d) into master (09e1525) will increase coverage by 0.49%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #141      +/-   ##
==========================================
+ Coverage   69.32%   69.82%   +0.49%     
==========================================
  Files          17       17              
  Lines         890      898       +8     
==========================================
+ Hits          617      627      +10     
+ Misses        226      224       -2     
  Partials       47       47              
Impacted Files Coverage Δ
noop.go 100.00% <100.00%> (+14.28%) ⬆️
segment.go 93.27% <100.00%> (+0.23%) ⬆️
span.go 100.00% <100.00%> (ø)

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 09e1525...b4a580d. Read the comment docs.

@kagaya85 kagaya85 force-pushed the feat/span-valid-check branch from 2c88168 to 3287538 Compare December 28, 2021 06:24
noop.go Outdated
}

func (*NoopSpan) IsValid() bool {
return false
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to keep no-op span always valid? The codes would expect a span valid in most cases, right?

Copy link
Member

Choose a reason for hiding this comment

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

The reason I think about this is, if return false always, we will face a case a new created span is Invalid, which could cause some unexpected bugs switching from tracing to noop mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's true, I thought about it for a while, the only side-effect is the no-op span is always be valid, even after callling End, I will modify it

@wu-sheng wu-sheng added this to the 1.4.0 milestone Dec 28, 2021
@wu-sheng wu-sheng merged commit 343dbb7 into SkyAPM:master Dec 28, 2021
@kagaya85 kagaya85 deleted the feat/span-valid-check branch December 28, 2021 09:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants