aboutsummaryrefslogtreecommitdiff
path: root/kamon-jdbc
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2015-03-05 23:39:44 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2015-03-09 23:09:08 +0100
commit959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b (patch)
tree27c1fe8f22429fe3820f988ab17caaf8e4a6fa3a /kamon-jdbc
parent69ea63923e0d3697f8ca4c7eb9cb808821832aa2 (diff)
downloadKamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.gz
Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.bz2
Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.zip
! all: introduced support for metric tags.
Diffstat (limited to 'kamon-jdbc')
-rw-r--r--kamon-jdbc/src/main/scala/kamon/jdbc/instrumentation/StatementInstrumentation.scala17
-rw-r--r--kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala42
2 files changed, 40 insertions, 19 deletions
diff --git a/kamon-jdbc/src/main/scala/kamon/jdbc/instrumentation/StatementInstrumentation.scala b/kamon-jdbc/src/main/scala/kamon/jdbc/instrumentation/StatementInstrumentation.scala
index aa9295db..bef20667 100644
--- a/kamon-jdbc/src/main/scala/kamon/jdbc/instrumentation/StatementInstrumentation.scala
+++ b/kamon-jdbc/src/main/scala/kamon/jdbc/instrumentation/StatementInstrumentation.scala
@@ -44,9 +44,8 @@ class StatementInstrumentation {
@Around("onExecuteStatement(sql) || onExecutePreparedStatement(sql) || onExecutePreparedCall(sql)")
def aroundExecuteStatement(pjp: ProceedingJoinPoint, sql: String): Any = {
Tracer.currentContext.collect { ctx ⇒
- val metricsExtension = Kamon.metrics
val jdbcExtension = Kamon(Jdbc)
- implicit val statementRecorder = metricsExtension.register(StatementsMetrics, "jdbc-statements").map(_.recorder)
+ implicit val statementRecorder = Kamon.metrics.entity(StatementsMetrics, "jdbc-statements")
sql.replaceAll(CommentPattern, Empty) match {
case SelectStatement(_) ⇒ withSegment(ctx, Select, jdbcExtension)(recordRead(pjp, sql, jdbcExtension))
@@ -71,22 +70,22 @@ class StatementInstrumentation {
try thunk finally segment.finish()
}
- def recordRead(pjp: ProceedingJoinPoint, sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: Option[StatementsMetrics]): Any = {
+ def recordRead(pjp: ProceedingJoinPoint, sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: StatementsMetrics): Any = {
withTimeSpent(pjp.proceedWithErrorHandler(sql, jdbcExtension)) { timeSpent ⇒
- statementRecorder.map(stmr ⇒ stmr.reads.record(timeSpent))
+ statementRecorder.reads.record(timeSpent)
val timeSpentInMillis = nanos.toMillis(timeSpent)
if (timeSpentInMillis >= jdbcExtension.slowQueryThreshold) {
- statementRecorder.map(stmr ⇒ stmr.slows.increment())
+ statementRecorder.slows.increment()
jdbcExtension.processSlowQuery(sql, timeSpentInMillis)
}
}
}
- def recordWrite(pjp: ProceedingJoinPoint, sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: Option[StatementsMetrics]): Any = {
+ def recordWrite(pjp: ProceedingJoinPoint, sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: StatementsMetrics): Any = {
withTimeSpent(pjp.proceedWithErrorHandler(sql, jdbcExtension)) { timeSpent ⇒
- statementRecorder.map(stmr ⇒ stmr.writes.record(timeSpent))
+ statementRecorder.writes.record(timeSpent)
}
}
}
@@ -107,13 +106,13 @@ object StatementInstrumentation {
val Delete = "Delete"
implicit class PimpedProceedingJoinPoint(pjp: ProceedingJoinPoint) {
- def proceedWithErrorHandler(sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: Option[StatementsMetrics]): Any = {
+ def proceedWithErrorHandler(sql: String, jdbcExtension: JdbcExtension)(implicit statementRecorder: StatementsMetrics): Any = {
try {
pjp.proceed()
} catch {
case NonFatal(cause) ⇒
jdbcExtension.processSqlError(sql, cause)
- statementRecorder.map(stmr ⇒ stmr.errors.increment())
+ statementRecorder.errors.increment()
throw cause
}
}
diff --git a/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala b/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala
index 8ad5faa8..80107dff 100644
--- a/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala
+++ b/kamon-jdbc/src/test/scala/kamon/jdbc/instrumentation/StatementInstrumentationSpec.scala
@@ -24,8 +24,6 @@ import kamon.testkit.BaseKamonSpec
import kamon.trace.{ Tracer, SegmentCategory }
class StatementInstrumentationSpec extends BaseKamonSpec("jdbc-spec") {
- import TraceMetricsSpec.SegmentSyntax
-
override lazy val config =
ConfigFactory.parseString(
"""
@@ -76,8 +74,14 @@ class StatementInstrumentationSpec extends BaseKamonSpec("jdbc-spec") {
val traceSnapshot = takeSnapshotOf("jdbc-trace-insert", "trace")
traceSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- traceSnapshot.segments.size should be(1)
- traceSnapshot.segment("Jdbc[Insert]", SegmentCategory.Database, Jdbc.SegmentLibraryName).numberOfMeasurements should be(100)
+
+ val segmentSnapshot = takeSnapshotOf("Jdbc[Insert]", "trace-segment",
+ tags = Map(
+ "trace" -> "jdbc-trace-insert",
+ "category" -> SegmentCategory.Database,
+ "library" -> Jdbc.SegmentLibraryName))
+
+ segmentSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(100)
}
"record the execution time of SELECT operation" in {
@@ -96,8 +100,14 @@ class StatementInstrumentationSpec extends BaseKamonSpec("jdbc-spec") {
val traceSnapshot = takeSnapshotOf("jdbc-trace-select", "trace")
traceSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- traceSnapshot.segments.size should be(1)
- traceSnapshot.segment("Jdbc[Select]", SegmentCategory.Database, Jdbc.SegmentLibraryName).numberOfMeasurements should be(100)
+
+ val segmentSnapshot = takeSnapshotOf("Jdbc[Select]", "trace-segment",
+ tags = Map(
+ "trace" -> "jdbc-trace-select",
+ "category" -> SegmentCategory.Database,
+ "library" -> Jdbc.SegmentLibraryName))
+
+ segmentSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(100)
}
"record the execution time of UPDATE operation" in {
@@ -116,8 +126,14 @@ class StatementInstrumentationSpec extends BaseKamonSpec("jdbc-spec") {
val traceSnapshot = takeSnapshotOf("jdbc-trace-update", "trace")
traceSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- traceSnapshot.segments.size should be(1)
- traceSnapshot.segment("Jdbc[Update]", SegmentCategory.Database, Jdbc.SegmentLibraryName).numberOfMeasurements should be(100)
+
+ val segmentSnapshot = takeSnapshotOf("Jdbc[Update]", "trace-segment",
+ tags = Map(
+ "trace" -> "jdbc-trace-update",
+ "category" -> SegmentCategory.Database,
+ "library" -> Jdbc.SegmentLibraryName))
+
+ segmentSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(100)
}
"record the execution time of DELETE operation" in {
@@ -136,8 +152,14 @@ class StatementInstrumentationSpec extends BaseKamonSpec("jdbc-spec") {
val traceSnapshot = takeSnapshotOf("jdbc-trace-delete", "trace")
traceSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- traceSnapshot.segments.size should be(1)
- traceSnapshot.segment("Jdbc[Delete]", SegmentCategory.Database, Jdbc.SegmentLibraryName).numberOfMeasurements should be(100)
+
+ val segmentSnapshot = takeSnapshotOf("Jdbc[Delete]", "trace-segment",
+ tags = Map(
+ "trace" -> "jdbc-trace-delete",
+ "category" -> SegmentCategory.Database,
+ "library" -> Jdbc.SegmentLibraryName))
+
+ segmentSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(100)
}