-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
How to implement a filtering middleware core? #453
Comments
FilteringCore doesn't seem to work. I am discussing the issue at uber-go/zap#453
@tchap This is a great question - I'm going to add it to the FAQ whenever I can free up the time to write decent docs (hopefully soon!). You're right that However, you should still be able to accomplish this. Rather than trying to do the filtering in I suspect that this can actually be quite generic - if you have time, I'd love to see a PR that adds
|
@akshayjshah I can send the PR in the evening or tomorrow, no problem. I would personally swap the arguments, i.e. I would make it zap.NewFilteringCore(next zapcore.Core, filter func(Field) bool) zapcore.Core But I will make it as you wish. |
Also from the naming and signature we have chosen it may seem that the core is just filtering fields and then sending the entry containing the fields not filtered out. I will think about a better naming. |
Perhaps we could add zap.NewEntryFilteringCore(next zapcore.Core, filter func(Field) bool) zapcore.Core
zap.NewFieldFilteringCore(next zapcore.Core, filter func(Field) bool) zapcore.Core The former would drop the whole entry on |
Sure, sounds good. |
@akshayjshah This does not seem to be working, the test is failing: What am I doing wrong? |
Ok, I see where the problem is... |
Actually I don't :-) This doesn't work either. Anyway, I guess that I will open a pull request and we can discuss there... |
Discussed on the PR; after looking more carefully, it's possible to do this reasonably well, but not in a way that can wrap all |
Hi,
I implemented a core that sends log entries to Sentry. But I want to skip entries containing particular fields from being sent to Sentry. For that reason I tried to implement a core that would wrap the Sentry core and simply skip writing the entry when certain field is present.
The thing is, I don't see how the filtering core can be done in a generic way since calling
Check
on the filtering core should obviously callCheck
on the core being wrapped. But that will add the underlying core into the checked entry, causing it to always contain the log entry. In other words, this does not work:https://github.com/tchap/zapext/blob/a5d992351555de581c6d36e2829287a6d1c2f16a/middleware/core_filtering.go
The problem seems to be that fields are not available in
Check
so I cannot run the filter function without really calling the underlying core'sCheck
first.Any ideas how to do this? Am I missing something obvious?
The text was updated successfully, but these errors were encountered: