WebSocket: API to use initiating request MDC
andrus opened this issue · comments
Andrus Adamchik commented
Per #104 we have a new Slf4J MDC management API in Jetty. Let's extend it to websockets, so that each socket session would inherit MDC from the initiating web request. Since websocket operations happen in different threads, we have to establish and clean up the context on every method call of a ws endpoint. Don't see an easy way to intercept that automatically, so going to provide an injectable instance of WebSocketMDCManager
that will have to be manually applied as this:
@Inject
WebSocketMDCManager mdc;
@OnMessage
public void onMessage(String m, Session s) {
mdc.run(s, () -> { /* do something */});
}
MDC data will be captured in the Session "userProperties" map.