-
Notifications
You must be signed in to change notification settings - Fork 63
Feat/trace generator #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/trace generator #38
Conversation
} | ||
|
||
if strings.HasPrefix(c.Response().Header().Get(echo.HeaderContentType), "application/json") { | ||
return json.RawMessage(storer.storedResponse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json.RawMessage
provided a little bit better formatting for JSON values than just string.
Example
{
message: "some message"
}
For string
{\n\"message\":\"some message\"\n}
} | ||
|
||
type TraceStarter struct { | ||
newUUID func() (uuid.UUID, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to pass request trace ID in HTTP headers to connect requests between services
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge with the current solution now.
Also, it is possible to achieve this with the built-in echo middleware, but it does not log the request body and requires workarounds to achieve the same functionality. Check please if we want to use it instead: https://echo.labstack.com/docs/middleware/logger#examples Here's example logg from it with tracer (it can be customized) {
"time": "2025-05-23T08:08:40.511738769Z",
"level": "INFO",
"source": {
"function": "github.com/nix-united/golang-echo-boilerplate/internal/server/routes.ConfigureRoutes.func2",
"file": "/app/internal/server/routes/routes.go",
"line": 52
},
"msg": "Received request",
"application": "my_awesome_app",
"hostname": "bf3764f3455c",
"val": {
"StartTime": "2025-05-23T08:08:40.511565142Z",
"Latency": 169407,
"Protocol": "HTTP/1.1",
"RemoteIP": "172.18.0.1",
"Host": "localhost:7788",
"Method": "POST",
"URI": "/posts",
"URIPath": "/posts",
"RoutePath": "/posts",
"RequestID": "",
"Referer": "",
"UserAgent": "PostmanRuntime/7.44.0",
"Status": 500,
"Error": {},
"ContentLength": "60",
"ResponseSize": 36,
"Headers": null,
"QueryParams": null,
"FormValues": null
},
"http": {
"request_body": "{\n \"title\": \"post title\",\n \"content\": \"post content\"\n}"
},
"trace": { "trace": "0196fc2f-e93f-78a1-a736-bef0a1771708", "index": 2 }
} |
🎫 Ticket Reference
No ticket.
📝 Changes
Refactor logging system. Introduced request trace.
POST /posts loggs
Example for 500 status code