新增 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

16
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "main",
"type": "go",
"request": "launch",
"mode": "debug",
"cwd": "${workspaceFolder}",
"program": "cmd/main",
}
]
}

View File

@@ -25,7 +25,7 @@ func ApplyMiddlewares(app *fiber.App) {
EnableStackTrace: true, EnableStackTrace: true,
})) }))
// metric // otel
app.Use(otelfiber.Middleware()) app.Use(otelfiber.Middleware())
// logger // logger
@@ -45,12 +45,23 @@ func ApplyMiddlewares(app *fiber.App) {
return err return err
} }
str := ""
if err != nil { 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 return err
}) })