From b77454ed16d2d01c2eea340dc0524aba1c962a4d Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Mon, 24 Mar 2014 23:56:07 -0300 Subject: ensure that kamon.trace.ask-pattern-tracing setting is honored, closes #4 --- .../instrumentation/ActorLoggingTracing.scala | 34 ++++++++++++-------- .../main/scala/kamon/trace/TraceExtension.scala | 36 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 kamon-core/src/main/scala/kamon/trace/TraceExtension.scala (limited to 'kamon-core/src/main/scala/kamon') diff --git a/kamon-core/src/main/scala/kamon/instrumentation/ActorLoggingTracing.scala b/kamon-core/src/main/scala/kamon/instrumentation/ActorLoggingTracing.scala index 954f351a..85d39d3e 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/ActorLoggingTracing.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/ActorLoggingTracing.scala @@ -1,21 +1,22 @@ -/* =================================================== +/* + * ========================================================================================= * Copyright © 2013 the kamon project * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================================================== */ + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + * ========================================================================================= + */ + package kamon.instrumentation -import org.aspectj.lang.annotation.{ Around, Pointcut, DeclareMixin, Aspect } +import org.aspectj.lang.annotation._ import org.aspectj.lang.ProceedingJoinPoint import kamon.trace.{ TraceContextAware, TraceRecorder } @@ -25,6 +26,15 @@ class ActorLoggingTracing { @DeclareMixin("akka.event.Logging.LogEvent+") def mixinTraceContextAwareToLogEvent: TraceContextAware = TraceContextAware.default + @Pointcut("execution(akka.event.Logging.LogEvent+.new(..)) && this(event)") + def logEventCreation(event: TraceContextAware): Unit = {} + + @After("logEventCreation(event)") + def captureTraceContext(event: TraceContextAware): Unit = { + // Force initialization of TraceContextAware + event.traceContext + } + @Pointcut("execution(* akka.event.slf4j.Slf4jLogger.withMdc(..)) && args(logSource, logEvent, logStatement)") def withMdcInvocation(logSource: String, logEvent: TraceContextAware, logStatement: () ⇒ _): Unit = {} diff --git a/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala b/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala new file mode 100644 index 00000000..a59abc18 --- /dev/null +++ b/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala @@ -0,0 +1,36 @@ +/* + * ========================================================================================= + * Copyright © 2013 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + * ========================================================================================= + */ + +package kamon.trace + +import akka.actor.{ ExtendedActorSystem, ExtensionIdProvider, ExtensionId } +import akka.actor +import kamon.util.GlobPathFilter +import kamon.Kamon + +class TraceExtension(system: ExtendedActorSystem) extends Kamon.Extension { + val config = system.settings.config.getConfig("kamon.trace") + val enableAskPatternTracing = config.getBoolean("ask-pattern-tracing") +} + +object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { + def lookup(): ExtensionId[_ <: actor.Extension] = Trace + def createExtension(system: ExtendedActorSystem): TraceExtension = new TraceExtension(system) + + case class MetricGroupFilter(includes: List[GlobPathFilter], excludes: List[GlobPathFilter]) { + def accept(name: String): Boolean = includes.exists(_.accept(name)) && !excludes.exists(_.accept(name)) + } +} -- cgit v1.2.3