Skip to content

Commit

Permalink
Merge pull request #29 from ivantopo/move-appender-instrumentation-to…
Browse files Browse the repository at this point in the history
…-advice

move appender loop instrumentation from interceptor to advice, fixes #28
  • Loading branch information
ivantopo committed Sep 29, 2019
2 parents a26cf66 + 70b210e commit e530248
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ script:
scala:
- 2.12.4
jdk:
- oraclejdk8
- openjdk8
before_script:
- mkdir $TRAVIS_BUILD_DIR/tmp
- export SBT_OPTS="-Djava.io.tmpdir=$TRAVIS_BUILD_DIR/tmp"
sudo: false
sudo: false
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import java.util.concurrent.Callable
import com.typesafe.config.Config
import kamon.Kamon
import kamon.context.Context
import kamon.context.Context.Key
import kamon.context.Storage.Scope
import kamon.instrumentation.context.HasContext
import kamon.tag.Tag
import kamon.trace.{Identifier, Span}
import kanela.agent.api.instrumentation.InstrumentationBuilder
import kanela.agent.libs.net.bytebuddy.asm.Advice
import kanela.agent.libs.net.bytebuddy.asm.Advice.Argument
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation.{RuntimeType, SuperCall}
import org.slf4j.MDC

Expand All @@ -41,7 +39,7 @@ class LogbackInstrumentation extends InstrumentationBuilder {
.mixin(classOf[HasContext.MixinWithInitializer])

onType("ch.qos.logback.core.spi.AppenderAttachableImpl")
.intercept(method("appendLoopOnAppenders"), AppendLoopMethodInterceptor)
.advise(method("appendLoopOnAppenders"), AppendLoopOnAppendersAdvice)

onType("ch.qos.logback.classic.util.LogbackMDCAdapter")
.intercept(method("getPropertyMap"), GetPropertyMapMethodInterceptor)
Expand Down Expand Up @@ -76,11 +74,15 @@ object LogbackInstrumentation {
}
}

object AppendLoopMethodInterceptor {
object AppendLoopOnAppendersAdvice {

@RuntimeType
def aroundAppendLoop(@SuperCall callable: Callable[Int], @annotation.Argument(0) event:AnyRef): Int =
Kamon.runWithContext(event.asInstanceOf[HasContext].context)(callable.call())
@Advice.OnMethodEnter
def enter(@Advice.Argument(0) event: Any): Scope =
Kamon.storeContext(event.asInstanceOf[HasContext].context)

@Advice.OnMethodExit
def exit(@Advice.Enter scope: Scope): Unit =
scope.close()
}

object GetPropertyMapMethodInterceptor {
Expand Down

0 comments on commit e530248

Please sign in to comment.