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

gin context with tracing not work #3993

Closed
pepea23 opened this issue Jun 13, 2024 · 6 comments
Closed

gin context with tracing not work #3993

pepea23 opened this issue Jun 13, 2024 · 6 comments

Comments

@pepea23
Copy link

pepea23 commented Jun 13, 2024

when implementing use otel tracing like this
image

and apply to router like "router.POST("/v4/*xxxx", gatewayPostHandler, WithTracer())"

then tried to get a trace I found that gin context does not save trace id and span id it empty so how to reproduce the problem?

handler function
image
trace_id and span_id is empty

GetTraceIds function
image

Environment

  • go version: 1.22.4
  • gin version (or commit ref): github.com/gin-gonic/gin v1.10.0
@FarmerChillax
Copy link
Contributor

FarmerChillax commented Jun 17, 2024

problem locating the hasRequestContext function return False

gin/context.go

Line 1240 in 9c081de

func (c *Context) hasRequestContext() bool {

It seems that the problem is caused by the ContextWithFallback field, but I am not sure what this field does.

Solution:

// ...
app := gin.Default()
app.ContextWithFallback = true
// ...

@JimChenWYU
Copy link

router.POST("/v4/*xxxx", gatewayPostHandler, WithTracer())

replace by

router.POST("/v4/*xxxx", WithTracer(), gatewayPostHandler)

can it work ?

@mgerasimchuk
Copy link

Faced a similar issue too..

Using tracing middleware instead of a handlers chain will help you

@FarmerChillax
Copy link
Contributor

FarmerChillax commented Oct 15, 2024

This issue is same with #4074

Add example in gin-gonic/examples#171, hope this helps for you @mgerasimchuk @pepea23 @JimChenWYU

@FarmerChillax
Copy link
Contributor

It seems that the problem is caused by the ContextWithFallback field, but I am not sure what this field does.

Do I need to open a new issue to track this? @appleboy

@appleboy
Copy link
Member

@FarmerChillax Yes. Please open the new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants