diff options
Diffstat (limited to 'kamon-core/src/test')
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala b/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala new file mode 100644 index 00000000..9ecffb24 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala @@ -0,0 +1,64 @@ +package kamon.trace + +import kamon.Kamon +import kamon.Kamon.buildSpan +import kamon.metric._ +import org.scalatest.{Matchers, WordSpecLike} + +class SpanMetrics extends WordSpecLike with Matchers { + import SpanMetricsTestHelper._ + + val errorTag = "error" -> "true" + val histogramMetric: HistogramMetric = Kamon.histogram("span.elapsed-time") + + "Span Metrics" should { + "be recorded for successeful execution" in { + val operation = "span-success" + val operationTag = "operation" -> operation + + buildSpan(operation) + .start() + .finish() + + val histogram = histogramMetric.refine(operationTag) + histogram.distribution().count === 1 + + val errorHistogram = histogramMetric.refine(Map(operationTag, errorTag)).distribution() + errorHistogram.count === 0 + + } + + "record correctly error latency and count" in { + val operation = "span-failure" + val operationTag = "operation" -> operation + + buildSpan(operation) + .start() + .addSpanTag("error", true) + .finish() + + val histogram = histogramMetric.refine(operationTag) + histogram.distribution().count === 0 + + val errorHistogram = histogramMetric.refine(operationTag, errorTag).distribution() + errorHistogram.count === 1 + + } + } + +} + +object SpanMetricsTestHelper { + + implicit class HistogramMetricSyntax(histogram: Histogram) { + def distribution(resetState: Boolean = true): Distribution = + histogram match { + case hm: HistogramMetric => hm.refine(Map.empty[String, String]).distribution(resetState) + case h: AtomicHdrHistogram => h.snapshot(resetState).distribution + case h: HdrHistogram => h.snapshot(resetState).distribution + } + } +} + + + |