-
Notifications
You must be signed in to change notification settings - Fork 927
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
Add Logback integration which exports context properties to MDC #305
Conversation
|
@taicki @imasahiro PTAL |
authority = authority.substring(0, m.start()); | ||
} | ||
REQ_AUTHORITY.set(authority); | ||
return; |
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.
Remove this
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.
oops, never mind.
} | ||
} | ||
|
||
String authority; |
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.
Add final
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. Fixed. :-)
*/ | ||
protected abstract Channel channel(); | ||
|
||
@Override |
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.
Do we need to put @Nullable
annotation here?
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.
Fixed.
return ch != null ? (A) ch.remoteAddress() : null; | ||
} | ||
|
||
@Override |
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.
ditto
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.
Fixed
return; | ||
} | ||
|
||
if (mdcKey.startsWith("req.http_headers.")) { |
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.
How about define string constant and use it?
mdcKey.substring(17)
is hard to understand for me.
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 suggestion. Fixed.
|
||
public Map<AttributeKey<?>, String> getAttributes() { | ||
return Collections.unmodifiableMap(attrNames.entrySet().stream().collect( | ||
Collectors.toMap(Entry::getKey, e -> e.getValue().substring(6)))); |
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.
PREFIX_ATTRS.length() I think
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. Missed that one! :-)
import io.netty.util.AsciiString; | ||
import io.netty.util.AttributeKey; | ||
|
||
public class RequestContextExportingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> |
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.
Since this is Unsynchronized, do we need to make this class threadsafe (e.g. ConcurrentHashMap, computeIfAbsent)?
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.
Will make the export list immutable once start()
is called.
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.
Done. Thanks for an advice.
if (enabledBuiltIns.contains(SSL_SESSION_ID)) { | ||
final byte[] id = s.getId(); | ||
if (id != null) { | ||
SSL_SESSION_ID.set(BaseEncoding.base16().lowerCase().encode(id)); |
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.
Can store BaseEncoding.base16().lowerCase() to a static final
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.
Fixed.
Current coverage is 64.35% (diff: 70.48%)@@ master #305 diff @@
==========================================
Files 310 316 +6
Lines 12236 12727 +491
Methods 0 0
Messages 0 0
Branches 1790 1906 +116
==========================================
+ Hits 7830 8190 +360
- Misses 3584 3661 +77
- Partials 822 876 +54
|
private RequestContextExporter exporter; | ||
|
||
private final AppenderAttachableImpl<ILoggingEvent> aai = new AppenderAttachableImpl<>(); | ||
private final Set<BuiltInProperty> builtIns = EnumSet.noneOf(BuiltInProperty.class); |
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.
How about making these part of a RequestContextExporterBuilder which returns RequestContextExporter after calling build()? It's a bit weird having this now-"temporary" state on the appender.
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.
We cannot fix the mutability of appender because XML configuration requires it to be so - it has to call setExport()
on each <export/>
element. Please let me know if there's a way to build an immutable appender using Joran.
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.
I agree the class won't be completely immutable, but at least wrapping these into a separate, Builder type of object, makes it clearer they're only used during setup.
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.
OK. Extracted intermediary data structure to RequestContextExporterBuilder
. Looking better?
Found a bug where the exported MDC properties are not included in the |
Bug fixed at: 3f918fd |
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.
Looks good. A couple of minor comments.
return state; | ||
} | ||
|
||
private static int flag(RequestLog req, ResponseLog res) { |
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.
nit: defining an enum and adding this method would be a bit more readable.
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.
Now using enum :-)
<export>remote.port</export> | ||
<export>tls.cipher</export> | ||
<export>req.http_headers.user-agent</export> | ||
<export>attrs.req_id:com.example.RequestId#ATTR</export> |
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.
Please add an example in the above pattern for attrs' case.
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 the documentation.
f9250fa
to
085b9e7
Compare
- Add RequestContextExportingAppender - Deprecate ServiceRequestContext.logger() and its related configuration properties
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.
LGTM
properties