-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oh, right. Figured out why ActorMonitorInstrumentation was throwing i…
…n scala 3. Patch it back in.
- Loading branch information
1 parent
83ff191
commit 71b2b74
Showing
4 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...main/scala/kamon/instrumentation/pekko/instrumentations/ActorMonitorInstrumentation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package kamon.instrumentation.pekko.instrumentations | ||
|
||
import org.apache.pekko.actor.WrappedMessage | ||
import org.apache.pekko.dispatch.Envelope | ||
import kamon.instrumentation.pekko.instrumentations.ActorCellInfo | ||
import kanela.agent.api.instrumentation.InstrumentationBuilder | ||
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation.Argument | ||
import org.slf4j.LoggerFactory | ||
|
||
import scala.annotation.static | ||
import scala.util.control.NonFatal | ||
|
||
class ActorMonitorInstrumentation extends InstrumentationBuilder { | ||
/* | ||
* Changes implementation of extractMessageClass for our ActorMonitor. | ||
* In Pekko, all typed messages are converted to AdaptMessage, | ||
* so we're forced to extract the original message type. | ||
*/ | ||
onSubTypesOf("kamon.instrumentation.pekko.instrumentations.ActorMonitor") | ||
.intercept(method("extractMessageClass"), classOf[MessageClassAdvice]) | ||
} | ||
|
||
class MessageClassAdvice | ||
object MessageClassAdvice { | ||
private val logger = LoggerFactory.getLogger(classOf[MessageClassAdvice]) | ||
|
||
@static def extractMessageClass(@Argument(0) envelope: Any): String = { | ||
val e = envelope.asInstanceOf[Envelope] | ||
try { | ||
e.message match { | ||
case message: WrappedMessage => ActorCellInfo.simpleClassName(message.message.getClass) | ||
case _ => ActorCellInfo.simpleClassName(e.message.getClass) | ||
} | ||
} catch { | ||
// NoClassDefFound is thrown in early versions of akka 2.6 | ||
// so we can safely fallback to the original method | ||
case _: NoClassDefFoundError | _: ClassCastException | _: NullPointerException => | ||
ActorCellInfo.simpleClassName(e.message.getClass) | ||
case NonFatal(ex) => | ||
logger.info(s"Expected NoClassDefFoundError, got: ${ex}") | ||
ActorCellInfo.simpleClassName(e.message.getClass) | ||
} | ||
} | ||
} |