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

[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 #12079

Open
2 of 3 tasks
Donghui0 opened this issue Apr 8, 2024 · 2 comments
Assignees
Labels
agent Language agent related. bug Something isn't working and you are sure it's a bug! go Go agent

Comments

@Donghui0
Copy link

Donghui0 commented Apr 8, 2024

Search before asking

  • 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.
image

The following is debug mode:
Gin CreateEntrySpan,ctx:
image

The first CreateExitSpan within the goroutine, ctx:
image

Second CreateExitSpan inside goroutine, ctx:
image

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

@Donghui0 Donghui0 added the bug Something isn't working and you are sure it's a bug! label Apr 8, 2024
@wu-sheng
Copy link
Member

wu-sheng commented Apr 8, 2024

Which version are you using? There was a relative fix in 0.4 release, apache/skywalking-go#161

@wu-sheng wu-sheng added agent Language agent related. go Go agent labels Apr 8, 2024
@Donghui0
Copy link
Author

Donghui0 commented Apr 8, 2024

Which version are you using? There was a relative fix in 0.4 release, apache/skywalking-go#161

version 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent Language agent related. bug Something isn't working and you are sure it's a bug! go Go agent
Projects
None yet
Development

No branches or pull requests

3 participants