Logger with context #1437
No reviewers
Labels
No labels
P0
P1
P2
P3
badger
frostfs-adm
frostfs-cli
frostfs-ir
frostfs-lens
frostfs-node
good first issue
triage
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#1437
Loading…
Reference in a new issue
No description provided.
Delete branch "dstepanov-yadro/frostfs-node:feat/log_with_ctx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Now log has traceID:
8bf0a66e14
to692749dba1
@ -0,0 +16,4 @@
}
func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field) {
l.z.Info(msg, append(fields, zap.String("trace_id", tracing.GetTraceID(ctx)))...)
Did you mean
l.z.Warn(...)
?sure, fixed, thanks
16c66065e9
to242033b436
242033b436
tof729d1a8c8
WIP: Logger with contextto Logger with contextHave you seen any other implementations like
https://github.com/uptrace/opentelemetry-go-extra/blob/main/otelzap/otelzap.go
or suggestions in https://github.com/uber-go/zap/issues/654
To me, the approach with a different method name or
log.Ctx(ctx).Info(...)
looks clearer and is less invasive.Having to provide context each time I need to log something would certainly introduce friction.
f729d1a8c8
to8b637b136b
I think that passing the context is not as difficult as it seems at first glance. At the same time, I proceed from the opinion that people are lazy, and if something can be omitted, they do not do it.
In particular, we already have a method for logging traceId, but it was used only where it was originally done, and not everywhere where it is necessary.
Also you can use
context.Background()
if there is no context. Butcontextcheck
linter will help you, if you have forgotten to use context from caller:)8b637b136b
to4b5c2113c5
4b5c2113c5
toca988524ad
ca988524ad
to630d996fe8
New commits pushed, approval review dismissed automatically according to repository settings
630d996fe8
toa4e10975fc
a4e10975fc
toff1e7b531f
@ -365,3 +366,3 @@
}
func (c *testNetmapClient) MorphNotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error {
func (c *testNetmapClient) MorphNotaryInvoke(ctx context.Context, contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error {
Interesting, linter has ignored this unused
ctx
?ff1e7b531f
to6e283295a2
6e283295a2
to612b34d570
Great