Behaviors.logMessages implementation#26238
Conversation
|
Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK TO TEST' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged. For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask! |
e22df82 to
a13558b
Compare
I think the original reason for having a config property is to be able to have the That reason is still valid for Typed, but I think it would be more useful to have a way to enable/disable individual I also wonder if we should make it possible to pass in a custom Apart from this the implementation and everything in this PR is looking good. |
|
OK TO TEST |
|
Test PASSed. |
seglo
left a comment
There was a problem hiding this comment.
I implemented a LogOptions to group parameters to Behaviors.logMessages based on your feedback. It now logs signals too.
|
Test PASSed. |
b4653dd to
b348488
Compare
|
Test FAILed. |
|
Test PASSed. |
johanandren
left a comment
There was a problem hiding this comment.
Great work, added a few thoughts.
Would be good if the Java API was at least touched from test code, I think compile only would be fine, in akka.actor.typed.javadsl.ActorLoggingTest
| if (opts.enabled) | ||
| logger.getOrElse(ctx.asScala.log).log(opts.level, "received message {}", msg) | ||
| target(ctx, msg) | ||
| } |
There was a problem hiding this comment.
The untyped one actually invokes receive and looks at the result to be able to say if it was handled/unhandled in the log message, should we perhaps do that here as well? We could actually even log what the new behavior/state is. WDYT?
There was a problem hiding this comment.
I noticed that LoggingReceive uses isDefinedAt to see if a message is handled an encodes that into the message. I wasn't sure how to do that with the Behavior because I don't know how to access the underlying PartialFunction.
We could actually even log what the new behavior/state is.
I'm not sure what you mean by this.
There was a problem hiding this comment.
More of an idea than entirely sure we should do this but,
instead of logging before (or in addition to logging before perhaps) we could do something like this:
val newBehavior = target(ctx, msg)
val handled = if (newBehavior == Behavior.UnhandledBehavior) "unhandled" else "handled"
log.debug("received message {}, was {}")
// or even the full state, perhaps behind a separate config flag
if (opts.logNewState)
log.debug("handled message {}, new behavior {}", msg, newBehavior)
newBehavior
There was a problem hiding this comment.
It could be useful. I can include it if you like.
I have a question regarding the following line
val handled = if (newBehavior == Behavior.UnhandledBehavior) "unhandled" else "handled"
This is checking if the newBehavior is a Behavior.UnhandledBehavior, but in LoggingReceive the logic is checking whether a message is actually handled by a behavior, which can be done using PartialFunction.isDefinedAt. Is there a way to access the underlying PF of the behavior to do a similar check?
There was a problem hiding this comment.
In the typed case we don't know if it is a PF at all, so no, the only way to know that a message was unhandled is to call the behavior and look at the return value. Maybe we could skip that now and look into what would be useful in a follow up PR?
patriknw
left a comment
There was a problem hiding this comment.
looking good, a few nitpicks
seglo
left a comment
There was a problem hiding this comment.
I made a number of updates based on your feedback. I left some comments where I need further clarification. Thanks for your patience reviewing.
|
Test FAILed. |
|
Test FAILed. |
|
I'm having trouble reformatting |
patriknw
left a comment
There was a problem hiding this comment.
LGTM, something very minor...
29041cd to
fb5d798
Compare
|
Test PASSed. |
This PR provides a new Akka Typed
Behaviorthat can be decorated with aReceive[T]to log all messages received. This is similar to usingLoggingReceivein untyped Akka. See #26226 for some more details.I have a few questions:
LoggingReceivehttps://doc.akka.io/docs/akka/current/logging.html#auxiliary-logging-options
Should this implementation check that
akka.actor.debug.receive = onbefore logging? I'm not sure this is actually required when usingLoggingReceivein Akka untyped.This is a relatively minor addition. Does documentation need to be added?What is the most appropriate place in the user docs to mention this feature?