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

pkg/logger/lk: new package for log key glossary #986

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

jmank88
Copy link
Collaborator

@jmank88 jmank88 commented Jan 8, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

Supports:

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

@jmank88
Copy link
Collaborator Author

jmank88 commented Jan 9, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

@jmank88
Copy link
Collaborator Author

jmank88 commented Jan 9, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

We could try to start with some automation, but adding keys manually would be sufficient for most common inconsistencies.

I did consider providing zap field support as well, but I'm not sure how that should work. Even just ChainID is an interesting example. We probably would want to encourage (or even enforce) string based chain IDs, but we don't want to force callers to make a string to pass in, since that is inefficient in cases where the log message does not need to be serialized. We'd rather also accept fmt.Stringer. So zapfield.ChainID("string") isn't flexible enough, we'd want a fmt.Stringer version, and probably int64 too. It wasn't obvious to me how to sort that out in a clean way, so I left it out of scope for now.

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

We could try to start with some automation, but adding keys manually would be sufficient for most common inconsistencies.

I did consider providing zap field support as well, but I'm not sure how that should work. Even just ChainID is an interesting example. We probably would want to encourage (or even enforce) string based chain IDs, but we don't want to force callers to make a string to pass in, since that is inefficient in cases where the log message does not need to be serialized. We'd rather also accept fmt.Stringer. So zapfield.ChainID("string") isn't flexible enough, we'd want a fmt.Stringer version, and probably int64 too. It wasn't obvious to me how to sort that out in a clean way, so I left it out of scope for now.

Sound good. Thanks for explaining!

pavel-raykov
pavel-raykov previously approved these changes Jan 9, 2025
pavel-raykov
pavel-raykov previously approved these changes Jan 15, 2025
const (
ChainID = "chainID" // string
ContractID = "contractID" // string
FeedID = "feedID" // string - hex-encoded 32-byte value, prefixed with "0x", all lowercase
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps lowercase is needlessly strict? I copied this from a type FeedID string.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is fine either way. What exactly do you mean by strict? I.e., in which situation lower case is better/worse than the upper case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mean that it seems superficial to expect/enforce that we use only lowercase. It is trivial to convert to only lowercase at the call site if that is what you need, and it could be a big pain to chase around all the cases and align them as lower case. Perhaps filtering logs is easier with all lowercase? That might be worth it.

@@ -112,12 +113,12 @@ func (a *dataFeedsAggregator) Aggregate(lggr logger.Logger, previousOutcome *typ
previousReportInfo := currentState.FeedInfo[feedIDStr]
feedID, err2 := datastreams.NewFeedID(feedIDStr)
if err2 != nil {
lggr.Errorw("could not convert %s to feedID", "feedID", feedID)
lggr.Errorw("could not convert %s to feedID", logkey.FeedID, feedID)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is logkey the best package name? We might want to use these with Prometheus too, and so we could generalize and shorten to just keys:

Suggested change
lggr.Errorw("could not convert %s to feedID", logkey.FeedID, feedID)
lggr.Errorw("could not convert %s to feedID", keys.FeedID, feedID)

But this would have name collisions in some places.

Something like labels is perhaps less collision prone, but more verbose:

Suggested change
lggr.Errorw("could not convert %s to feedID", logkey.FeedID, feedID)
lggr.Errorw("could not convert %s to feedID", labels.FeedID, feedID)

Any other ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

logconst or logentry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it would need to be fewer than 6 characters to be an improvement on logkey

Copy link
Contributor

Choose a reason for hiding this comment

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

logval or logdef ?

Copy link
Collaborator Author

@jmank88 jmank88 Jan 21, 2025

Choose a reason for hiding this comment

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

Would package lk be too opaque? Typically they should be meaningful, but in this case the usage should always make it clear 🤔 It would also make aliasing packages less obnoxious (chainlk, caplk, etc.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update to package lk to try it out. I think I like it.

krehermann
krehermann previously approved these changes Jan 20, 2025
Copy link
Contributor

@krehermann krehermann left a comment

Choose a reason for hiding this comment

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

discussed offline.

to move forward, agree to keep this simple and audit the growth/ussage of the package with intent to mv/refactor if it becomes too ungainly

@jmank88 jmank88 changed the title pkg/logger/logkey: new package for log key glossary pkg/logger/lk: new package for log key glossary Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants