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

🤗 [Question]: Otelfiber - How to set span status to Error on panic? #810

Open
3 tasks done
matteobassan opened this issue Oct 8, 2023 · 0 comments
Open
3 tasks done
Labels
🤔 Question Further information is requested

Comments

@matteobassan
Copy link

Question Description

I've been using otel-fiber for a while, and I've noticed that by editing the fiber.go (around line 123) file in this way, I can set the main span status to error:

if err := c.Next(); err != nil {
	span.RecordError(err)
	span.SetStatus(codes.Error, err.Message) //<-- added this line
			
	// invokes the registered HTTP error handler
	// to get the correct response status code
	_ = c.App().Config().ErrorHandler(c, err)
}

Now, this solution works every time there is an error returned, but clearly not when there is a panic inside the handler function or one of the sub-functions, since no error is returned from the handler. I checked with breaks in debug mode, and the program never enters the if statemen, so the span is not set to Error.
What sounds strange is that the error is still recorded and logged as "event" in the span, and i can find it in the Uptrace application, with all the exception-related info, even if span.RecordError(err) is (apparently) never called.

Can anyone explain this behavior? I'm sure I'm missing something.

Is worth noting that i am using the recover middleware, in this order:

router.Use(logger.New())
router.Use(recover.New())
router.Use(cors.New())
router.Use(otelfiber.Middleware())

Thanks

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@matteobassan matteobassan added the 🤔 Question Further information is requested label Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant