Skip to content

Commit

Permalink
ensure the bundle works when the Cassandra Driver isn't in the classp…
Browse files Browse the repository at this point in the history
…ath, fixes #805
  • Loading branch information
ivantopo committed Jul 7, 2020
1 parent 60bcb63 commit 9efc972
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ object PoolCloseAdvice {
* Measure time spent waiting for a connection
* Record number of in-flight queries on just-acquired connection
*/
class BorrowAdvice
object BorrowAdvice {

@Advice.OnMethodEnter
def startBorrow(@Advice.This poolMetrics: HasPoolMetrics): Long = {
Kamon.clock().nanos()
}

@Advice.OnMethodExit(suppress = classOf[Throwable])
@Advice.OnMethodExit(suppress = classOf[Throwable], inline = false)
def onBorrowed(
@Advice.Return(readOnly = false) connection: ListenableFuture[Connection],
@Advice.Enter start: Long,
@Advice.This poolMetrics: HasPoolMetrics,
@Advice.Return connection: ListenableFuture[Connection],
@Advice.Enter start: Long,
@Advice.This poolMetrics: HasPoolMetrics,
@Advice.FieldValue("totalInFlight") totalInflight: AtomicInteger
): Unit = {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package com.datastax.driver.core
import java.util.concurrent.Callable

import kamon.instrumentation.cassandra.driver.InstrumentedSession
import kanela.agent.libs.net.bytebuddy.asm.Advice
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation.SuperCall
import kanela.agent.libs.net.bytebuddy.implementation.bind.annotation.{RuntimeType, SuperCall}

class SessionInterceptor
object SessionInterceptor {

@Advice.OnMethodExit
def wrapSession(@SuperCall session: Callable[Session]): Session = {
@RuntimeType
def newSession(@SuperCall session: Callable[Session]): Session = {
new InstrumentedSession(session.call())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DriverInstrumentation extends InstrumentationBuilder {
* Wraps the client session with an InstrumentedSession.
*/
onType("com.datastax.driver.core.Cluster$Manager")
.intercept(method("newSession"), SessionInterceptor)
.intercept(method("newSession"), classOf[SessionInterceptor])
.bridge(classOf[ClusterManagerBridge])

/**
Expand All @@ -42,7 +42,7 @@ class DriverInstrumentation extends InstrumentationBuilder {
* Pool metrics are mixed in the pool object itself
*/
onType("com.datastax.driver.core.HostConnectionPool")
.advise(method("borrowConnection"), BorrowAdvice)
.advise(method("borrowConnection"), classOf[BorrowAdvice])
.advise(method("trashConnection"), TrashConnectionAdvice)
.advise(method("addConnectionIfUnderMaximum"), CreateConnectionAdvice)
.advise(method("onConnectionDefunct"), ConnectionDefunctAdvice)
Expand Down

0 comments on commit 9efc972

Please sign in to comment.