新增 trace attr

This commit is contained in:
2026-09-17 13:33:58 +08:00
parent 5103c08c2b
commit 2f0c6e6cb7
2 changed files with 31 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ func ApplyMiddlewares(app *fiber.App) {
EnableStackTrace: true,
}))
// metric
// otel
app.Use(otelfiber.Middleware())
// logger
@@ -45,12 +45,23 @@ func ApplyMiddlewares(app *fiber.App) {
return err
}
str := ""
if err != nil {
str = err.Error()
span.SetAttributes(attribute.String("http.response.error", err.Error()))
}
authCtx := auth.GetAuthCtx(c)
if authCtx != nil {
if authCtx.User != nil {
span.SetAttributes(attribute.Int("auth.user.id", int(authCtx.User.ID)))
}
if authCtx.Admin != nil {
span.SetAttributes(attribute.Int("auth.admin.id", int(authCtx.Admin.ID)))
}
if authCtx.Client != nil {
span.SetAttributes(attribute.Int("auth.client.id", int(authCtx.Client.ID)))
}
}
span.SetAttributes(attribute.String("http.response.error", str))
return err
})