修复请求错误消息上报问题

This commit is contained in:
2026-05-13 18:07:44 +08:00
parent ccbc6f0b67
commit 80f04c92ec
2 changed files with 16 additions and 65 deletions

View File

@@ -22,6 +22,9 @@ func ApplyMiddlewares(app *fiber.App) {
EnableStackTrace: true,
}))
// metric
app.Use(otelfiber.Middleware())
// logger
app.Use(logger.New(logger.Config{
Next: func(c *fiber.Ctx) bool {
@@ -29,8 +32,7 @@ func ApplyMiddlewares(app *fiber.App) {
},
}))
// metric
app.Use(otelfiber.Middleware())
// 补充 otel span attr
app.Use(func(c *fiber.Ctx) error {
err := c.Next()
@@ -39,16 +41,12 @@ func ApplyMiddlewares(app *fiber.App) {
return err
}
status := c.Response().StatusCode()
body := []byte{}
if status < 200 || status >= 300 {
body = c.Response().Body()
if len(body) > 1024 {
body = body[:1024]
}
str := ""
if err != nil {
str = err.Error()
}
span.SetAttributes(attribute.String("http.response.error", string(body)))
span.SetAttributes(attribute.String("http.response.error", str))
return err
})