diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-15 11:16:21 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-15 11:16:21 +0100 |
commit | cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb (patch) | |
tree | 0f07e794e6fb88e180913a10f57ffaa4e2fa03cc /kamon-akka/src | |
parent | 8a532fc8c95a5700721248b6b4f558d9a1dcebcb (diff) | |
download | Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.tar.gz Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.tar.bz2 Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.zip |
! core: move the TraceContext manipulation API to the Tracer companion object.
Diffstat (limited to 'kamon-akka/src')
8 files changed, 59 insertions, 60 deletions
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala index 7c722569..4783484f 100644 --- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala @@ -53,7 +53,7 @@ class ActorCellInstrumentation { val contextAndTimestamp = envelope.asInstanceOf[TimestampedTraceContextAware] try { - TraceContext.withContext(contextAndTimestamp.traceContext) { + Tracer.withContext(contextAndTimestamp.traceContext) { pjp.proceed() } } finally { @@ -142,7 +142,7 @@ class RoutedActorCellInstrumentation { val contextAndTimestamp = envelope.asInstanceOf[TimestampedTraceContextAware] try { - TraceContext.withContext(contextAndTimestamp.traceContext) { + Tracer.withContext(contextAndTimestamp.traceContext) { // The router metrics recorder will only be picked up if the message is sent from a tracked router. RouterAwareEnvelope.dynamicRouterMetricsRecorder.withValue(cellMetrics.routerRecorder) { diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorLoggingInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorLoggingInstrumentation.scala index dd998c6b..f17c4976 100644 --- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorLoggingInstrumentation.scala +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorLoggingInstrumentation.scala @@ -17,7 +17,7 @@ package akka.kamon.instrumentation import kamon.trace.logging.MdcKeysSupport -import kamon.trace.{ TraceContext, TraceContextAware } +import kamon.trace.{ Tracer, TraceContextAware } import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ @@ -41,7 +41,7 @@ class ActorLoggingInstrumentation extends MdcKeysSupport { @Around("withMdcInvocation(logSource, logEvent, logStatement)") def aroundWithMdcInvocation(pjp: ProceedingJoinPoint, logSource: String, logEvent: TraceContextAware, logStatement: () ⇒ _): Unit = { - TraceContext.withContext(logEvent.traceContext) { + Tracer.withContext(logEvent.traceContext) { withMdc { pjp.proceed() } diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentation.scala index 0cb4ef13..c123ee04 100644 --- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentation.scala +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentation.scala @@ -17,7 +17,7 @@ package akka.kamon.instrumentation import akka.dispatch.sysmsg.EarliestFirstSystemMessageList -import kamon.trace.{ TraceContext, TraceContextAware } +import kamon.trace.{ Tracer, TraceContextAware } import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ @@ -31,7 +31,7 @@ class ActorSystemMessageInstrumentation { def aroundSystemMessageInvoke(pjp: ProceedingJoinPoint, messages: EarliestFirstSystemMessageList): Any = { if (messages.nonEmpty) { val ctx = messages.head.asInstanceOf[TraceContextAware].traceContext - TraceContext.withContext(ctx)(pjp.proceed()) + Tracer.withContext(ctx)(pjp.proceed()) } else pjp.proceed() } @@ -73,7 +73,7 @@ class TraceContextIntoRepointableActorRefMixin { @Around("repointableActorRefCreation(repointableActorRef)") def afterRepointableActorRefCreation(pjp: ProceedingJoinPoint, repointableActorRef: TraceContextAware): Any = { - TraceContext.withContext(repointableActorRef.traceContext) { + Tracer.withContext(repointableActorRef.traceContext) { pjp.proceed() } } diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala index e1dcdf32..42edf4db 100644 --- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala +++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala @@ -19,16 +19,15 @@ package akka.kamon.instrumentation import akka.util.Timeout import kamon.Kamon import kamon.akka.Akka -import kamon.trace.{ TraceContext, EmptyTraceContext, TraceContextAware } +import kamon.trace.Tracer import akka.actor.{ InternalActorRef, ActorSystem, ActorRef } import akka.event.Logging.Warning -import akka.pattern.{ PromiseActorRef, AskTimeoutException } +import akka.pattern.AskTimeoutException import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ import org.aspectj.lang.reflect.SourceLocation import scala.concurrent.Future import scala.compat.Platform.EOL -import scala.concurrent.duration.FiniteDuration @Aspect class AskPatternInstrumentation { @@ -40,7 +39,7 @@ class AskPatternInstrumentation { @Around("askableActorRefAsk(actor, timeout)") def hookAskTimeoutWarning(pjp: ProceedingJoinPoint, actor: ActorRef, timeout: Timeout): AnyRef = - TraceContext.map { ctx ⇒ + Tracer.currentContext.collect { ctx ⇒ actor match { // the AskPattern will only work for InternalActorRef's with these conditions. case ref: InternalActorRef if !ref.isTerminated && timeout.duration.length > 0 ⇒ diff --git a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorCellInstrumentationSpec.scala b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorCellInstrumentationSpec.scala index 8f7ae613..457b8351 100644 --- a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorCellInstrumentationSpec.scala +++ b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorCellInstrumentationSpec.scala @@ -20,7 +20,7 @@ import akka.pattern.{ ask, pipe } import akka.routing._ import akka.util.Timeout import kamon.testkit.BaseKamonSpec -import kamon.trace.TraceContext +import kamon.trace.Tracer import scala.concurrent.duration._ @@ -29,18 +29,18 @@ class ActorCellInstrumentationSpec extends BaseKamonSpec("actor-cell-instrumenta "the message passing instrumentation" should { "propagate the TraceContext using bang" in new EchoActorFixture { - val testTraceContext = TraceContext.withContext(newContext("bang-reply")) { + val testTraceContext = Tracer.withContext(newContext("bang-reply")) { ctxEchoActor ! "test" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) } "propagate the TraceContext using tell" in new EchoActorFixture { - val testTraceContext = TraceContext.withContext(newContext("tell-reply")) { + val testTraceContext = Tracer.withContext(newContext("tell-reply")) { ctxEchoActor.tell("test", testActor) - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) @@ -48,37 +48,37 @@ class ActorCellInstrumentationSpec extends BaseKamonSpec("actor-cell-instrumenta "propagate the TraceContext using ask" in new EchoActorFixture { implicit val timeout = Timeout(1 seconds) - val testTraceContext = TraceContext.withContext(newContext("ask-reply")) { + val testTraceContext = Tracer.withContext(newContext("ask-reply")) { // The pipe pattern use Futures internally, so FutureTracing test should cover the underpinnings of it. (ctxEchoActor ? "test") pipeTo (testActor) - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) } "propagate the TraceContext to actors behind a simple router" in new EchoSimpleRouterFixture { - val testTraceContext = TraceContext.withContext(newContext("router-reply")) { + val testTraceContext = Tracer.withContext(newContext("router-reply")) { router.route("test", testActor) - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) } "propagate the TraceContext to actors behind a pool router" in new EchoPoolRouterFixture { - val testTraceContext = TraceContext.withContext(newContext("router-reply")) { + val testTraceContext = Tracer.withContext(newContext("router-reply")) { pool ! "test" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) } "propagate the TraceContext to actors behind a group router" in new EchoGroupRouterFixture { - val testTraceContext = TraceContext.withContext(newContext("router-reply")) { + val testTraceContext = Tracer.withContext(newContext("router-reply")) { group ! "test" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) @@ -116,7 +116,7 @@ class ActorCellInstrumentationSpec extends BaseKamonSpec("actor-cell-instrumenta class TraceContextEcho extends Actor { def receive = { - case msg: String ⇒ sender ! TraceContext.currentContext + case msg: String ⇒ sender ! Tracer.currentContext } } diff --git a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorLoggingInstrumentationSpec.scala b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorLoggingInstrumentationSpec.scala index 21706af9..42a26cdd 100644 --- a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorLoggingInstrumentationSpec.scala +++ b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorLoggingInstrumentationSpec.scala @@ -21,7 +21,7 @@ import com.typesafe.config.ConfigFactory import kamon.testkit.BaseKamonSpec import kamon.trace.TraceLocal.AvailableToMdc import kamon.trace.logging.MdcKeysSupport -import kamon.trace.{ TraceContextAware, TraceLocal, TraceContext } +import kamon.trace.{Tracer, TraceContextAware, TraceLocal} import org.scalatest.Inspectors import org.slf4j.MDC @@ -39,9 +39,9 @@ class ActorLoggingInstrumentationSpec extends BaseKamonSpec("actor-logging-instr val loggerActor = system.actorOf(Props[LoggerActor]) system.eventStream.subscribe(testActor, classOf[LogEvent]) - val testTraceContext = TraceContext.withContext(newContext("logging")) { + val testTraceContext = Tracer.withContext(newContext("logging")) { loggerActor ! "info" - TraceContext.currentContext + Tracer.currentContext } fishForMessage() { @@ -55,7 +55,7 @@ class ActorLoggingInstrumentationSpec extends BaseKamonSpec("actor-logging-instr "allow retrieve a value from the MDC when was created a key of type AvailableToMdc" in { val testString = "Hello World" - TraceContext.withContext(newContext("logging-with-mdc")) { + Tracer.withContext(newContext("logging-with-mdc")) { TraceLocal.store(AvailableToMdc("some-cool-key"))(testString) withMdc { @@ -71,6 +71,6 @@ class ActorLoggingInstrumentationSpec extends BaseKamonSpec("actor-logging-instr class LoggerActor extends Actor with ActorLogging { def receive = { - case "info" ⇒ log.info("TraceContext(name = {}, token = {})", TraceContext.currentContext.name, TraceContext.currentContext.token) + case "info" ⇒ log.info("TraceContext(name = {}, token = {})", Tracer.currentContext.name, Tracer.currentContext.token) } } diff --git a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentationSpec.scala b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentationSpec.scala index 808473cd..fd9f58d0 100644 --- a/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentationSpec.scala +++ b/kamon-akka/src/test/scala/kamon/akka/instrumentation/ActorSystemMessageInstrumentationSpec.scala @@ -21,7 +21,7 @@ import akka.actor._ import akka.testkit.ImplicitSender import com.typesafe.config.ConfigFactory import kamon.testkit.BaseKamonSpec -import kamon.trace.{ EmptyTraceContext, TraceContext } +import kamon.trace.{Tracer, EmptyTraceContext} import org.scalatest.WordSpecLike import scala.concurrent.duration._ @@ -40,31 +40,31 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- "the system message passing instrumentation" should { "keep the TraceContext while processing the Create message in top level actors" in { - val testTraceContext = TraceContext.withContext(newContext("creating-top-level-actor")) { + val testTraceContext = Tracer.withContext(newContext("creating-top-level-actor")) { system.actorOf(Props(new Actor { - testActor ! TraceContext.currentContext + testActor ! Tracer.currentContext def receive: Actor.Receive = { case any ⇒ } })) - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) } "keep the TraceContext while processing the Create message in non top level actors" in { - val testTraceContext = TraceContext.withContext(newContext("creating-non-top-level-actor")) { + val testTraceContext = Tracer.withContext(newContext("creating-non-top-level-actor")) { system.actorOf(Props(new Actor { def receive: Actor.Receive = { case any ⇒ context.actorOf(Props(new Actor { - testActor ! TraceContext.currentContext + testActor ! Tracer.currentContext def receive: Actor.Receive = { case any ⇒ } })) } })) ! "any" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) @@ -74,9 +74,9 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- "the actor is resumed" in { val supervisor = supervisorWithDirective(Resume) - val testTraceContext = TraceContext.withContext(newContext("fail-and-resume")) { + val testTraceContext = Tracer.withContext(newContext("fail-and-resume")) { supervisor ! "fail" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) // From the parent executing the supervision strategy @@ -89,9 +89,9 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- "the actor is restarted" in { val supervisor = supervisorWithDirective(Restart, sendPreRestart = true, sendPostRestart = true) - val testTraceContext = TraceContext.withContext(newContext("fail-and-restart")) { + val testTraceContext = Tracer.withContext(newContext("fail-and-restart")) { supervisor ! "fail" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) // From the parent executing the supervision strategy @@ -106,9 +106,9 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- "the actor is stopped" in { val supervisor = supervisorWithDirective(Stop, sendPostStop = true) - val testTraceContext = TraceContext.withContext(newContext("fail-and-stop")) { + val testTraceContext = Tracer.withContext(newContext("fail-and-stop")) { supervisor ! "fail" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) // From the parent executing the supervision strategy @@ -119,9 +119,9 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- "the failure is escalated" in { val supervisor = supervisorWithDirective(Escalate, sendPostStop = true) - val testTraceContext = TraceContext.withContext(newContext("fail-and-escalate")) { + val testTraceContext = Tracer.withContext(newContext("fail-and-escalate")) { supervisor ! "fail" - TraceContext.currentContext + Tracer.currentContext } expectMsg(testTraceContext) // From the parent executing the supervision strategy @@ -139,7 +139,7 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- val child = context.actorOf(Props(new Parent)) override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() { - case NonFatal(throwable) ⇒ testActor ! TraceContext.currentContext; Stop + case NonFatal(throwable) ⇒ testActor ! Tracer.currentContext; Stop } def receive = { @@ -151,7 +151,7 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- val child = context.actorOf(Props(new Child)) override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() { - case NonFatal(throwable) ⇒ testActor ! TraceContext.currentContext; directive + case NonFatal(throwable) ⇒ testActor ! Tracer.currentContext; directive } def receive: Actor.Receive = { @@ -159,7 +159,7 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- } override def postStop(): Unit = { - if (sendPostStop) testActor ! TraceContext.currentContext + if (sendPostStop) testActor ! Tracer.currentContext super.postStop() } } @@ -167,26 +167,26 @@ class ActorSystemMessageInstrumentationSpec extends BaseKamonSpec("actor-system- class Child extends Actor { def receive = { case "fail" ⇒ throw new ArithmeticException("Division by zero.") - case "context" ⇒ sender ! TraceContext.currentContext + case "context" ⇒ sender ! Tracer.currentContext } override def preRestart(reason: Throwable, message: Option[Any]): Unit = { - if (sendPreRestart) testActor ! TraceContext.currentContext + if (sendPreRestart) testActor ! Tracer.currentContext super.preRestart(reason, message) } override def postRestart(reason: Throwable): Unit = { - if (sendPostRestart) testActor ! TraceContext.currentContext + if (sendPostRestart) testActor ! Tracer.currentContext super.postRestart(reason) } override def postStop(): Unit = { - if (sendPostStop) testActor ! TraceContext.currentContext + if (sendPostStop) testActor ! Tracer.currentContext super.postStop() } override def preStart(): Unit = { - if (sendPreStart) testActor ! TraceContext.currentContext + if (sendPreStart) testActor ! Tracer.currentContext super.preStart() } } diff --git a/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala b/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala index 44b90642..a44945ea 100644 --- a/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala +++ b/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala @@ -27,7 +27,7 @@ import com.typesafe.config.ConfigFactory import kamon.Kamon import kamon.akka.Akka import kamon.testkit.BaseKamonSpec -import kamon.trace.{ TraceContext, TraceContextAware } +import kamon.trace.{Tracer, TraceContext, TraceContextAware} import scala.concurrent.duration._ @@ -51,9 +51,9 @@ class AskPatternInstrumentationSpec extends BaseKamonSpec("ask-pattern-tracing-s setAskPatternTimeoutWarningMode("heavyweight") expectTimeoutWarning() { - TraceContext.withContext(newContext("ask-timeout-warning")) { + Tracer.withContext(newContext("ask-timeout-warning")) { noReplyActorRef ? "hello" - TraceContext.currentContext + Tracer.currentContext } } } @@ -64,9 +64,9 @@ class AskPatternInstrumentationSpec extends BaseKamonSpec("ask-pattern-tracing-s setAskPatternTimeoutWarningMode("lightweight") expectTimeoutWarning(messageSizeLimit = Some(1)) { - TraceContext.withContext(newContext("ask-timeout-warning")) { + Tracer.withContext(newContext("ask-timeout-warning")) { noReplyActorRef ? "hello" - TraceContext.currentContext + Tracer.currentContext } } } @@ -77,9 +77,9 @@ class AskPatternInstrumentationSpec extends BaseKamonSpec("ask-pattern-tracing-s setAskPatternTimeoutWarningMode("off") expectTimeoutWarning(expectWarning = false) { - TraceContext.withContext(newContext("ask-timeout-warning")) { + Tracer.withContext(newContext("ask-timeout-warning")) { noReplyActorRef ? "hello" - TraceContext.currentContext + Tracer.currentContext } } } |