-
Notifications
You must be signed in to change notification settings - Fork 20
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: Add contextual logger #527
Conversation
Returns a zerolog instance configured with the service name. We can add more contextual information going forward.
pkg/solver/controller.go
Outdated
@@ -413,7 +421,7 @@ func (controller *SolverController) addJobOffer(jobOffer data.JobOffer) (*data.J | |||
} | |||
jobOffer.ID = id | |||
|
|||
controller.log.Info("add job offer", jobOffer) | |||
controller.log.Info().Any("jobOffer", jobOffer).Msg("add job offer") |
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 also add the jobOfferId as a key-value so it'll be a little easier to spot in the logs
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.
Yeah! Great idea. Added in 157cc4c
pkg/solver/controller.go
Outdated
return nil, nil | ||
} | ||
|
||
controller.log.Info("add resource offer", resourceOffer) | ||
controller.log.Info().Any("resourceOffer", resourceOffer).Msg("add resource offer") |
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 also add the resourceOfferId and resourceProviderId as a key-value so it'll be a little easier to spot in the logs
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.
✅ Done: 157cc4c
pkg/solver/controller.go
Outdated
@@ -520,7 +535,7 @@ func (controller *SolverController) addDeal(ctx context.Context, deal data.Deal) | |||
span.SetAttributes(attribute.String("deal.id", deal.ID)) | |||
span.AddEvent("data.get_deal_id.done") | |||
|
|||
controller.log.Info("add deal", deal) | |||
controller.log.Info().Any("deal", deal).Msg("add deal") |
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 also add the dealId and the resourceProviderId of the RP whose going to do the job as key-value pairs here
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.
Also done in 157cc4c. Did the job creator ID as well.
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.
LGTM! Just left some comments on additions to some of the log statements
Summary
This pull request makes the following changes:
GetLogger
helper to get a logger with service contextSetupLogging
toSetupGlobalLogger
(to clarify its purpose)This pull request moves us towards a uniform logging system built around the
zerolog
interface.We have also made a small naming change:
solverServer
instances toserver
(we know we're in the solver)Task/Issue reference
Implements: #303
Test plan
Start the stack. Run a job. Make sure it all works.
Also may be of interest to run a job and compare the logs on
main
with the logs in this pull request.Details
Our system currently uses a global
zerolog
implementation in some places and a service logger in others. We would like to move to individualizedzerolog
loggers for each package or component that can be configured with additional context. This pull request starts with loggers configured with theservice
they log from.This pull request also updates the solver logs to replace global logger and service logger calls with the new contextualized logs. We have updated many of the existing logs with additional key-pairs which in some cases were not possible using the service logger. The additional key-pair fields support our upcoming OpenTelemetry work.
Related issues or PRs
Epic: https://github.com/Lilypad-Tech/internal/issues/345