Logging in a private rest api

Hi guys,

I never logged at production grade so my questions may be dumb.

In my microservice app, only the gateway is logging, other services only return errors to each other up to the gateway using this structure:

type restErr struct {     
    // sent to the frontend
	ErrStatus  int    `json:"status"`  // HTTP Status Code
	ErrTitle   string `json:"title"`   // The string representation of the Status Code like "bad_request"
	ErrMessage string `json:"message"` // An optional message send to the front_end

    // not sent to the frontend, only used for logging
	ErrError    error  `json:"error"`     // Raw error returned by a DB, another Servive or whatever
	ErrErrorMsg string `json:"error_msg"` // String representation of ErrError
	ErrCode     string `json:"code"`      // Raw error code from the DB or another service

The errors are wrapped by each layer of each microservice up to the gateway which logs an error like this one:

2023-04-29T09:14:44+04:00 ERR | can't do what you want me to | error="gw.controllerX.MethodX: gw.httpclientY.MethodY: service1.controllerX.MethodX: service1.serviceY.MethodY: service2.controllerX.MethodX: service2.serviceY.MethodY: service2.repositoryY.MethodY: error 9009 in database" code=9009 correlationID=cgva1dg3lcjadv69n180 service=gw status=500

I really have a doubt cause I am pretty sure I’ve read that some apps are only logging from the gateway but that would make the correlationID that I see everywhere completely useless. On the other hands, I see that error in go should be wrapped for better tracking of the execution path so I’m a bit lost … Any advice is gold to me.

Here is a diagram to illustrate:

and a link to the original diagram for better legibility: logging with microservices - Google Drive

Thank you so much.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.