[Bug] When the sampling rate is 0 and the code exists across goroutine, ExitSpan has a problem of failure to create. err: span type is wrong
Search before asking
- [X] I had searched in the issues and found no similar issues.
Apache SkyWalking Component
Go Agent (apache/skywalking-go)
What happened
In the following scenario, Gin handler serves as the entry point and calls 2 mongo operations through goroutine.
Gin -- EntrySpan (NewNoopSpan() -> SET_GLS(NoopSpan{stackCount: 1})) | (sync.Group) MongoClient ExitSpan (GET_GLS() -> NoopSpan{stackCount:0} -> noop.enterNoSpan() -> span.End() -> SET_GLS(nil) ) | (Why stackCount is 0 ?) MongoClient ExitSpan (GET_GLS() -> nil)
In the 2nd ExitSpan, ctx.ActiveSpan() returns nil, Then createSpan0() returns NoopSpan.
The following is debug mode:
Gin CreateEntrySpan,ctx:
The first CreateExitSpan within the goroutine, ctx:
Second CreateExitSpan inside goroutine, ctx:
What you expected to happen
In the first ExitSpan, The stackCount of ActiveSpan() obtained by GetTracingContext() should be 1. in the 2nd ExitSpan, getTracingContext() -> ActiveSpan() Should not be nil.
How to reproduce
After changing the sampling rate to 0, run the following test code.
package main
import (
"fmt"
_ "github.com/apache/skywalking-go"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"golang.org/x/sync/errgroup"
)
type ErrorGroup struct {
errgroup.Group
}
func main() {
r := gin.Default()
r.GET("/mongo_get", mongoGet)
r.Run()
}
func mongoGet(c *gin.Context) {
var e ErrorGroup
var m, _ = mongo.Connect(c, options.Client().ApplyURI("mongodb://127.0.0.1:27017"))
filter := bson.D{{"name", "test"}}
e.Go(func() (err error) {
collection := m.Database("demo").Collection("testCollection")
_, err = collection.Find(c, filter)
if err != nil {
return err
}
fmt.Println("first Find Done")
_, err = collection.Find(c, filter)
if err != nil {
return err
}
fmt.Println("second Find Done")
return nil
})
err := e.Wait()
if err != nil {
fmt.Println(err)
}
}
Observe the log, you can find that the log will print the following error:
cannot create exit span on mongo client: span type is wrong
Anything else
No response
Are you willing to submit a pull request to fix on your own?
- [ ] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Which version are you using? There was a relative fix in 0.4 release, https://github.com/apache/skywalking-go/pull/161
Which version are you using? There was a relative fix in 0.4 release, apache/skywalking-go#161
version 0.4.0
Which version are you using? There was a relative fix in 0.4 release, apache/skywalking-go#161
version 0.4.0
Please check gmail to discuss the same issue,ty
Recheck 0.5. It should have been fixed.