-
Notifications
You must be signed in to change notification settings - Fork 492
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
otelzap: Skeleton for zap encoder #5566
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5566 +/- ##
=======================================
- Coverage 63.2% 63.0% -0.2%
=======================================
Files 193 194 +1
Lines 11917 11949 +32
=======================================
Hits 7534 7534
- Misses 4166 4198 +32
Partials 217 217
|
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.
From https://pkg.go.dev/go.uber.org/zap#hdr-Extending_Zap:
requires implementing the zapcore.Encoder, zapcore.WriteSyncer, or zapcore.Core interfaces
Can we have proof we need to implement the encoder? AFAIK we just need to implement zapcore.Core
. Zap encoder implementation would be needed only if we would like the users to create the zapcore.Core
using https://pkg.go.dev/go.uber.org/zap/zapcore#NewCore. What are the benefits of supporting such use-case?
EDIT: AFAIK implementing zap encoders makes sense if the destination is io.Writer
-like (basically steams logs to https://pkg.go.dev/go.uber.org/zap/zapcore#WriteSyncer).
PS. I already mentioned it as the first bullet in #5191 (comment)
I did use switch statements at the beginning and this is the problem I ran into - When a user chooses to implement MarshalLogObject/MarshalLogArray - we need an encoder to unmarshal its contents since
The only other way to do this w/o an enoder would be to read from the destination that zap writes to and convert the data to OTel values (cannot vouch if this may be a good solution tho) |
Now, I get it. Thanks for the explanation 🙏 I missed that these use the encoder API. To sum up, this is needed for handling ArrayMarshalerType and ObjectMarshalerType, right? EDIT: I pushed 1d91526 to your other PR. |
yes correct |
You can force the linter to ignore the error by adding a comment looking like |
Part of #5191
Pre-work #5279
Why we might need a custom encoder -
zap code forces you to implement your own object encoder to intercept field types. We cannot use their default console and json encoder - as they write to the provided
io.Writer
in JSON format.MemoryEncoder from zap would have been a suitable solution for our use case - but it is not recommended to be used in production.
A custom encoder will also ensure support for all compatible types