chainlink-common icon indicating copy to clipboard operation
chainlink-common copied to clipboard

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

Open jmank88 opened this issue 11 months ago • 5 comments

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

Supports:

  • https://github.com/smartcontractkit/chainlink/pull/15936

jmank88 avatar Jan 08 '25 19:01 jmank88

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?

pavel-raykov avatar Jan 09 '25 15:01 pavel-raykov

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)

jmank88 avatar Jan 09 '25 15:01 jmank88

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?

pavel-raykov avatar Jan 09 '25 16:01 pavel-raykov

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.

jmank88 avatar Jan 09 '25 16:01 jmank88

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 avatar Jan 09 '25 17:01 pavel-raykov

This PR is stale because it has been open 30 days with no activity. Remove the stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jun 14 '25 00:06 github-actions[bot]

This PR is stale because it has been open 30 days with no activity. Remove the stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 15 '25 00:07 github-actions[bot]

This PR has been automatically closed because it has been stale for > 30 days. If you wish to continue working on this PR, please reopen it and make any necessary changes.

github-actions[bot] avatar Jul 23 '25 00:07 github-actions[bot]