Commit 1e85ff71 authored by Cloud User's avatar Cloud User

log http request id

parent c1877c32
......@@ -52,6 +52,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
......
......@@ -749,6 +749,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
......
......@@ -73,6 +73,7 @@ var producerMessagesBytes = make(chan bytesAndHeader, 1000)
var consumerMessages = make(chan string)
const TaskIdAtrr = "Task-Id"
const RequestId = "Request_Id"
func kafkaProducerBytes() {
......@@ -1003,10 +1004,27 @@ func ApiOrJWT(c *fiber.Ctx) error {
reqHeaders := c.GetReqHeaders()
if taskHeaders, ok := reqHeaders[TaskIdAtrr]; ok {
if taskHeaders == nil || len(taskHeaders) == 0 {
return c.SendString(fmt.Sprintf("Please provide http header %s value, right now the value is %v.", TaskIdAtrr, taskHeaders))
}
} else {
return c.SendString(fmt.Sprintf("Please provide http header %s .", TaskIdAtrr))
}
if RequestIdHeaders, ok := reqHeaders[RequestId]; ok {
if RequestIdHeaders == nil || len(RequestIdHeaders) == 0 {
return c.SendString(fmt.Sprintf("Please provide http header %s value, right now the value is %v.", RequestId, RequestIdHeaders))
}
} else {
return c.SendString(fmt.Sprintf("Please provide http header %s .", RequestId))
}
slogfiber.AddCustomAttributes(c, slog.String(TaskIdAtrr, reqHeaders[TaskIdAtrr][0]))
baseAttributes := []slog.Attr{}
baseAttributes = append(baseAttributes, slog.String(TaskIdAtrr, reqHeaders[TaskIdAtrr][0]))
baseAttributes = append(baseAttributes, slog.String(RequestId, reqHeaders[RequestId][0]))
newAttributes := append(baseAttributes, slog.String("match_path", c.Route().Path))
slog.LogAttrs(c.UserContext(), slog.LevelInfo, "new Api or JWT reuqest", newAttributes...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment