-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1052 from SimunKaracic/rediscala-initial
Rediscala initial
- Loading branch information
Showing
5 changed files
with
190 additions
and
66 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
15 changes: 14 additions & 1 deletion
15
instrumentation/kamon-redis/src/main/resources/reference.conf
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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
kanela.modules { | ||
redis { | ||
name = "Redis Instrumentation" | ||
description = "Provides tracing for Jedis and Lettuce libraries" | ||
description = "Provides tracing for Jedis, Lettuce and Rediscala libraries" | ||
|
||
instrumentations = [ | ||
"kamon.instrumentation.jedis.JedisInstrumentation", | ||
"kamon.instrumentation.lettuce.LettuceInstrumentation", | ||
"kamon.instrumentation.rediscala.RediscalaInstrumentation", | ||
] | ||
|
||
within = [ | ||
"redis.clients.jedis.Protocol", | ||
"io.lettuce.core..*", | ||
"redis..*", | ||
] | ||
} | ||
} | ||
|
||
|
||
# when using multiple clients, the extension will be alphabetical | ||
# e.g. $a, $b, $c. | ||
# so add exclude clauses as needed | ||
kamon.instrumentation.akka.filters.actors.trace { | ||
excludes += "*/user/RedisClient-$a/**" | ||
excludes += "*/user/RedisClient-$a" | ||
excludes += "*/user/RedisBlockingClient-$a/**" | ||
excludes += "*/user/RedisBlockingClient-$a" | ||
} |
111 changes: 111 additions & 0 deletions
111
...kamon-redis/src/main/scala/kamon/instrumentation/rediscala/RediscalaInstrumentation.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,111 @@ | ||
package kamon.instrumentation.rediscala | ||
|
||
import kamon.Kamon | ||
import kamon.trace.Span | ||
import kamon.util.CallingThreadExecutionContext | ||
import kanela.agent.api.instrumentation.InstrumentationBuilder | ||
import kanela.agent.libs.net.bytebuddy.asm.Advice | ||
|
||
import scala.concurrent.Future | ||
import scala.util.{Failure, Success} | ||
|
||
class RediscalaInstrumentation extends InstrumentationBuilder { | ||
onTypes("redis.Request", "redis.ActorRequest", "redis.BufferedRequest", | ||
"redis.commands.BLists", "redis.RoundRobinPoolRequest", "ActorRequest") | ||
.advise(method("send").and(takesArguments(1)), classOf[RequestInstrumentation]) | ||
|
||
onTypes("redis.ActorRequest$class") | ||
.advise(method("send"), classOf[ActorRequestAdvice]) | ||
|
||
} | ||
|
||
class RequestInstrumentation | ||
object RequestInstrumentation { | ||
@Advice.OnMethodEnter() | ||
def enter(@Advice.Argument(0) command: Any): Span = { | ||
val spanName = s"redis.command.${command.getClass.getSimpleName}" | ||
|
||
Kamon.clientSpanBuilder(spanName, "redis.client.rediscala") | ||
.start() | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = classOf[Throwable], suppress = classOf[Throwable]) | ||
def exit(@Advice.Enter span: Span, | ||
@Advice.Thrown t: Throwable, | ||
@Advice.Return future: Future[_]) = { | ||
if (t != null) { | ||
span.fail(t); | ||
} | ||
|
||
future.onComplete { | ||
case Success(_value) => | ||
span.finish() | ||
|
||
case Failure(exception) => | ||
span.fail(exception) | ||
span.finish() | ||
|
||
}(CallingThreadExecutionContext) | ||
} | ||
} | ||
|
||
class RoundRobinRequestInstrumentation | ||
|
||
object RoundRobinRequestInstrumentation { | ||
@Advice.OnMethodEnter() | ||
def enter(@Advice.Argument(1) command: Any): Span = { | ||
println("Entering round robin") | ||
val spanName = s"redis.command.${command.getClass.getSimpleName}" | ||
Kamon.clientSpanBuilder(spanName, "redis.client.rediscala") | ||
.start() | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = classOf[Throwable], suppress = classOf[Throwable]) | ||
def exit(@Advice.Enter span: Span, | ||
@Advice.Thrown t: Throwable, | ||
@Advice.Return future: Future[_]) = { | ||
println("Exiting round robin") | ||
if (t != null) { | ||
span.fail(t); | ||
} | ||
|
||
future.onComplete { | ||
case Success(_value) => | ||
span.finish() | ||
|
||
case Failure(exception) => | ||
span.fail(exception) | ||
span.finish() | ||
|
||
}(CallingThreadExecutionContext) | ||
} | ||
} | ||
|
||
class ActorRequestAdvice | ||
object ActorRequestAdvice { | ||
@Advice.OnMethodEnter() | ||
def enter(@Advice.Argument(1) command: Any): Span = { | ||
val spanName = s"redis.command.${command.getClass.getSimpleName}" | ||
Kamon.clientSpanBuilder(spanName, "redis.client.rediscala") | ||
.start() | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = classOf[Throwable], suppress = classOf[Throwable]) | ||
def exit(@Advice.Enter span: Span, | ||
@Advice.Thrown t: Throwable, | ||
@Advice.Return future: Future[_]) = { | ||
if (t != null) { | ||
span.fail(t); | ||
} | ||
|
||
future.onComplete { | ||
case Success(_value) => | ||
span.finish() | ||
|
||
case Failure(exception) => | ||
span.fail(exception) | ||
span.finish() | ||
|
||
}(CallingThreadExecutionContext) | ||
} | ||
} |
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
59 changes: 0 additions & 59 deletions
59
...ion/kamon-redis/src/test/scala/kamon/instrumentation/jedis/JedisInstrumentationSpec.scala
This file was deleted.
Oops, something went wrong.