Git Product home page Git Product logo

Comments (7)

wu-sheng avatar wu-sheng commented on May 26, 2024

span will be created by the first HandlerFunc and closed by the last HandlerFunc,

What was wrong? This sentence is not clear.

from skywalking.

Ruff-nono avatar Ruff-nono commented on May 26, 2024

span will be created by the first HandlerFunc and closed by the last HandlerFunc,

What was wrong? This sentence is not clear.

I found that the Gin plugin has been changed to func (c *Context) Next(). However, this method will be handled multiple times by multiple middleware handlerFuncs in the route.
As a result, CreateEntrySpan is called every handlerFuncs and propagated by Invocation.SetContext() closed by the last handlerFunc, causing the segment to be incorrectly interrupted prematurely when customizing Gin middleware.

from skywalking.

wu-sheng avatar wu-sheng commented on May 26, 2024

Could you put a graph to explain this? You are using an instance level dynamic field, this should not be helpful is a handler instance repeatedly used in the process.

from skywalking.

Ruff-nono avatar Ruff-nono commented on May 26, 2024

when customize middleware in Gin, the trace info will lost , such as

router := gin.Default()
router.Use(func(c *gin.Context) {
        logger.Info("do something before handler")
	c.Next()
	logger.Info("do something after handler")
})

and the log like this, after has no trace info

2024-01-31 16:56:02 | info | [email protected]/context.go:174 | do something before handler | {"SW_CTX": "[Your_ApplicationName,[email protected],8ad58d8ac01611eea4c42672e7982bed.36.39184449623780005,8ad58d8ac01611eea4c42672e7982bed.36.39184449623780006,0]"}
2024-01-31 16:56:02 | info | [email protected]/context.go:174 | handle | {"SW_CTX": "[Your_ApplicationName,[email protected],8ad58d8ac01611eea4c42672e7982bed.36.39184449623780005,8ad58d8ac01611eea4c42672e7982bed.36.39184449623780006,0]"}
2024-01-31 16:56:02 | info | [email protected]/context.go:174 | do something after handler | {"SW_CTX": "[Your_ApplicationName,[email protected],N/A,N/A,-1]"}
[GIN] 2024/01/31 - 16:56:02 | 200 |       179.3µs |             ::1 | GET      "/hello"

from skywalking.

wu-sheng avatar wu-sheng commented on May 26, 2024

I could understand your case now, then, when the context gets reset in the after? Is it caused by stop span at the end of #Next, or somewhere else?

from skywalking.

Ruff-nono avatar Ruff-nono commented on May 26, 2024

because every middleware handlerFuncs could call #Next, then it will call #CreateEntrySpan in #BeforeInvoke and call span.End() in #AfterInvoke many times, but after span.End() first be Called by the last middleware handlerFunc, the TracingContext in current goroutine will be cleared, so the other handlerfuncs cannot get the TraceContext for use.

image

from skywalking.

wu-sheng avatar wu-sheng commented on May 26, 2024

OK, then there is typically solution for this, you should put a counter in the context of the chain. This counter increases one in before and minus one in after. Then, create span when the counter created, and stop span when counter back to zero.

Note, the counter should be kept in the request context.

from skywalking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.