aboutsummaryrefslogtreecommitdiff
path: root/kamon-core
diff options
context:
space:
mode:
authorIvan Topolnak <itopolnak@despegar.com>2014-03-21 17:55:32 -0300
committerIvan Topolnak <itopolnak@despegar.com>2014-03-21 17:55:32 -0300
commitb0c40681d8d6a7f5096fd6d70f37eda23336b0a6 (patch)
treea5f24c03ef1795a3e23c0b1a57b529bd6e46dcf0 /kamon-core
parentc0784898f23472eed0f58e64bf776ea77bb43454 (diff)
downloadKamon-b0c40681d8d6a7f5096fd6d70f37eda23336b0a6.tar.gz
Kamon-b0c40681d8d6a7f5096fd6d70f37eda23336b0a6.tar.bz2
Kamon-b0c40681d8d6a7f5096fd6d70f37eda23336b0a6.zip
avoid using perthis association with ActorCell, fixes #22
Diffstat (limited to 'kamon-core')
-rw-r--r--kamon-core/src/main/resources/META-INF/aop.xml1
-rw-r--r--kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala40
2 files changed, 28 insertions, 13 deletions
diff --git a/kamon-core/src/main/resources/META-INF/aop.xml b/kamon-core/src/main/resources/META-INF/aop.xml
index f5babd54..180d905b 100644
--- a/kamon-core/src/main/resources/META-INF/aop.xml
+++ b/kamon-core/src/main/resources/META-INF/aop.xml
@@ -7,6 +7,7 @@
<aspect name="akka.instrumentation.SystemMessageTraceContextMixin"/>
<aspect name="akka.instrumentation.ActorSystemMessagePassingTracing"/>
<aspect name="akka.instrumentation.EnvelopeTraceContextMixin"/>
+ <aspect name="akka.instrumentation.ActorCellMetricsMixin"/>
<aspect name="akka.instrumentation.BehaviourInvokeTracing"/>
<aspect name="kamon.instrumentation.ActorLoggingTracing"/>
diff --git a/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala b/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala
index c79f980c..60266461 100644
--- a/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala
+++ b/kamon-core/src/main/scala/akka/instrumentation/ActorMessagePassingTracing.scala
@@ -24,20 +24,20 @@ import kamon.metrics.{ ActorMetrics, Metrics }
import kamon.Kamon
import kamon.metrics.ActorMetrics.ActorMetricRecorder
-@Aspect("perthis(actorCellCreation(*, *, *, *, *))")
+@Aspect
class BehaviourInvokeTracing {
- var metricIdentity: ActorMetrics = _
- var actorMetrics: Option[ActorMetricRecorder] = None
- @Pointcut("execution(akka.actor.ActorCell.new(..)) && args(system, ref, props, dispatcher, parent)")
- def actorCellCreation(system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, parent: ActorRef): Unit = {}
+ @Pointcut("execution(akka.actor.ActorCell.new(..)) && this(cell) && args(system, ref, props, dispatcher, parent)")
+ def actorCellCreation(cell: ActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, parent: ActorRef): Unit = {}
- @After("actorCellCreation(system, ref, props, dispatcher, parent)")
- def afterCreation(system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, parent: ActorRef): Unit = {
+ @After("actorCellCreation(cell, system, ref, props, dispatcher, parent)")
+ def afterCreation(cell: ActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, parent: ActorRef): Unit = {
val metricsExtension = Kamon(Metrics)(system)
+ val metricIdentity = ActorMetrics(ref.path.elements.mkString("/"))
+ val cellWithMetrics = cell.asInstanceOf[ActorCellMetrics]
- metricIdentity = ActorMetrics(ref.path.elements.mkString("/"))
- actorMetrics = metricsExtension.register(metricIdentity, ActorMetrics.Factory)
+ cellWithMetrics.metricIdentity = metricIdentity
+ cellWithMetrics.actorMetricsRecorder = metricsExtension.register(metricIdentity, ActorMetrics.Factory)
}
@Pointcut("(execution(* akka.actor.ActorCell.invoke(*)) || execution(* akka.routing.RoutedActorCell.sendMessage(*))) && this(cell) && args(envelope)")
@@ -47,12 +47,13 @@ class BehaviourInvokeTracing {
def aroundBehaviourInvoke(pjp: ProceedingJoinPoint, cell: ActorCell, envelope: Envelope): Any = {
val timestampBeforeProcessing = System.nanoTime()
val contextAndTimestamp = envelope.asInstanceOf[TraceContextAware]
+ val cellWithMetrics = cell.asInstanceOf[ActorCellMetrics]
TraceRecorder.withTraceContext(contextAndTimestamp.traceContext) {
pjp.proceed()
}
- actorMetrics.map { am ⇒
+ cellWithMetrics.actorMetricsRecorder.map { am ⇒
am.processingTime.record(System.nanoTime() - timestampBeforeProcessing)
am.timeInMailbox.record(timestampBeforeProcessing - contextAndTimestamp.captureNanoTime)
am.mailboxSize.record(cell.numberOfMessages)
@@ -60,14 +61,27 @@ class BehaviourInvokeTracing {
}
@Pointcut("execution(* akka.actor.ActorCell.stop()) && this(cell)")
- def actorStop(cell: Cell): Unit = {}
+ def actorStop(cell: ActorCell): Unit = {}
@After("actorStop(cell)")
- def afterStop(cell: Cell): Unit = {
- actorMetrics.map(p ⇒ Kamon(Metrics)(cell.system).unregister(metricIdentity))
+ def afterStop(cell: ActorCell): Unit = {
+ val cellWithMetrics = cell.asInstanceOf[ActorCellMetrics]
+ cellWithMetrics.actorMetricsRecorder.map(p ⇒ Kamon(Metrics)(cell.system).unregister(cellWithMetrics.metricIdentity))
}
}
+trait ActorCellMetrics {
+ var metricIdentity: ActorMetrics = _
+ var actorMetricsRecorder: Option[ActorMetricRecorder] = _
+}
+
+@Aspect
+class ActorCellMetricsMixin {
+
+ @DeclareMixin("akka.actor.ActorCell")
+ def mixinActorCellMetricsToActorCell: ActorCellMetrics = new ActorCellMetrics {}
+}
+
@Aspect
class EnvelopeTraceContextMixin {