Skip to content
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

sourceThread MDC value not set by typed actors #28153

Open
johanandren opened this issue Nov 8, 2019 · 10 comments
Open

sourceThread MDC value not set by typed actors #28153

johanandren opened this issue Nov 8, 2019 · 10 comments
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:typed

Comments

@johanandren
Copy link
Member

Mentioned by the docs but we don't seem to set it?

@johanandren johanandren added t:typed 0 - new Ticket is unclear on it's purpose or if it is valid or not labels Nov 8, 2019
@johanandren
Copy link
Member Author

Or it's built in now with Slf4J, so it should be %thread in the docs?

@patriknw
Copy link
Member

patriknw commented Nov 8, 2019

I think %thread is the thread that makes the org.slf4j.Logger.info call. For classic that is not useful so there we add sourceThread in SlfjLogger:

MDC.put(mdcThreadAttributeName, logEvent.thread.getName)

PS. I was wrong about that all Akka mdc keys are prefixed with akka.

@johanandren
Copy link
Member Author

So the typed docs should say %thread but then if you have a mixed system with typed and classic what do you do to not get confusing logs?

@patriknw
Copy link
Member

patriknw commented Nov 8, 2019

When using Typed it's always a mix, since our internal logging is going over the eventBus. I guess we could add sourceThread from the ActorContext logging so that field is always set, apart from when slf4j is used directly outside of ActorContext

@patriknw
Copy link
Member

Similar with akkaTimestamp

@aumann
Copy link
Contributor

aumann commented Nov 20, 2019

The missing akkaTimestamp is really unfortunate. Is there a workaround/logback configuration to get consistent log entries for a mixed system without losing precise timestamps for classic actors? With the current 'recommended' configuration all log entries from typed actors are without time stamp since upgrading to 2.6

@johanandren
Copy link
Member Author

I'm not clear on how to configure the logger to handle the diff but the timestamp and source thread is already in the log events (and is correct) for typed.

Is it possible to fallback from one expression to another if the first yields empty string? Could we provide some adapter that adds the mdc keys from the logger events or the other way around?

@aumann
Copy link
Contributor

aumann commented Nov 21, 2019

I found a somewhat ugly method to workaround the issue (with logback PatternLayout)

Unfortunately, the simple (defaultValue based) solution does not work:

%X{akkaTimestamp:-%date{HH:mm:ss.SSS,UTC}UTC}

The problem with this approach is that the %date pattern is not evaluated this way.

The only approach I got working was a nested regex-replace:
%replace(%replace(%X{akkaTimestamp}xxx%date{HH:mm:ss.SSS,UTC}UTC){'(.+)xxx(.*)','$1'}){'xxx(.*)', '$1'}

This way the akkaTimestamp is preferred if present, and otherwise the fallback %date based pattern is used.

Unfortunately, this is not very readable anymore.

@johanandren
Copy link
Member Author

Could we provide some intermediate event transformation component for logbook that uses the event values to add them as the old mdc attributes before the actual layout is applied?

@johanandren johanandren self-assigned this Dec 6, 2019
@johanandren johanandren added 3 - in progress Someone is working on this ticket and removed 0 - new Ticket is unclear on it's purpose or if it is valid or not labels Dec 6, 2019
@patriknw
Copy link
Member

We decided to add the sourceThread to the MDC for Typed also, and ignore the akkaTimestamp.

@johanandren johanandren removed their assignment Dec 17, 2019
@johanandren johanandren added 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted and removed 3 - in progress Someone is working on this ticket labels Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:typed
Projects
None yet
Development

No branches or pull requests

3 participants