SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
448 stars 122 forks source link

feat: add validity check for span #141

Closed kagaya85 closed 2 years ago

kagaya85 commented 2 years ago

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 https://github.com/SkyAPM/go2sky-plugins/pull/40#issuecomment-1001549312, 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.

codecov-commenter commented 2 years ago

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%) :arrow_up:
segment.go 93.27% <100.00%> (+0.23%) :arrow_up:
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.