-
Notifications
You must be signed in to change notification settings - Fork 46
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
RSDK-9150 - Client log interceptor should not use zap.Logger #375
Conversation
rpc/wrtc_client_channel.go
Outdated
switch level { | ||
case zap.DebugLevel: | ||
logger.Debugw(msg, fields...) | ||
case zap.InfoLevel: | ||
logger.Infow(msg, fields...) | ||
case zap.ErrorLevel: | ||
logger.Errorw(msg, fields...) | ||
case zap.WarnLevel: | ||
fallthrough | ||
default: | ||
logger.Warnw(msg, fields...) | ||
} |
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.
this is pretty ugly, but the Write()
methods differ between zap loggers and rdk loggers so I could either write another conversion method like AddFieldsToLogger
or do this and this is easier
zap.String("grpc.service", service), | ||
zap.String("grpc.method", method), | ||
return []any{ | ||
"span.kind", "client", |
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.
note: rdk loggers' WithFields() do not play nicely with zapcore.Field at all. which probably means that zap loggers will not play nicely with AddFieldsToLogger
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.
Thanks for filing that ticket; sounds like zap loggers will almost certainly not play nicely with AddFieldsToLogger
. But, from the sample "after changes" output you put in the PR description, the added fields do seem to be getting added. Is that right?
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.
yep, but the way they're getting passed in now is different - no longer a list of zap.Fields
rpc/wrtc_client_channel.go
Outdated
} | ||
fields = append(fields, "grpc.code", code.String(), "grpc.time_ms", duration) | ||
|
||
if logger.Level().Enabled(level) { |
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.
Why is this necessary? I would expect if the level were not enabled, then the calls to logger.Debuw
/logger.Infow
/etc... would early return. Are we not observing that?
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.
ya this is probably unnecessary, let me check. I was thinking too much about replicating the functionality of grpc_zap.DefaultMessageProducer, which also does a check before logging
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.
Cool, definitely speak up if removing this is problematic.
If removing is not problematic, then we can cascade and delete the interface change that added Level
and the dummy implementations for the testing cases.
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.
updated to remove
zap.String("grpc.service", service), | ||
zap.String("grpc.method", method), | ||
return []any{ | ||
"span.kind", "client", |
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.
Thanks for filing that ticket; sounds like zap loggers will almost certainly not play nicely with AddFieldsToLogger
. But, from the sample "after changes" output you put in the PR description, the added fields do seem to be getting added. Is that right?
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.
Thanks!
no reason to convert the logger to a zap logger and then stick it in the context
before changes:
after changes:
field order is different, since zap loggers put the With() fields in front whereas the RDK logger puts them in the back