Skip to content
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: fields for labels and non-sugared structured logging #202

Merged
merged 2 commits into from
Nov 17, 2023
Merged

Conversation

fracasula
Copy link
Collaborator

@fracasula fracasula commented Nov 10, 2023

Description

There has been some work in the rudder-observability-kit to expose some common labels that we can use across our projects to make sure that we are consistent with them while using structured logging.

You can find such labels here.

In this PullRequest I'm doing mostly two things:

  1. introduce the support for a faster non-sugared structured logging via zap
  2. adding a new logger.Field to be used with the non-sugared structured logging
    • such fields can be used in sugared logging too e.g. log.Infow("foo", field.Name(), field.Value()), also see Expand function in this PR
    • such fields are used in the rudder-observability-kit when we generate labels from the labels.yaml file, see the go/labels/common.go (this is done in this PR)

Linear Ticket

< Linear_Link >

Related PRs

For a showcase about how this can be used check the Pull Requests below:

TODOs

  • increase test coverage

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@fracasula fracasula changed the title Pipe 510 feat: non-sugared structured logging Nov 10, 2023
@fracasula fracasula changed the title feat: non-sugared structured logging feat: fields for labels and non-sugared structured logging Nov 10, 2023
Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Comparison is base (511b8a8) 79.31% compared to head (c29f943) 79.50%.

Files Patch % Lines
logger/nop.go 16.00% 21 Missing ⚠️
logger/factory.go 60.00% 5 Missing and 1 partial ⚠️
logger/logger.go 93.75% 4 Missing and 1 partial ⚠️
logger/field.go 98.46% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #202      +/-   ##
==========================================
+ Coverage   79.31%   79.50%   +0.18%     
==========================================
  Files          70       71       +1     
  Lines        5222     5342     +120     
==========================================
+ Hits         4142     4247     +105     
- Misses        876      890      +14     
- Partials      204      205       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@atzoum atzoum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for delaying my review, forgot to publish my comments 😅

error error
}

func (f Field) Name() string { return f.name }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to add some coverage for this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Test_Logger_NonSugared provide enough coverage? What other scenarios do you have in mind? What if I just add more logs there with all the types like time, duration, error, etc?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following seem to be uncovered right now:

  • Field#Name
  • Field#Value
  • Field#toZap (partial)
  • NewField
  • New{Float|Time|Duration|Error}Field
  • Expand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I got used to have the CodeCov report in the Files changed tab here in the Pull Request and somehow it isn't showing here. We do have the report above though 👍

logger/factory.go Outdated Show resolved Hide resolved
@fracasula fracasula merged commit 205700e into main Nov 17, 2023
10 checks passed
@fracasula fracasula deleted the pipe-510 branch November 17, 2023 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants