新增 trace attr
This commit is contained in:
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal 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",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user